Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,9 @@ import os
|
|
5 |
from ultralytics import YOLO
|
6 |
|
7 |
file_urls = [
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
]
|
12 |
|
13 |
def download_file(url, save_name):
|
@@ -29,7 +29,9 @@ def show_preds_image(image_path):
|
|
29 |
image = cv2.imread(image_path)
|
30 |
outputs = model.predict(source=image_path)
|
31 |
results = outputs[0].cpu().numpy()
|
|
|
32 |
for i, det in enumerate(results.boxes.xyxy):
|
|
|
33 |
cv2.rectangle(
|
34 |
image,
|
35 |
(int(det[0]), int(det[1])),
|
@@ -38,8 +40,36 @@ def show_preds_image(image_path):
|
|
38 |
thickness=2,
|
39 |
lineType=cv2.LINE_AA
|
40 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
inputs_image = [
|
44 |
gr.Image(type="filepath", label="Input Image"),
|
45 |
]
|
@@ -51,7 +81,7 @@ interface_image = gr.Interface(
|
|
51 |
fn=show_preds_image,
|
52 |
inputs=inputs_image,
|
53 |
outputs=outputs_image,
|
54 |
-
title="
|
55 |
examples=path,
|
56 |
cache_examples=False,
|
57 |
)
|
|
|
5 |
from ultralytics import YOLO
|
6 |
|
7 |
file_urls = [
|
8 |
+
'https://www.dropbox.com/scl/fi/kqd1z6wby1212c6ndodb3/Pol_20_jpg.rf.133c835b66958a7d48c12deeda31a719.jpg?rlkey=uqgvs2cwvahnmju15fv1zgorg&st=snv2yvtk&dl=0',
|
9 |
+
'https://www.dropbox.com/scl/fi/39aakapeh2y5ztk94rsyu/11e-a347-3f2d_jpg.rf.c66e5aeb57ee2ed660fdf0162156127d.jpg?rlkey=xoi3iw45vksgiejycau2ha7fh&st=etiawigv&dl=0',
|
10 |
+
'https://www.dropbox.com/scl/fi/8f08ehy53vsemw164g8n7/Recording2024-06-26184319.mp4?rlkey=pnmov906ttodl0cm92rpvc5ta&st=2twc9pjn&dl=0'
|
11 |
]
|
12 |
|
13 |
def download_file(url, save_name):
|
|
|
29 |
image = cv2.imread(image_path)
|
30 |
outputs = model.predict(source=image_path)
|
31 |
results = outputs[0].cpu().numpy()
|
32 |
+
|
33 |
for i, det in enumerate(results.boxes.xyxy):
|
34 |
+
# Draw the bounding box
|
35 |
cv2.rectangle(
|
36 |
image,
|
37 |
(int(det[0]), int(det[1])),
|
|
|
40 |
thickness=2,
|
41 |
lineType=cv2.LINE_AA
|
42 |
)
|
43 |
+
|
44 |
+
# Get the class label and confidence score
|
45 |
+
class_id = int(results.boxes.cls[i])
|
46 |
+
confidence = results.boxes.conf[i]
|
47 |
+
label = f"{model.names[class_id]}: {confidence:.2f}"
|
48 |
+
|
49 |
+
# Draw the label
|
50 |
+
label_size, _ = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
|
51 |
+
top_left = (int(det[0]), int(det[1]) - 10)
|
52 |
+
bottom_right = (int(det[0]) + label_size[0], int(det[1]))
|
53 |
+
cv2.rectangle(image, top_left, bottom_right, (0, 0, 255), cv2.FILLED)
|
54 |
+
cv2.putText(image, label, (int(det[0]), int(det[1]) - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
|
55 |
+
|
56 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
57 |
|
58 |
+
# def show_preds_image(image_path):
|
59 |
+
# image = cv2.imread(image_path)
|
60 |
+
# outputs = model.predict(source=image_path)
|
61 |
+
# results = outputs[0].cpu().numpy()
|
62 |
+
# for i, det in enumerate(results.boxes.xyxy):
|
63 |
+
# cv2.rectangle(
|
64 |
+
# image,
|
65 |
+
# (int(det[0]), int(det[1])),
|
66 |
+
# (int(det[2]), int(det[3])),
|
67 |
+
# color=(0, 0, 255),
|
68 |
+
# thickness=2,
|
69 |
+
# lineType=cv2.LINE_AA
|
70 |
+
# )
|
71 |
+
# return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
72 |
+
|
73 |
inputs_image = [
|
74 |
gr.Image(type="filepath", label="Input Image"),
|
75 |
]
|
|
|
81 |
fn=show_preds_image,
|
82 |
inputs=inputs_image,
|
83 |
outputs=outputs_image,
|
84 |
+
title="Smoke Detection on Indian Roads",
|
85 |
examples=path,
|
86 |
cache_examples=False,
|
87 |
)
|