Spaces:
Running
Running
Revert "Use Gradio Examples component with image thumbnails"
Browse filesThis reverts commit 2de81b223370b1d721832a2f9351a20c9ac60595.
.DS_Store
DELETED
|
Binary file (6.15 kB)
|
|
|
app.py
CHANGED
|
@@ -454,40 +454,72 @@ def _launch_demo(args, model, processor):
|
|
| 454 |
regen_btn = gr.Button('Regenerate')
|
| 455 |
empty_bin = gr.Button('Clear')
|
| 456 |
|
| 457 |
-
# Examples section
|
| 458 |
-
gr.Markdown("### Examples - Click to load")
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
|
| 492 |
# Feature descriptions
|
| 493 |
with gr.Row():
|
|
|
|
| 454 |
regen_btn = gr.Button('Regenerate')
|
| 455 |
empty_bin = gr.Button('Clear')
|
| 456 |
|
| 457 |
+
# Examples section
|
| 458 |
+
gr.Markdown("### Quick Examples - Click to load")
|
| 459 |
+
|
| 460 |
+
with gr.Row():
|
| 461 |
+
example_1_btn = gr.Button("Text Detection")
|
| 462 |
+
example_2_btn = gr.Button("Document Parsing")
|
| 463 |
+
example_3_btn = gr.Button("Info Extraction")
|
| 464 |
+
example_4_btn = gr.Button("Visual Q&A")
|
| 465 |
+
example_5_btn = gr.Button("Translation")
|
| 466 |
+
|
| 467 |
+
task_history = gr.State([])
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
# Example 1: Text Detection
|
| 471 |
+
def load_example_1(history, task_hist):
|
| 472 |
+
prompt = "Detect and recognize all text in this image. Output the text with bounding box coordinates."
|
| 473 |
+
image_path = EXAMPLE_IMAGES["spotting"]
|
| 474 |
+
history = [((image_path,), None)]
|
| 475 |
+
task_hist = [((image_path,), None)]
|
| 476 |
+
return history, task_hist, prompt
|
| 477 |
+
|
| 478 |
+
# Example 2: Document Parsing
|
| 479 |
+
def load_example_2(history, task_hist):
|
| 480 |
+
prompt = "Extract all text from this document in markdown format. Use HTML for tables and LaTeX for equations. Parse in reading order."
|
| 481 |
+
image_path = EXAMPLE_IMAGES["parsing"]
|
| 482 |
+
history = [((image_path,), None)]
|
| 483 |
+
task_hist = [((image_path,), None)]
|
| 484 |
+
return history, task_hist, prompt
|
| 485 |
+
|
| 486 |
+
# Example 3: Information Extraction
|
| 487 |
+
def load_example_3(history, task_hist):
|
| 488 |
+
prompt = "Extract the following fields from this receipt and return as JSON: ['total', 'subtotal', 'tax', 'date', 'items']"
|
| 489 |
+
image_path = EXAMPLE_IMAGES["ie"]
|
| 490 |
+
history = [((image_path,), None)]
|
| 491 |
+
task_hist = [((image_path,), None)]
|
| 492 |
+
return history, task_hist, prompt
|
| 493 |
+
|
| 494 |
+
# Example 4: Visual Q&A
|
| 495 |
+
def load_example_4(history, task_hist):
|
| 496 |
+
prompt = "Look at this chart and answer: Which quarter had the highest revenue? What was the Sales value in Q4?"
|
| 497 |
+
image_path = EXAMPLE_IMAGES["vqa"]
|
| 498 |
+
history = [((image_path,), None)]
|
| 499 |
+
task_hist = [((image_path,), None)]
|
| 500 |
+
return history, task_hist, prompt
|
| 501 |
+
|
| 502 |
+
# Example 5: Translation
|
| 503 |
+
def load_example_5(history, task_hist):
|
| 504 |
+
prompt = "Translate all text in this image to English."
|
| 505 |
+
image_path = EXAMPLE_IMAGES["translation"]
|
| 506 |
+
history = [((image_path,), None)]
|
| 507 |
+
task_hist = [((image_path,), None)]
|
| 508 |
+
return history, task_hist, prompt
|
| 509 |
+
|
| 510 |
+
# Bind events
|
| 511 |
+
example_1_btn.click(load_example_1, [chatbot, task_history], [chatbot, task_history, query])
|
| 512 |
+
example_2_btn.click(load_example_2, [chatbot, task_history], [chatbot, task_history, query])
|
| 513 |
+
example_3_btn.click(load_example_3, [chatbot, task_history], [chatbot, task_history, query])
|
| 514 |
+
example_4_btn.click(load_example_4, [chatbot, task_history], [chatbot, task_history, query])
|
| 515 |
+
example_5_btn.click(load_example_5, [chatbot, task_history], [chatbot, task_history, query])
|
| 516 |
+
|
| 517 |
+
submit_btn.click(add_text, [chatbot, task_history, query],
|
| 518 |
+
[chatbot, task_history]).then(predict, [chatbot, task_history], [chatbot], show_progress=True)
|
| 519 |
+
submit_btn.click(reset_user_input, [], [query])
|
| 520 |
+
empty_bin.click(reset_state, [chatbot, task_history], [chatbot], show_progress=True)
|
| 521 |
+
regen_btn.click(regenerate, [chatbot, task_history], [chatbot], show_progress=True)
|
| 522 |
+
addfile_btn.upload(add_file, [chatbot, task_history, addfile_btn], [chatbot, task_history], show_progress=True)
|
| 523 |
|
| 524 |
# Feature descriptions
|
| 525 |
with gr.Row():
|