edcelbogs's picture
Update app.py
126307a verified
raw
history blame contribute delete
881 Bytes
from ultralytics import YOLO
import gradio as gr
import cv2
import numpy as np
# ---------------- LOAD MODEL ----------------
model = YOLO("nano_best.pt")
# ---------------- DETECTION FUNCTION ----------------
def detect(image):
if image is None:
return None
# Convert to OpenCV format
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
# YOLO inference
results = model.predict(
source=img,
conf=0.35,
iou=0.1,
imgsz=640,
verbose=False
)
# Plot results
annotated = results[0].plot()
return annotated
# ---------------- GRADIO UI ----------------
interface = gr.Interface(
fn=detect,
inputs=gr.Image(type="pil"),
outputs=gr.Image(type="numpy"),
title="🔥 Fire & Smoke Detection (YOLOv8)",
description="Upload an image to detect fire or smoke."
)
interface.launch()