NandanData commited on
Commit
5ab8844
·
verified ·
1 Parent(s): 5b611e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ import numpy as np
4
+ import cv2
5
+
6
+ # Load the fire+smoke model
7
+ model = YOLO("best.pt")
8
+
9
+ def detect_fire_smoke(image):
10
+ if image is None:
11
+ return "Please upload an image"
12
+
13
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
14
+
15
+ results = model(img)[0]
16
+
17
+ # No detection
18
+ if len(results.boxes) == 0:
19
+ return "✔ SAFE — NO FIRE/SMOKE DETECTED"
20
+
21
+ final = []
22
+
23
+ for box in results.boxes:
24
+ cls_id = int(box.cls[0])
25
+ conf = float(box.conf[0])
26
+
27
+ if cls_id == 0:
28
+ final.append(f"🔥 FIRE DETECTED (confidence {conf:.2f})")
29
+ elif cls_id == 1:
30
+ final.append(f"💨 SMOKE DETECTED (confidence {conf:.2f})")
31
+
32
+ if not final:
33
+ return "✔ SAFE — NO FIRE/SMOKE DETECTED"
34
+
35
+ return "\n".join(final)
36
+
37
+ demo = gr.Interface(
38
+ fn=detect_fire_smoke,
39
+ inputs=gr.Image(type="pil"),
40
+ outputs="text",
41
+ title="Fire & Smoke Detection (DEMO)",
42
+ description="Upload an image to test detection using YOLOv10 Fire & Smoke Model."
43
+ )
44
+
45
+ demo.launch()