Update app.py
Browse files
app.py
CHANGED
@@ -176,21 +176,6 @@ def update_vote(vote_type, session_id, is_example_image):
|
|
176 |
with open("./assets/showui.png", "rb") as image_file:
|
177 |
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
|
178 |
|
179 |
-
def on_submit(image, query, example_flag):
|
180 |
-
if image is None:
|
181 |
-
raise ValueError("No image provided. Please upload an image before submitting.")
|
182 |
-
|
183 |
-
session_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
184 |
-
|
185 |
-
# Use the example_flag to determine if the image is an example
|
186 |
-
is_example_image = example_flag
|
187 |
-
|
188 |
-
result_image, click_coords, image_path = run_showui(image, query, session_id)
|
189 |
-
|
190 |
-
save_and_upload_data(image_path, query, session_id, is_example_image)
|
191 |
-
|
192 |
-
return result_image, click_coords, image_path, session_id, is_example_image
|
193 |
-
|
194 |
def build_demo(embed_mode, concurrency_count=1):
|
195 |
with gr.Blocks(title="ShowUI Demo", theme=gr.themes.Default()) as demo:
|
196 |
state_image_path = gr.State(value=None)
|
@@ -232,17 +217,17 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
232 |
|
233 |
gr.Examples(
|
234 |
examples=[
|
235 |
-
["./examples/app_store.png", "Download Kindle."
|
236 |
-
["./examples/ios_setting.png", "Turn off Do not disturb."
|
237 |
-
["./examples/apple_music.png", "Star to favorite."
|
238 |
-
["./examples/map.png", "Boston."
|
239 |
-
["./examples/wallet.png", "Scan a QR code."
|
240 |
-
["./examples/word.png", "More shapes."
|
241 |
-
["./examples/web_shopping.png", "Proceed to checkout."
|
242 |
-
["./examples/web_forum.png", "Post my comment."
|
243 |
-
["./examples/safari_google.png", "Click on search bar."
|
244 |
],
|
245 |
-
inputs=[imagebox, textbox
|
246 |
examples_per_page=3
|
247 |
)
|
248 |
|
@@ -260,9 +245,23 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
260 |
downvote_btn = gr.Button(value="Too bad!", variant="secondary")
|
261 |
clear_btn = gr.Button(value="🗑️ Clear", interactive=True)
|
262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
submit_btn.click(
|
264 |
on_submit,
|
265 |
-
[imagebox, textbox
|
266 |
[output_img, output_coords, state_image_path, state_session_id, state_is_example_image],
|
267 |
)
|
268 |
|
@@ -296,13 +295,4 @@ if __name__ == "__main__":
|
|
296 |
server_port=7860,
|
297 |
ssr_mode=False,
|
298 |
debug=True,
|
299 |
-
)
|
300 |
-
|
301 |
-
if __name__ == "__main__":
|
302 |
-
demo = build_demo(embed_mode=False)
|
303 |
-
demo.queue(api_open=False).launch(
|
304 |
-
server_name="0.0.0.0",
|
305 |
-
server_port=7860,
|
306 |
-
ssr_mode=False,
|
307 |
-
debug=True,
|
308 |
-
)
|
|
|
176 |
with open("./assets/showui.png", "rb") as image_file:
|
177 |
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
def build_demo(embed_mode, concurrency_count=1):
|
180 |
with gr.Blocks(title="ShowUI Demo", theme=gr.themes.Default()) as demo:
|
181 |
state_image_path = gr.State(value=None)
|
|
|
217 |
|
218 |
gr.Examples(
|
219 |
examples=[
|
220 |
+
["./examples/app_store.png", "Download Kindle."],
|
221 |
+
["./examples/ios_setting.png", "Turn off Do not disturb."],
|
222 |
+
["./examples/apple_music.png", "Star to favorite."],
|
223 |
+
["./examples/map.png", "Boston."],
|
224 |
+
["./examples/wallet.png", "Scan a QR code."],
|
225 |
+
["./examples/word.png", "More shapes."],
|
226 |
+
["./examples/web_shopping.png", "Proceed to checkout."],
|
227 |
+
["./examples/web_forum.png", "Post my comment."],
|
228 |
+
["./examples/safari_google.png", "Click on search bar."],
|
229 |
],
|
230 |
+
inputs=[imagebox, textbox],
|
231 |
examples_per_page=3
|
232 |
)
|
233 |
|
|
|
245 |
downvote_btn = gr.Button(value="Too bad!", variant="secondary")
|
246 |
clear_btn = gr.Button(value="🗑️ Clear", interactive=True)
|
247 |
|
248 |
+
def on_submit(image, query):
|
249 |
+
if image is None:
|
250 |
+
raise ValueError("No image provided. Please upload an image before submitting.")
|
251 |
+
|
252 |
+
session_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
253 |
+
print("image_path:", image)
|
254 |
+
is_example_image = isinstance(image, str) and image.startswith("./examples/")
|
255 |
+
|
256 |
+
result_image, click_coords, image_path = run_showui(image, query, session_id)
|
257 |
+
|
258 |
+
save_and_upload_data(image_path, query, session_id, is_example_image)
|
259 |
+
|
260 |
+
return result_image, click_coords, image_path, session_id, is_example_image
|
261 |
+
|
262 |
submit_btn.click(
|
263 |
on_submit,
|
264 |
+
[imagebox, textbox],
|
265 |
[output_img, output_coords, state_image_path, state_session_id, state_is_example_image],
|
266 |
)
|
267 |
|
|
|
295 |
server_port=7860,
|
296 |
ssr_mode=False,
|
297 |
debug=True,
|
298 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|