FireDetection / app.py
Last commit not found
raw
history blame
1.22 kB
import gradio as gr
import os
from firedetection import detect_fire_in_video
# Temporary directory to store results
TEMP_DIR = "temp_outputs"
os.makedirs(TEMP_DIR, exist_ok=True)
def fire_detection_interface(video_file):
"""
Gradio interface function that:
1) Receives an uploaded video.
2) Calls detect_fire_in_video.
3) Returns the path of the processed video for display in Gradio.
"""
if video_file is None:
return None
# Extract filename
input_video_path = video_file
base_name = os.path.basename(input_video_path)
name_no_ext, ext = os.path.splitext(base_name)
output_path = os.path.join(TEMP_DIR, f"{name_no_ext}_fire{ext}")
processed_path = detect_fire_in_video(
input_video_path=input_video_path,
output_video_path=output_path,
model_path="yolov12n.pt",
device="cpu"
)
return processed_path
demo = gr.Interface(
fn=fire_detection_interface,
inputs=gr.Video(label="Upload a Video"),
outputs=gr.Video(label="Annotated Video"),
title="Fire Detection with YOLO",
description="This interface detects fire in an uploaded video using YOLO."
)
if __name__ == "__main__":
demo.launch()