sagar007 commited on
Commit
cfb69be
·
verified ·
1 Parent(s): cb33707

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -57
app.py CHANGED
@@ -4,59 +4,6 @@ from PIL import Image
4
  import os
5
  import yolov9
6
 
7
- import gradio as gr
8
- import torch
9
- from PIL import Image
10
- import os
11
- import yolov9
12
-
13
- def yolov9_inference(img_path, image_size, conf_threshold, iou_threshold):
14
- model = yolov9.load('./best.pt')
15
- model.conf = conf_threshold
16
- model.iou = iou_threshold
17
- results = model(img_path, size=image_size)
18
- output = results.render()
19
- return output[0]
20
-
21
- def app():
22
- with gr.Blocks() as demo:
23
- gr.HTML(HTML_TEMPLATE)
24
-
25
- with gr.Row():
26
- with gr.Column(scale=1, min_width=300):
27
- img_path = gr.Image(type="filepath", label="Upload Image")
28
- image_size = gr.Slider(label="Image Size", minimum=320, maximum=1280, step=32, value=640)
29
- conf_threshold = gr.Slider(label="Confidence Threshold", minimum=0.1, maximum=1.0, step=0.1, value=0.4)
30
- iou_threshold = gr.Slider(label="IoU Threshold", minimum=0.1, maximum=1.0, step=0.1, value=0.5)
31
- detect_button = gr.Button("Detect Manholes", variant="primary")
32
-
33
- with gr.Column(scale=1, min_width=300):
34
- output_numpy = gr.Image(type="numpy", label="Detection Result")
35
-
36
- detect_button.click(
37
- fn=yolov9_inference,
38
- inputs=[img_path, image_size, conf_threshold, iou_threshold],
39
- outputs=[output_numpy]
40
- )
41
-
42
- gr.Examples(
43
- examples=[
44
- ["./openmanhole.jpg", 640, 0.4, 0.5],
45
- ["./images.jpeg", 640, 0.4, 0.5],
46
- ],
47
- fn=yolov9_inference,
48
- inputs=[img_path, image_size, conf_threshold, iou_threshold],
49
- outputs=[output_numpy],
50
- cache_examples=True,
51
- )
52
-
53
- return demo
54
- import gradio as gr
55
- import torch
56
- from PIL import Image
57
- import os
58
- import yolov9
59
-
60
  HTML_TEMPLATE = """
61
  <style>
62
  body {
@@ -193,16 +140,46 @@ HTML_TEMPLATE = """
193
  </div>
194
  """
195
 
196
- # Your existing yolov9_inference function here
197
  def yolov9_inference(img_path, image_size, conf_threshold, iou_threshold):
198
- # ... (your existing code)
 
 
 
 
 
199
 
200
  def app():
201
  with gr.Blocks() as demo:
202
  gr.HTML(HTML_TEMPLATE)
203
 
204
- # ... (rest of your existing app code)
205
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  return demo
207
 
208
  css = """
 
4
  import os
5
  import yolov9
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  HTML_TEMPLATE = """
8
  <style>
9
  body {
 
140
  </div>
141
  """
142
 
 
143
  def yolov9_inference(img_path, image_size, conf_threshold, iou_threshold):
144
+ model = yolov9.load('./best.pt')
145
+ model.conf = conf_threshold
146
+ model.iou = iou_threshold
147
+ results = model(img_path, size=image_size)
148
+ output = results.render()
149
+ return output[0]
150
 
151
  def app():
152
  with gr.Blocks() as demo:
153
  gr.HTML(HTML_TEMPLATE)
154
 
155
+ with gr.Row():
156
+ with gr.Column(scale=1, min_width=300):
157
+ img_path = gr.Image(type="filepath", label="Upload Image")
158
+ image_size = gr.Slider(label="Image Size", minimum=320, maximum=1280, step=32, value=640)
159
+ conf_threshold = gr.Slider(label="Confidence Threshold", minimum=0.1, maximum=1.0, step=0.1, value=0.4)
160
+ iou_threshold = gr.Slider(label="IoU Threshold", minimum=0.1, maximum=1.0, step=0.1, value=0.5)
161
+ detect_button = gr.Button("Detect Manholes", variant="primary")
162
+
163
+ with gr.Column(scale=1, min_width=300):
164
+ output_numpy = gr.Image(type="numpy", label="Detection Result")
165
+
166
+ detect_button.click(
167
+ fn=yolov9_inference,
168
+ inputs=[img_path, image_size, conf_threshold, iou_threshold],
169
+ outputs=[output_numpy]
170
+ )
171
+
172
+ gr.Examples(
173
+ examples=[
174
+ ["./openmanhole.jpg", 640, 0.4, 0.5],
175
+ ["./images.jpeg", 640, 0.4, 0.5],
176
+ ],
177
+ fn=yolov9_inference,
178
+ inputs=[img_path, image_size, conf_threshold, iou_threshold],
179
+ outputs=[output_numpy],
180
+ cache_examples=True,
181
+ )
182
+
183
  return demo
184
 
185
  css = """