NandanData commited on
Commit
1307b53
Β·
verified Β·
1 Parent(s): 51a17b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
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") # Fire + Smoke YOLOv10 model
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/Smoke Detected"
18
 
19
  output = []
 
20
  for box in results.boxes:
21
- cls = int(box.cls[0]) # 0=fire, 1=smoke
22
  conf = float(box.conf[0])
23
 
24
- if cls == 0:
25
  output.append(f"πŸ”₯ FIRE DETECTED β€” Confidence {conf:.2f}")
26
- elif cls == 1:
27
  output.append(f"πŸ’¨ SMOKE DETECTED β€” Confidence {conf:.2f}")
28
 
29
  if not output:
30
- return "βœ” SAFE β€” No Fire/Smoke Detected"
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 using YOLOv10 model."
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()