FireDetection / app.py
NandanData's picture
Update app.py
beae699 verified
raw
history blame
1.08 kB
import gradio as gr
from ultralytics import YOLO
import numpy as np
import cv2
# Load model
model = YOLO("best.pt") # Fire + Smoke YOLOv10 model
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/Smoke Detected"
output = []
for box in results.boxes:
cls = int(box.cls[0]) # 0=fire, 1=smoke
conf = float(box.conf[0])
if cls == 0:
output.append(f"πŸ”₯ FIRE DETECTED β€” Confidence {conf:.2f}")
elif cls == 1:
output.append(f"πŸ’¨ SMOKE DETECTED β€” Confidence {conf:.2f}")
if not output:
return "βœ” SAFE β€” No Fire/Smoke Detected"
return "\n".join(output)
demo = gr.Interface(
fn=detect_fire_smoke,
inputs=gr.Image(type="pil"),
outputs="text",
title="Fire & Smoke Detection",
description="Upload an image to detect fire or smoke using YOLOv10 model."
)
demo.launch()