SakshiRathi77 commited on
Commit
5d35d9a
1 Parent(s): d02e46f

Upload app (2).py

Browse files
Files changed (1) hide show
  1. app (2).py +87 -0
app (2).py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import spaces
4
+ from huggingface_hub import hf_hub_download
5
+ import yolov9
6
+
7
+ def yolov9_inference(img_path, model_id, image_size, conf_threshold, iou_threshold):
8
+
9
+ # Load the model
10
+ # model_path = download_models(model_id)
11
+ model = yolov9.load(model_id)
12
+ # Set model parameters
13
+ model.conf = conf_threshold
14
+ model.iou = iou_threshold
15
+ # Perform inference
16
+ results = model(img_path, size=image_size)
17
+ # Optionally, show detection bounding boxes on image
18
+ output = results.render()
19
+ return output[0]
20
+
21
+
22
+ def app():
23
+ with gr.Blocks():
24
+ with gr.Row():
25
+ with gr.Column():
26
+ img_path = gr.Image(type="filepath", label="Image")
27
+ model_path = gr.Dropdown(
28
+ label="Model",
29
+ choices=[
30
+ "best.pt",
31
+ ],
32
+ value="./best.pt",
33
+ )
34
+ image_size = gr.Slider(
35
+ label="Image Size",
36
+ minimum=320,
37
+ maximum=1280,
38
+ step=32,
39
+ value=640,
40
+ )
41
+ conf_threshold = gr.Slider(
42
+ label="Confidence Threshold",
43
+ minimum=0.1,
44
+ maximum=1.0,
45
+ step=0.1,
46
+ value=0.4,
47
+ )
48
+ iou_threshold = gr.Slider(
49
+ label="IoU Threshold",
50
+ minimum=0.1,
51
+ maximum=1.0,
52
+ step=0.1,
53
+ value=0.5,
54
+ )
55
+ yolov9_infer = gr.Button(value="Inference")
56
+
57
+ with gr.Column():
58
+ output_numpy = gr.Image(type="numpy",label="Output")
59
+
60
+ yolov9_infer.click(
61
+ fn=yolov9_inference,
62
+ inputs=[
63
+ img_path,
64
+ model_path,
65
+ image_size,
66
+ conf_threshold,
67
+ iou_threshold,
68
+ ],
69
+ outputs=[output_numpy],
70
+ )
71
+
72
+
73
+
74
+
75
+ gradio_app = gr.Blocks()
76
+ with gradio_app:
77
+ gr.HTML(
78
+ """
79
+ <h1 style='text-align: center'>
80
+ YOLOv9: Detect Void Space in Retail Shelf
81
+ </h1>
82
+ """)
83
+ with gr.Row():
84
+ with gr.Column():
85
+ app()
86
+
87
+ gradio_app.launch(debug=True)