Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,8 @@ from ultralytics import YOLO
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
-
# Load model
|
| 7 |
-
model = YOLO("best.pt")
|
| 8 |
|
| 9 |
def detect_fire_smoke(image):
|
| 10 |
if image is None:
|
|
@@ -14,20 +14,21 @@ def detect_fire_smoke(image):
|
|
| 14 |
results = model(img)[0]
|
| 15 |
|
| 16 |
if len(results.boxes) == 0:
|
| 17 |
-
return "β SAFE β No Fire
|
| 18 |
|
| 19 |
output = []
|
|
|
|
| 20 |
for box in results.boxes:
|
| 21 |
-
|
| 22 |
conf = float(box.conf[0])
|
| 23 |
|
| 24 |
-
if
|
| 25 |
output.append(f"π₯ FIRE DETECTED β Confidence {conf:.2f}")
|
| 26 |
-
elif
|
| 27 |
output.append(f"π¨ SMOKE DETECTED β Confidence {conf:.2f}")
|
| 28 |
|
| 29 |
if not output:
|
| 30 |
-
return "β SAFE β No Fire
|
| 31 |
|
| 32 |
return "\n".join(output)
|
| 33 |
|
|
@@ -35,8 +36,8 @@ demo = gr.Interface(
|
|
| 35 |
fn=detect_fire_smoke,
|
| 36 |
inputs=gr.Image(type="pil"),
|
| 37 |
outputs="text",
|
| 38 |
-
title="Fire & Smoke Detection",
|
| 39 |
-
description="Upload an image to detect fire or smoke
|
| 40 |
)
|
| 41 |
|
| 42 |
demo.launch()
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
+
# Load YOLOv10 Fire + Smoke model
|
| 7 |
+
model = YOLO("best.pt")
|
| 8 |
|
| 9 |
def detect_fire_smoke(image):
|
| 10 |
if image is None:
|
|
|
|
| 14 |
results = model(img)[0]
|
| 15 |
|
| 16 |
if len(results.boxes) == 0:
|
| 17 |
+
return "β SAFE β No Fire or Smoke Detected"
|
| 18 |
|
| 19 |
output = []
|
| 20 |
+
|
| 21 |
for box in results.boxes:
|
| 22 |
+
cls_id = int(box.cls[0]) # YOLOv10 classes
|
| 23 |
conf = float(box.conf[0])
|
| 24 |
|
| 25 |
+
if cls_id == 0:
|
| 26 |
output.append(f"π₯ FIRE DETECTED β Confidence {conf:.2f}")
|
| 27 |
+
elif cls_id == 1:
|
| 28 |
output.append(f"π¨ SMOKE DETECTED β Confidence {conf:.2f}")
|
| 29 |
|
| 30 |
if not output:
|
| 31 |
+
return "β SAFE β No Fire or Smoke Detected"
|
| 32 |
|
| 33 |
return "\n".join(output)
|
| 34 |
|
|
|
|
| 36 |
fn=detect_fire_smoke,
|
| 37 |
inputs=gr.Image(type="pil"),
|
| 38 |
outputs="text",
|
| 39 |
+
title="Fire & Smoke Detection (YOLOv10)",
|
| 40 |
+
description="Upload an image to detect fire or smoke."
|
| 41 |
)
|
| 42 |
|
| 43 |
demo.launch()
|