Spaces:
Runtime error
Runtime error
StarAtNyte1
commited on
Commit
•
b498d3d
1
Parent(s):
2150cef
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,50 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|