Satoru commited on
Commit
0f967fc
1 Parent(s): 8a166e0

feat: add outputs

Browse files
Files changed (2) hide show
  1. .gitignore +3 -1
  2. app.py +9 -4
.gitignore CHANGED
@@ -1,2 +1,4 @@
1
  .DS_Store
2
- yolov5s.pt
 
 
 
1
  .DS_Store
2
+ yolov5s.pt
3
+ __pycache__
4
+ gradio_queue.db
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
  import torch
3
  from PIL import Image
4
-
5
- import gdown
6
 
7
  '''
8
  # a file
@@ -29,11 +29,16 @@ def yolo(im, size=1024):
29
 
30
  results = model(im) # inference
31
  results.render() # updates results.imgs with boxes and labels
32
- return Image.fromarray(results.imgs[0])
 
 
 
 
33
 
34
 
35
  inputs = gr.inputs.Image(type='pil', label="Original Image")
36
- outputs = gr.outputs.Image(type="pil", label="Output Image")
 
37
 
38
  title = "YOLOv5 Character"
39
  description = "YOLOv5 Character 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
+ # import gdown
6
 
7
  '''
8
  # a file
 
29
 
30
  results = model(im) # inference
31
  results.render() # updates results.imgs with boxes and labels
32
+
33
+ df = results.pandas().xyxy[0].to_json(orient="records")
34
+ res = json.loads(df)
35
+
36
+ return [Image.fromarray(results.imgs[0]), res]
37
 
38
 
39
  inputs = gr.inputs.Image(type='pil', label="Original Image")
40
+ outputs = [gr.outputs.Image(type="pil", label="Output Image"),
41
+ gr.outputs.JSON(label="Output JSON")]
42
 
43
  title = "YOLOv5 Character"
44
  description = "YOLOv5 Character Gradio demo for object detection. Upload an image or click an example image to use."