Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from datasets import load_dataset
|
| 3 |
from PIL import Image, ImageDraw
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
current_index = 0
|
| 8 |
|
| 9 |
def draw_bounding_box(image, bbox):
|
|
@@ -44,6 +45,13 @@ def previous_image():
|
|
| 44 |
current_index = (current_index - 1) % len(dataset)
|
| 45 |
return show_image(current_index)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
shortcut_js = """
|
| 48 |
<script>
|
| 49 |
function shortcuts(e) {
|
|
@@ -67,7 +75,7 @@ document.addEventListener('keydown', shortcuts, false);
|
|
| 67 |
"""
|
| 68 |
|
| 69 |
with gr.Blocks(head=shortcut_js) as app:
|
| 70 |
-
gr.Markdown("#
|
| 71 |
|
| 72 |
with gr.Row():
|
| 73 |
image_output = gr.Image(type="pil")
|
|
@@ -77,9 +85,14 @@ with gr.Blocks(head=shortcut_js) as app:
|
|
| 77 |
prev_button = gr.Button("Previous", elem_id="prev_btn")
|
| 78 |
next_button = gr.Button("Next", elem_id="next_btn")
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
prev_button.click(previous_image, outputs=[image_output, label_output])
|
| 81 |
next_button.click(next_image, outputs=[image_output, label_output])
|
|
|
|
| 82 |
|
| 83 |
app.load(show_image, inputs=[gr.Number(value=0, visible=False)], outputs=[image_output, label_output])
|
| 84 |
|
| 85 |
-
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from datasets import load_dataset
|
| 3 |
from PIL import Image, ImageDraw
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 7 |
+
dataset = load_dataset("agentsea/wave-ui-25k", split="train", token=hf_token)
|
| 8 |
current_index = 0
|
| 9 |
|
| 10 |
def draw_bounding_box(image, bbox):
|
|
|
|
| 45 |
current_index = (current_index - 1) % len(dataset)
|
| 46 |
return show_image(current_index)
|
| 47 |
|
| 48 |
+
def change_index(new_index):
|
| 49 |
+
new_index = int(new_index)
|
| 50 |
+
if 0 <= new_index < len(dataset):
|
| 51 |
+
return show_image(new_index)
|
| 52 |
+
else:
|
| 53 |
+
return show_image(current_index), f"Invalid index. Please enter a number between 0 and {len(dataset) - 1}."
|
| 54 |
+
|
| 55 |
shortcut_js = """
|
| 56 |
<script>
|
| 57 |
function shortcuts(e) {
|
|
|
|
| 75 |
"""
|
| 76 |
|
| 77 |
with gr.Blocks(head=shortcut_js) as app:
|
| 78 |
+
gr.Markdown("# WaveUI 25k Dataset Explorer")
|
| 79 |
|
| 80 |
with gr.Row():
|
| 81 |
image_output = gr.Image(type="pil")
|
|
|
|
| 85 |
prev_button = gr.Button("Previous", elem_id="prev_btn")
|
| 86 |
next_button = gr.Button("Next", elem_id="next_btn")
|
| 87 |
|
| 88 |
+
with gr.Row():
|
| 89 |
+
index_input = gr.Number(label="Go to index (0-based)", value=0)
|
| 90 |
+
go_button = gr.Button("Go", elem_id="go_btn")
|
| 91 |
+
|
| 92 |
prev_button.click(previous_image, outputs=[image_output, label_output])
|
| 93 |
next_button.click(next_image, outputs=[image_output, label_output])
|
| 94 |
+
go_button.click(change_index, inputs=[index_input], outputs=[image_output, label_output])
|
| 95 |
|
| 96 |
app.load(show_image, inputs=[gr.Number(value=0, visible=False)], outputs=[image_output, label_output])
|
| 97 |
|
| 98 |
+
app.launch()
|