Spaces:
Running
Running
Add captions to detected images gallery
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
from threading import Thread
|
2 |
|
3 |
-
from PIL import Image
|
4 |
import gradio as gr
|
5 |
import torch
|
6 |
-
from
|
|
|
7 |
from transformers import TextIteratorStreamer, AutoModelForCausalLM, AutoTokenizer # Moondream
|
8 |
from transformers import YolosImageProcessor, YolosForObjectDetection # YOLOS-small-300
|
9 |
|
@@ -64,7 +64,10 @@ def detect_objects(img: Image.Image):
|
|
64 |
f"Detected {yolos_model.config.id2label[label.item()]} with confidence "
|
65 |
f"{round(score.item(), 3)} at location {box}"
|
66 |
)
|
67 |
-
box_images.append(
|
|
|
|
|
|
|
68 |
|
69 |
return box_images
|
70 |
|
@@ -82,7 +85,7 @@ if __name__ == "__main__":
|
|
82 |
with gr.Tab("Object Detection"):
|
83 |
with gr.Row():
|
84 |
yolos_input = gr.Image(type="pil")
|
85 |
-
yolos_output = gr.Gallery(label="Detected Objects",
|
86 |
yolos_button = gr.Button("Submit")
|
87 |
|
88 |
with gr.Tab("Inference"):
|
|
|
1 |
from threading import Thread
|
2 |
|
|
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
+
from PIL import Image
|
6 |
+
from transformers import PreTrainedModel # for type hint
|
7 |
from transformers import TextIteratorStreamer, AutoModelForCausalLM, AutoTokenizer # Moondream
|
8 |
from transformers import YolosImageProcessor, YolosForObjectDetection # YOLOS-small-300
|
9 |
|
|
|
64 |
f"Detected {yolos_model.config.id2label[label.item()]} with confidence "
|
65 |
f"{round(score.item(), 3)} at location {box}"
|
66 |
)
|
67 |
+
box_images.append((
|
68 |
+
img.crop((box[0], box[1], box[2], box[3])),
|
69 |
+
f"{yolos_model.config.id2label[label.item()]} ({round(score.item(), 3)})")
|
70 |
+
)
|
71 |
|
72 |
return box_images
|
73 |
|
|
|
85 |
with gr.Tab("Object Detection"):
|
86 |
with gr.Row():
|
87 |
yolos_input = gr.Image(type="pil")
|
88 |
+
yolos_output = gr.Gallery(label="Detected Objects", object_fit="scale-down", columns=3)
|
89 |
yolos_button = gr.Button("Submit")
|
90 |
|
91 |
with gr.Tab("Inference"):
|