SakibRumu
Upload app.py
35a7ff1 verified
raw
history blame
1.25 kB
# vision-space/app.py (Hugging Face + Gradio version of your local code)
import gradio as gr
import cv2
import numpy as np
from ultralytics import YOLO
model = YOLO("best.pt") # YOLOv10 model trained for smoke/fire
def detect_fire_smoke_from_image(image):
results = model(image)
flame_score = 0.0
smoke_score = 0.0
person_detected = 0
for result in results:
for box in result.boxes:
label = result.names[int(box.cls)]
conf = float(box.conf)
if "fire" in label.lower():
flame_score = max(flame_score, conf)
elif "smoke" in label.lower():
smoke_score = max(smoke_score, conf)
elif "person" in label.lower():
person_detected = 1
return {
"cv_flame_score": round(flame_score, 3),
"cv_smoke_score": round(smoke_score, 3),
"person_detected": person_detected
}
iface = gr.Interface(
fn=detect_fire_smoke_from_image,
inputs=gr.Image(type="numpy"),
outputs="json",
title="Vison Model for Fire, Smoke, and Person Detection",
description="Upload or stream an image from video feed for real-time detection."
)
if __name__ == "__main__":
iface.launch(inline=False)