Spaces:
Runtime error
Runtime error
feat: add json output
Browse files- .gitignore +2 -1
- app.py +13 -2
.gitignore
CHANGED
@@ -2,4 +2,5 @@
|
|
2 |
yolov5s.pt
|
3 |
# __pycache__
|
4 |
*.jpg
|
5 |
-
gradio_queue.db
|
|
|
|
2 |
yolov5s.pt
|
3 |
# __pycache__
|
4 |
*.jpg
|
5 |
+
gradio_queue.db
|
6 |
+
__pycache__
|
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
# Images
|
6 |
torch.hub.download_url_to_file(
|
@@ -22,11 +23,21 @@ def yolo(im, size=1024):
|
|
22 |
|
23 |
results = model(im) # inference
|
24 |
results.render() # updates results.imgs with boxes and labels
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
29 |
-
outputs =
|
|
|
|
|
|
|
30 |
|
31 |
title = "YOLOv5 NDL-DocL Datasets"
|
32 |
description = "YOLOv5 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use."
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
+
import json
|
5 |
|
6 |
# Images
|
7 |
torch.hub.download_url_to_file(
|
|
|
23 |
|
24 |
results = model(im) # inference
|
25 |
results.render() # updates results.imgs with boxes and labels
|
26 |
+
|
27 |
+
df = results.pandas().xyxy[0].to_json(orient="records")
|
28 |
+
res = json.loads(df)
|
29 |
+
|
30 |
+
return [
|
31 |
+
Image.fromarray(results.imgs[0]),
|
32 |
+
res
|
33 |
+
]
|
34 |
|
35 |
|
36 |
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
37 |
+
outputs = [
|
38 |
+
gr.outputs.Image(type="pil", label="Output Image"),
|
39 |
+
gr.outputs.JSON(label="Output JSON")
|
40 |
+
]
|
41 |
|
42 |
title = "YOLOv5 NDL-DocL Datasets"
|
43 |
description = "YOLOv5 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use."
|