Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,35 @@
|
|
|
|
1 |
import torch
|
|
|
|
|
2 |
import gradio as gr
|
|
|
|
|
3 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
4 |
from PIL import Image, ImageDraw
|
|
|
|
|
5 |
import numpy as np
|
|
|
|
|
6 |
import json
|
|
|
|
|
7 |
import cv2
|
|
|
|
|
8 |
from scipy.ndimage import gaussian_filter
|
9 |
|
|
|
10 |
# Constants and Model Downloads
|
11 |
REPO_ID = "thoucentric/Shelf_Objects_Detection_Yolov7_Pytorch"
|
12 |
FILENAME = "best.pt"
|
13 |
yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
14 |
|
15 |
# Load YOLOv7 Custom Model
|
|
|
16 |
model = torch.hub.load('Owaiskhan9654/yolov7-1:main', model='custom', path_or_model=yolov7_custom_weights, force_reload=True)
|
17 |
|
18 |
# Image Splitting and Merging Functionality
|
@@ -196,36 +213,42 @@ inputs = [
|
|
196 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.01, label="Confidence Threshold"),
|
197 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.01, label="IOU Threshold"),
|
198 |
]
|
199 |
-
outputs_image =
|
|
|
|
|
200 |
outputs_json = gr.Textbox(label="Bounding Boxes JSON")
|
201 |
|
202 |
title = "<center>Yolov7 Custom Object Detection</center>"
|
203 |
description = "<center>Nolen Felten</center>"
|
204 |
footer = ("<br><br><center><b>Item Classes it will detect (Total 140 Classes)</b></center>")
|
205 |
|
206 |
-
# Regular Object Detection Interface
|
207 |
-
interface = gr.Interface(
|
208 |
-
fn=object_detection,
|
209 |
-
inputs=inputs,
|
210 |
-
outputs=[outputs_image, outputs_json],
|
211 |
-
title=title,
|
212 |
-
description=description,
|
213 |
-
article=footer,
|
214 |
-
cache_examples=False,
|
215 |
-
allow_flagging="never"
|
216 |
-
)
|
217 |
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
# Edge Enhanced Density-Based Counting Interface
|
231 |
inputs_density_edge = [
|
|
|
1 |
+
print("import torch")
|
2 |
import torch
|
3 |
+
|
4 |
+
print("import gradio")
|
5 |
import gradio as gr
|
6 |
+
|
7 |
+
print("import huggingface_hub")
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
+
|
10 |
+
print("import PIL")
|
11 |
from PIL import Image, ImageDraw
|
12 |
+
|
13 |
+
print("import numpy")
|
14 |
import numpy as np
|
15 |
+
|
16 |
+
print("import json")
|
17 |
import json
|
18 |
+
|
19 |
+
print("import opencv")
|
20 |
import cv2
|
21 |
+
|
22 |
+
print("import scipy")
|
23 |
from scipy.ndimage import gaussian_filter
|
24 |
|
25 |
+
|
26 |
# Constants and Model Downloads
|
27 |
REPO_ID = "thoucentric/Shelf_Objects_Detection_Yolov7_Pytorch"
|
28 |
FILENAME = "best.pt"
|
29 |
yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
30 |
|
31 |
# Load YOLOv7 Custom Model
|
32 |
+
print("Load YOLOv7 Custom Model")
|
33 |
model = torch.hub.load('Owaiskhan9654/yolov7-1:main', model='custom', path_or_model=yolov7_custom_weights, force_reload=True)
|
34 |
|
35 |
# Image Splitting and Merging Functionality
|
|
|
213 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.01, label="Confidence Threshold"),
|
214 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.01, label="IOU Threshold"),
|
215 |
]
|
216 |
+
outputs_image = [
|
217 |
+
gr.outputs.Image(type="pil", label="Output Image")
|
218 |
+
]
|
219 |
outputs_json = gr.Textbox(label="Bounding Boxes JSON")
|
220 |
|
221 |
title = "<center>Yolov7 Custom Object Detection</center>"
|
222 |
description = "<center>Nolen Felten</center>"
|
223 |
footer = ("<br><br><center><b>Item Classes it will detect (Total 140 Classes)</b></center>")
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
+
interfaces = [
|
227 |
+
# Regular Object Detection Interface
|
228 |
+
gr.Interface(
|
229 |
+
fn=object_detection,
|
230 |
+
inputs=inputs,
|
231 |
+
outputs=[outputs_image, outputs_json],
|
232 |
+
title=title,
|
233 |
+
description=description,
|
234 |
+
article=footer,
|
235 |
+
cache_examples=False,
|
236 |
+
allow_flagging="never"
|
237 |
+
),
|
238 |
+
|
239 |
+
|
240 |
+
# Edge Enhanced Object Detection Interface
|
241 |
+
gr.Interface(
|
242 |
+
fn=object_detection_with_edge_enhancement,
|
243 |
+
inputs=inputs,
|
244 |
+
outputs=[outputs_image, outputs_json],
|
245 |
+
title="Object Detection with Edge Enhancement",
|
246 |
+
description=description,
|
247 |
+
article=footer,
|
248 |
+
cache_examples=False,
|
249 |
+
allow_flagging="never"
|
250 |
+
)
|
251 |
+
]
|
252 |
|
253 |
# Edge Enhanced Density-Based Counting Interface
|
254 |
inputs_density_edge = [
|