Sanan commited on
Commit
28f2001
·
1 Parent(s): cd3df7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,7 +1,24 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
 
5
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True)
 
6
 
7
+ def yolo(im, size=640):
8
+ g = (size / max(im.size)) # gain
9
+ im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
10
+
11
+ results = model(im) # inference
12
+ results.render() # updates results.imgs with boxes and labels
13
+ return Image.fromarray(results.imgs[0])
14
+
15
+
16
+ inputs = gr.inputs.Image(type='pil', label="Original Image")
17
+ outputs = gr.outputs.Image(type="pil", label="Output Image")
18
+
19
+ title = "YOLOv5"
20
+ description = "YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use."
21
+ article = "<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, and export to ONNX, CoreML and TFLite. <a href='https://github.com/ultralytics/yolov5'>Source code</a> |<a href='https://apps.apple.com/app/id1452689527'>iOS App</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
22
+
23
+ gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, theme="huggingface").launch(
24
+ debug=True)