StarAtNyte1 commited on
Commit
b498d3d
1 Parent(s): 2150cef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -26
app.py CHANGED
@@ -1,28 +1,50 @@
1
  import gradio as gr
2
  import torch
3
- from PIL import Image
4
- import os
5
-
6
-
7
- # Model
8
- model = torch.hub.load('StarAtNyte1/yolov7_custom', 'best') # force_reload=True to update
9
-
10
- def yolo(im):
11
- g = (size / max(im.size)) # gain
12
- im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
13
-
14
- results = model(im) # inference
15
- results.render() # updates results.imgs with boxes and labels
16
- results.save()
17
- os.system("ls")
18
- return "out.png"
19
-
20
-
21
- inputs = gr.inputs.Image(type='pil', label="Original Image")
22
- outputs = gr.outputs.Image(type="file", label="Output Image")
23
-
24
- title = "YOLOv7"
25
- description = "YOLOv7 Gradio demo for object detection. Upload an image or click an example image to use."
26
-
27
- examples = [['zidane.jpg'], ['bus.jpg']]
28
- gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, theme="huggingface").launch(cache_examples=True,enable_queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
+ import yolov7
4
+
5
+
6
+ # Images
7
+ torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
8
+ torch.hub.download_url_to_file('https://raw.githubusercontent.com/obss/sahi/main/tests/data/small-vehicles1.jpeg', 'small-vehicles1.jpeg')
9
+
10
+ def yolov7_inference(
11
+ image: gr.inputs.Image = None,
12
+ model_path: gr.inputs.Dropdown = None,
13
+ image_size: gr.inputs.Slider = 640,
14
+ conf_threshold: gr.inputs.Slider = 0.25,
15
+ iou_threshold: gr.inputs.Slider = 0.45,
16
+ ):
17
+
18
+ model = yolov7.load(model_path, device="cpu", hf_model=True, trace=False)
19
+ model.conf = conf_threshold
20
+ model.iou = iou_threshold
21
+ results = model([image], size=image_size)
22
+ return results.render()[0]
23
+
24
+
25
+ inputs = [
26
+ gr.inputs.Image(type="pil", label="Input Image"),
27
+ gr.inputs.Dropdown(
28
+ choices=[
29
+ "StarAtNyte1/yolov7_custom",
30
+
31
+ ],
32
+ default="StarAtNyte1/yolov7_custom",
33
+ label="Model",
34
+ ),
35
+ ]
36
+
37
+ outputs = gr.outputs.Image(type="filepath", label="Output Image")
38
+ title = "Yolov7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors"
39
+
40
+ examples = [['small-vehicles1.jpeg', 'kadirnar/yolov7-tiny-v0.1', 640, 0.25, 0.45], ['zidane.jpg', 'kadirnar/yolov7-v0.1', 640, 0.25, 0.45]]
41
+ demo_app = gr.Interface(
42
+ fn=yolov7_inference,
43
+ inputs=inputs,
44
+ outputs=outputs,
45
+ title=title,
46
+ examples=examples,
47
+ cache_examples=True,
48
+ theme='huggingface',
49
+ )
50
+ demo_app.launch(debug=True, enable_queue=True)