-
Notifications
You must be signed in to change notification settings - Fork 26
Prep quickstart #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
239d093
cut down number of dependencies
colearendt ebbe1f2
remove problematic line for connect
colearendt 7cdccbf
name chunk
colearendt c3f99ff
add rproj file
colearendt 3eccd5a
add gitignore to avoid tracking generated files
colearendt dbd42e7
add simple requirements.txt
colearendt 4135828
add manifest.json for demo-notebook
colearendt 624dbd8
add image link to .internal.yml
colearendt 98434db
try adding python directly
colearendt a3e345c
add debug info
colearendt c0fcdbb
add print
colearendt 7664a0e
rename .internal.yml to .connect.yml
colearendt 8b0c0d5
rename name to title
colearendt 30c891e
Merge remote-tracking branch 'origin/master' into prep-quickstart
colearendt e56ecec
add space
colearendt 71fa9e1
fix connect.yml
colearendt 22c2acb
update manifest
colearendt 4b4ebb7
add .internal.yml temporarily until the quickstart changes its codebase
colearendt 06286a8
Merge remote-tracking branch 'origin/master' into prep-quickstart
colearendt a153a03
add manifest for image-classifier
colearendt b2d9299
fix torch requirements.txt entry
colearendt 99aa005
add image classification to .connect.yml
colearendt ca5c496
add gitlink placeholder
colearendt 3126ec5
overhaul image path provisioning
colearendt 464548d
add config.yml
colearendt 4906e96
clean up semantics
colearendt 9e940c2
add default images
colearendt 58426a9
clean up default images
colearendt f254fe0
fix error handling
colearendt dc62b84
update config.yml
colearendt 631b924
add image-classifier manifest
colearendt 479ee3c
fix wrapping issue on the image
colearendt 9c9d507
remove gitlink
colearendt 9f0d5e4
change "download" to "fetch-image-url"
colearendt aac652b
update config file
colearendt 123791b
scrub "download" from the app
colearendt 0858cdf
add image classification with pytorch to .internal.yml for the quicks…
colearendt 5e690ca
add pytorch logo
colearendt 93f7de0
update image to use pytorch-logo
colearendt 0008ea4
update .connect.yml to use the pytorch logo
colearendt 72ea993
first pass at sentiment-analysis app
colearendt 86b8fa4
add predict.py
colearendt 26f5c3a
add namesgenerator.py
colearendt b531037
commit model trained on 10k movie reviews
colearendt 8271a3c
add requirements.txt
colearendt 61f568b
add rproj file
colearendt 66c7a16
add (duplicate) train.Rmd :grimacing:
colearendt 6d8a64f
add a br() to help with spacing
colearendt 90a9bb5
change inputPanel layout
colearendt 697a0e6
add some sample reviews
colearendt 81d94ae
minor updates to the sentiment app
colearendt 844d649
allow committing the model
colearendt 91221ee
add another copy of the model for the api
colearendt fc66f02
clean up sentiment analysis api
colearendt dd238f0
generate manifest
colearendt baadea4
update manifest from connect
colearendt 01e3d16
add spacy logo
colearendt 384ae18
update connect.yml
colearendt 024a6d6
update rmarkdown-notebook manifest
colearendt f2895d4
add api description
colearendt 1d9c172
update internal.yml
colearendt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
default: | ||
content: | ||
- title: "Use Python with R" | ||
path: "./rmarkdown-notebook" | ||
description: "Use the reticulate package to integrate Python into an R Markdown notebook." | ||
tag: | ||
- "Demo Content|Python" | ||
url: "/python/reticulate/" | ||
image: "reticulated_python.png" | ||
- title: "Sentiment Analysis with Python" | ||
path: "./sentiment-analysis" | ||
description: "A Plumber API that uses R and Python to evaluate sentiment in text input using a pretrained spaCy model." | ||
tag: | ||
- "Demo Content|Python" | ||
url: "/python/sentiment-analysis/" | ||
image: "sentiment-analysis/spacy_logo.jpg" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,3 @@ __pycache__ | |
.ipynb_checkpoints | ||
*.html | ||
rmarkdown-notebook/flights.csv | ||
sentiment-analysis/model/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
default: | ||
content: | ||
- name: "Use Python with R" | ||
path: "./reticulate" | ||
path: "./rmarkdown-notebook" | ||
description: "Use the reticulate package to integrate Python into an R Markdown notebook." | ||
tag: | ||
- "Demo Content|Python" | ||
url: "/python/reticulate/" | ||
url: "/python/reticulate/" | ||
image: "reticulated_python.png" | ||
- name: "Sentiment Analysis with Python" | ||
path: "./sentiment-analysis" | ||
description: "A Plumber API that uses R and Python to evaluate sentiment in text input using a pretrained spaCy model." | ||
tag: | ||
- "Demo Content|Python" | ||
url: "/python/sentiment-analysis/" | ||
image: "sentiment-analysis/spacy_logo.jpg" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,79 +3,95 @@ library(reticulate) # Used to call Tensorflow Python script | |
library(shiny) | ||
library(shinycssloaders) | ||
|
||
behavior <- config::get("image") | ||
stopifnot(behavior %in% c("upload", "fetch-image-url")) | ||
|
||
# Load source of Python image classifier script | ||
source_python('image-classifier.py') | ||
|
||
server <- function(input, output, session) { | ||
|
||
output$contents <- renderTable({ | ||
# After the user uploads a file, the image will be classified and the predictions will be shown. | ||
|
||
# where the image that should be classified is on disk | ||
image_path <- reactiveVal("./img/cat.jpg") | ||
|
||
image_prefix <- "pytorch_image" | ||
|
||
# the configurable selector for fetch-image-url vs. upload | ||
output$image_selector <- renderUI({ | ||
if (behavior == "fetch-image-url") { | ||
list( | ||
textInput("file1", label = h5("Enter Image URL:"), value = ""), | ||
actionButton("fetch-image-url", "Fetch Image") | ||
) | ||
} else if (behavior == "upload") { | ||
fileInput("file_upload", label = h5("Upload an Image:")) | ||
} else { | ||
stop("Invalid configuration. Please chose 'fetch-image-url' or 'upload'") | ||
} | ||
}) | ||
|
||
# handle upload | ||
observe({ | ||
req(input$file_upload) | ||
upload_file <- input$file_upload | ||
image_path(upload_file$datapath[[1]]) | ||
}) | ||
|
||
# handle fetch-image-url | ||
observeEvent(input[["fetch-image-url"]], { | ||
req(input$file1) | ||
tryCatch({ | ||
# Fetch image from URL | ||
temp_fetch_image_url <- fs::file_temp(image_prefix, ext = ".jpg") | ||
downloader::download(input$file1, temp_fetch_image_url) | ||
|
||
image_path(temp_fetch_image_url) | ||
}, error = function(e){ | ||
# usually, you would not expose this to the user | ||
# without a little sanitization | ||
showNotification(as.character(safeError(e)), type = "warning") | ||
}) | ||
}) | ||
|
||
output$contents <- renderTable({ | ||
req(image_path()) | ||
|
||
tryCatch( | ||
{ | ||
# Download image from URL | ||
downloader::download(input$file1, "image") | ||
|
||
# Call function from PyTorch Python script to classify image | ||
results <- classify_image_pytorch(image_path="image") | ||
results <- classify_image_pytorch(image_path=image_path()) | ||
}, | ||
error = function(e) { | ||
stop(safeError(e)) | ||
# usually, you would not expose this to the user | ||
# without a little sanitization | ||
showNotification(as.character(safeError(e)), type = "warning") | ||
} | ||
) | ||
return(results) | ||
}) | ||
|
||
# render the image | ||
output$image1 <- renderImage({ | ||
req(input$file1) | ||
tryCatch( | ||
{ | ||
input$file1 | ||
}, | ||
error = function(e) { | ||
stop(safeError(e)) | ||
} | ||
) | ||
req(image_path()) | ||
|
||
# Copy the image to temp space | ||
new_path <- fs::file_copy(image_path(), fs::file_temp(image_prefix, ext = ".jpg")) | ||
|
||
# Return a list containing the filename | ||
if(is.null(input$file1)) { | ||
if(is.null(new_path)) { | ||
return(NULL) | ||
} | ||
else { | ||
return(list(src = "image")) | ||
return(list(src = new_path, style = htmltools::css(width = "100%"))) | ||
} | ||
}) | ||
|
||
observe({ | ||
x = input$oil_platform | ||
image_url = "https://upload.wikimedia.org/wikipedia/commons/a/a1/Oil_platform.jpeg" | ||
updateTextInput(session, "file1", value = paste(image_url)) | ||
}) | ||
|
||
observe({ | ||
x = input$truck | ||
image_url = "https://upload.wikimedia.org/wikipedia/commons/6/6c/Toyota-1984-truck.jpg" | ||
updateTextInput(session, "file1", value = paste(image_url)) | ||
}) | ||
|
||
observe({ | ||
x = input$flower | ||
image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Aster_Tataricus.JPG/612px-Aster_Tataricus.JPG" | ||
updateTextInput(session, "file1", value = paste(image_url)) | ||
}) | ||
|
||
observe({ | ||
x = input$cat | ||
image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7f/Egyptian_Mau_Bronze.jpg/611px-Egyptian_Mau_Bronze.jpg" | ||
updateTextInput(session, "file1", value = paste(image_url)) | ||
}) | ||
|
||
observe({ | ||
x = input$dog | ||
image_url = "https://upload.wikimedia.org/wikipedia/commons/e/e4/Border_Collie_600.jpg" | ||
updateTextInput(session, "file1", value = paste(image_url)) | ||
}) | ||
# default images | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for making these example images self-contained! |
||
observeEvent(input$oil_platform, image_path("./img/oil_platform.jpg")) | ||
observeEvent(input$truck, image_path("./img/truck.jpg")) | ||
observeEvent(input$flower, image_path("./img/flower.jpg")) | ||
observeEvent(input$cat, image_path("./img/cat.jpg")) | ||
observeEvent(input$dog, image_path("./img/dog.jpg")) | ||
|
||
} | ||
|
||
|
@@ -84,8 +100,8 @@ ui <- fluidPage( | |
titlePanel("Image Classifier"), | ||
sidebarLayout( | ||
sidebarPanel( | ||
textInput("file1", label = h5("Enter Image URL:"), value = ""), | ||
helpText("Your image will be downloaded and classified using Tensorflow in Python."), | ||
uiOutput("image_selector"), | ||
helpText("Your image will be classified using Tensorflow in Python."), | ||
helpText("The resulting predictions will be shown along with their confidence level."), | ||
hr(), | ||
helpText("Or, choose an example image:"), | ||
|
@@ -103,7 +119,7 @@ ui <- fluidPage( | |
mainPanel( | ||
# Output | ||
tableOutput("contents") %>% withSpinner(), | ||
imageOutput("image1") %>% withSpinner(color = "#ffffff") | ||
imageOutput("image1", height = NULL) %>% withSpinner(color = "#ffffff") | ||
) | ||
) | ||
) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
default: | ||
image: "fetch-image-url" | ||
quickstart: | ||
image: "upload" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between this file and
.internal.yml
? Are they both necessary?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeaaah.
.internal.yml
is what the QuickStart is using at the moment. Obviously both are configurable, but there are some minor differences that are not nailed down until we have a broader discussion as a team, and I would love to wait to eat that change until the change is nailed down. If you don't mind having both for the short term, it would make my life easier 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind having either files. this was mostly a curious question. If
.internal.yml
is being used for the QuickStart, then what is.connect.yml
is being used for?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the
connectapi
package (R package to simplify interacting with the Connect Server API). That's the experimental one that I want to chat with y'all about. I.e. the idea is that.connect.yml
(or some other such thing) would replace.internal.yml
. (I use it for testing the QuickStart stuff because it is much easier to use interactively)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thank you for clarifying!