rushidarge commited on
Commit
aa0d849
·
verified ·
1 Parent(s): b438fcb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import hf_hub_download
3
+ import yolov9
4
+
5
+
6
+ # Load the model
7
+ model_path = r'./model/V2_best.pt'
8
+ model = yolov9.load(model_path)
9
+
10
+ def yolov9_inference(img_path, conf_threshold, iou_threshold):
11
+ """
12
+ :param conf_threshold: Confidence threshold for NMS.
13
+ :param iou_threshold: IoU threshold for NMS.
14
+ :param img_path: Path to the image file.
15
+ :param size: Optional, input size for inference.
16
+ :return: A tuple containing the detections (boxes, scores, categories) and the results object for further actions like displaying.
17
+ """
18
+ global model
19
+ # Set model parameters
20
+ model.conf = conf_threshold
21
+ model.iou = iou_threshold
22
+
23
+ # Perform inference
24
+ results = model(img_path, size=640)
25
+
26
+ # Optionally, show detection bounding boxes on image
27
+ output = results.render()
28
+
29
+ return output[0]
30
+
31
+
32
+ def app():
33
+ with gr.Blocks():
34
+ with gr.Row():
35
+ with gr.Column():
36
+ img_path = gr.Image(type="filepath", label="Image")
37
+ conf_threshold = gr.Slider(
38
+ label="Confidence Threshold",
39
+ minimum=0.1,
40
+ maximum=1.0,
41
+ step=0.1,
42
+ value=0.4,
43
+ )
44
+ iou_threshold = gr.Slider(
45
+ label="IoU Threshold",
46
+ minimum=0.1,
47
+ maximum=1.0,
48
+ step=0.1,
49
+ value=0.5,
50
+ )
51
+ yolov9_infer = gr.Button(value="Prediction")
52
+
53
+ with gr.Column():
54
+ output_numpy = gr.Image(type="numpy",label="Output")
55
+
56
+ yolov9_infer.click(
57
+ fn=yolov9_inference,
58
+ inputs=[
59
+ img_path,
60
+ conf_threshold,
61
+ iou_threshold,
62
+ ],
63
+ outputs=[output_numpy],
64
+ )
65
+
66
+
67
+ gradio_app = gr.Blocks()
68
+ with gradio_app:
69
+ gr.HTML(
70
+ """
71
+ <h1 style='text-align: center'>
72
+ Traffic Signs Detection - Case Study
73
+ </h1>
74
+ """)
75
+ with gr.Row():
76
+ with gr.Column():
77
+ app()
78
+
79
+ gradio_app.launch(debug=True)