File size: 1,074 Bytes
5ab8844
 
 
 
 
1307b53
 
5ab8844
 
 
 
 
 
 
 
 
1307b53
5ab8844
74e16c9
1307b53
5ab8844
1307b53
5ab8844
 
1307b53
beae699
1307b53
beae699
5ab8844
74e16c9
1307b53
5ab8844
74e16c9
5ab8844
 
 
 
 
1307b53
 
5ab8844
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gradio as gr
from ultralytics import YOLO
import numpy as np
import cv2

# Load YOLOv10 Fire + Smoke model
model = YOLO("best.pt") 

def detect_fire_smoke(image):
    if image is None:
        return "Please upload an image"

    img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
    results = model(img)[0]

    if len(results.boxes) == 0:
        return "βœ” SAFE β€” No Fire or Smoke Detected"

    output = []

    for box in results.boxes:
        cls_id = int(box.cls[0])  # YOLOv10 classes
        conf = float(box.conf[0])

        if cls_id == 0:
            output.append(f"πŸ”₯ FIRE DETECTED β€” Confidence {conf:.2f}")
        elif cls_id == 1:
            output.append(f"πŸ’¨ SMOKE DETECTED β€” Confidence {conf:.2f}")

    if not output:
        return "βœ” SAFE β€” No Fire or Smoke Detected"

    return "\n".join(output)

demo = gr.Interface(
    fn=detect_fire_smoke,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="Fire & Smoke Detection (YOLOv10)",
    description="Upload an image to detect fire or smoke."
)

demo.launch()