Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import json
|
| 2 |
import skia
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Define the category dictionary
|
| 6 |
category_dict = {
|
|
@@ -63,21 +65,20 @@ def render_annotations(annotations, image_dir):
|
|
| 63 |
return annotated_images
|
| 64 |
|
| 65 |
# Gradio interface function
|
| 66 |
-
def gradio_interface(
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
return [gr.Image(value=image[0], label=image[1]) for image in annotated_images]
|
| 70 |
|
| 71 |
# Create Gradio interface
|
| 72 |
iface = gr.Interface(
|
| 73 |
fn=gradio_interface,
|
| 74 |
-
inputs=[
|
| 75 |
-
gr.File(label="Upload Annotations JSON File"),
|
| 76 |
-
gr.Textbox(label="Image Directory")
|
| 77 |
-
],
|
| 78 |
outputs=gr.Gallery(label="Annotated Images"),
|
| 79 |
title="Paper Annotation Renderer",
|
| 80 |
-
description="
|
| 81 |
)
|
| 82 |
|
| 83 |
# Launch the Gradio interface
|
|
|
|
| 1 |
import json
|
| 2 |
import skia
|
| 3 |
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
import random
|
| 6 |
|
| 7 |
# Define the category dictionary
|
| 8 |
category_dict = {
|
|
|
|
| 65 |
return annotated_images
|
| 66 |
|
| 67 |
# Gradio interface function
|
| 68 |
+
def gradio_interface():
|
| 69 |
+
example_dir = "examples/1"
|
| 70 |
+
annotations_file = random.choice([f for f in os.listdir(example_dir) if f.endswith('.json')])
|
| 71 |
+
annotations = load_annotations(os.path.join(example_dir, annotations_file))
|
| 72 |
+
annotated_images = render_annotations(annotations, example_dir)
|
| 73 |
return [gr.Image(value=image[0], label=image[1]) for image in annotated_images]
|
| 74 |
|
| 75 |
# Create Gradio interface
|
| 76 |
iface = gr.Interface(
|
| 77 |
fn=gradio_interface,
|
| 78 |
+
inputs=[],
|
|
|
|
|
|
|
|
|
|
| 79 |
outputs=gr.Gallery(label="Annotated Images"),
|
| 80 |
title="Paper Annotation Renderer",
|
| 81 |
+
description="Click to randomly choose an example and render annotations onto the images."
|
| 82 |
)
|
| 83 |
|
| 84 |
# Launch the Gradio interface
|