zachwormgoor@gmail.com
commited on
Commit
•
5cd635a
1
Parent(s):
71fac2a
Adding debug tab
Browse files
app.py
CHANGED
@@ -71,6 +71,23 @@ def classify_image_url(url_text):
|
|
71 |
# 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
|
72 |
return { categories[0]: 0.0, categories[1]: 0.0 }
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
|
76 |
image = gr.inputs.Image(shape=(192, 192))
|
@@ -93,10 +110,11 @@ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=exa
|
|
93 |
|
94 |
|
95 |
intf_text_url = gr.Interface(fn=classify_image_url, inputs="text", outputs=gr.outputs.Label())#, examples=example_urls)
|
|
|
96 |
# intf_text_url.launch(inline=False)
|
97 |
|
98 |
# https://github.com/gradio-app/gradio/issues/450
|
99 |
-
gr.TabbedInterface( [intf, intf_text_url], ["Image file upload", "Image URL" ] ).launch()
|
100 |
|
101 |
|
102 |
|
|
|
71 |
# 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
|
72 |
return { categories[0]: 0.0, categories[1]: 0.0 }
|
73 |
|
74 |
+
|
75 |
+
def classify_image_url_debug(url_text):
|
76 |
+
try:
|
77 |
+
dest = 'temp.jpg'
|
78 |
+
download_url(url_text, dest, show_progress=False)
|
79 |
+
im = Image.open(dest)
|
80 |
+
img = im.to_thumb(256,256)
|
81 |
+
#resize_images(dest, max_size=400, dest=dest)
|
82 |
+
os.remove(dest)
|
83 |
+
#return classify_image(img)
|
84 |
+
return "Success"
|
85 |
+
except Exception as ex:
|
86 |
+
# 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
|
87 |
+
#return { categories[0]: 0.0, categories[1]: 0.0 }
|
88 |
+
return ex.message
|
89 |
+
|
90 |
+
|
91 |
|
92 |
|
93 |
image = gr.inputs.Image(shape=(192, 192))
|
|
|
110 |
|
111 |
|
112 |
intf_text_url = gr.Interface(fn=classify_image_url, inputs="text", outputs=gr.outputs.Label())#, examples=example_urls)
|
113 |
+
intf_text_url_debug = gr.Interface(fn=classify_image_url_debug, inputs="text", outputs="text")
|
114 |
# intf_text_url.launch(inline=False)
|
115 |
|
116 |
# https://github.com/gradio-app/gradio/issues/450
|
117 |
+
gr.TabbedInterface( [intf, intf_text_url, intf_text_url_debug], ["Image file upload", "Image URL", "Image URL debug" ] ).launch()
|
118 |
|
119 |
|
120 |
|