Spaces:
Runtime error
Runtime error
zachwormgoor@gmail.com
commited on
Commit
β’
54dd2be
1
Parent(s):
66b0b77
Adding image preview for URLs
Browse files
app.py
CHANGED
@@ -63,10 +63,10 @@ def classify_image_url(learn, url_text):
|
|
63 |
img = im.to_thumb(256,256)
|
64 |
#resize_images(dest, max_size=400, dest=dest)
|
65 |
os.remove(dest)
|
66 |
-
return classify_image(learn, img)
|
67 |
except:
|
68 |
# in case there is any error, invalid URL or invalid image, etc., not sure how Gradio will handle a runtime exception so catching it to be safe
|
69 |
-
return { categories[0]: 0.0, categories[1]: 0.0 }
|
70 |
|
71 |
|
72 |
def classify_image_url_debug(url_text):
|
@@ -94,8 +94,11 @@ import gradio as gr
|
|
94 |
demo = gr.Blocks()
|
95 |
|
96 |
with demo:
|
97 |
-
gr.Markdown("Rudimentary age predictor. No refinement, just a hacked together experiment to try multiple output classes with fast.ai. Many ways the accuracy could be improved.
|
98 |
-
gr.Markdown("
|
|
|
|
|
|
|
99 |
with gr.Tabs():
|
100 |
with gr.TabItem("Image - resnet18"):
|
101 |
with gr.Row():
|
@@ -124,9 +127,9 @@ with demo:
|
|
124 |
text_d_button = gr.Button("Predict - debug")
|
125 |
|
126 |
image_r_button.click(classify_image_resnet, inputs=img_r_input, outputs=img_r_output)
|
127 |
-
url_r_button.click( classify_image_url_resnet, inputs=text_r_input, outputs=text_r_output)
|
128 |
image_c_button.click(classify_image_convnext, inputs=img_c_input, outputs=img_c_output)
|
129 |
-
text_c_button.click( classify_image_url_convnext, inputs=text_c_input, outputs=
|
130 |
text_d_button.click( classify_image_url_debug, inputs=text_d_input, outputs=text_d_output)
|
131 |
|
132 |
demo.launch()
|
|
|
63 |
img = im.to_thumb(256,256)
|
64 |
#resize_images(dest, max_size=400, dest=dest)
|
65 |
os.remove(dest)
|
66 |
+
return classify_image(learn, img),img
|
67 |
except:
|
68 |
# in case there is any error, invalid URL or invalid image, etc., not sure how Gradio will handle a runtime exception so catching it to be safe
|
69 |
+
return { categories[0]: 0.0, categories[1]: 0.0 },None
|
70 |
|
71 |
|
72 |
def classify_image_url_debug(url_text):
|
|
|
94 |
demo = gr.Blocks()
|
95 |
|
96 |
with demo:
|
97 |
+
gr.Markdown("Rudimentary age predictor. No refinement, just a hacked together experiment to try multiple output classes with fast.ai. Many ways the accuracy could be improved. ")
|
98 |
+
gr.Markdown("See: https://www.kaggle.com/code/zachwormgoor/age-predictor ")
|
99 |
+
gr.Markdown(" ")
|
100 |
+
gr.Markdown("Predict age from uploaded image or from provide URL to image file: ")
|
101 |
+
gr.Markdown(" ")
|
102 |
with gr.Tabs():
|
103 |
with gr.TabItem("Image - resnet18"):
|
104 |
with gr.Row():
|
|
|
127 |
text_d_button = gr.Button("Predict - debug")
|
128 |
|
129 |
image_r_button.click(classify_image_resnet, inputs=img_r_input, outputs=img_r_output)
|
130 |
+
url_r_button.click( classify_image_url_resnet, inputs=text_r_input, outputs=(text_r_output,gr.Image()))
|
131 |
image_c_button.click(classify_image_convnext, inputs=img_c_input, outputs=img_c_output)
|
132 |
+
text_c_button.click( classify_image_url_convnext, inputs=text_c_input, outputs=(text_c_output, gr.Image()))
|
133 |
text_d_button.click( classify_image_url_debug, inputs=text_d_input, outputs=text_d_output)
|
134 |
|
135 |
demo.launch()
|