CoolFace
Apppublic

SY-220/Fire_Detection

sourceHugging Facemitupdated 24d agoView on Hugging Face
0likes
App README

YOLOv8 Fire & Smoke Detection System (with Email Alerts)

A desktop application that downloads a YouTube video, runs YOLOv8-based fire/smoke detection on it frame-by-frame, and optionally sends an email alert — complete with a screenshot of the detected fire — the moment fire is first spotted. Comes with a simple Tkinter GUI so no code editing is required to run it.

Features

  • YOLOv8 fire/smoke detection: automatically downloads a dedicated fire-and-smoke YOLOv8 model (falls back to stock yolov8n.pt if the download fails).
  • YouTube video input: fetches and processes any YouTube URL via yt-dlp (with an automatic fallback download strategy if the primary one fails).
  • Optional email alerts: powered by Resend. When fire is first detected, sends one HTML alert email containing:
  • Detection timestamp, video position, fire count, and average confidence
  • An embedded screenshot of the exact frame where fire was detected, with the bounding box and warning overlay already drawn on it
  • The same screenshot attached as a JPEG file, so it's visible even in email clients that block inline images
  • Only one alert is sent per run (no spam on every subsequent detection).
  • Tkinter GUI: fill in a YouTube URL, an optional Resend API key, and optional recipient emails — no command-line arguments needed.
  • Start / Stop control: detection runs in a background thread so the GUI stays responsive; Stop cleanly interrupts processing after the current frame and still saves everything detected so far.
  • CSV detection log: every detection (class, confidence, bounding box, timestamp) is logged to detection_log.csv, downloadable straight from the GUI via a save-file dialog.
  • Additional outputs: an annotated output video (detected_output.mp4), a plain-text fire summary report, and a detailed .txt log.

How It Works

  1. 1.Enter a YouTube URL (required) and, optionally, a Resend API key and comma-separated recipient list.
  2. 2.Click Start Detection. In the background, the app:
  3. 3.Downloads the video with yt-dlp.
  4. 4.Loads the YOLOv8 fire/smoke model.
  5. 5.Steps through the video (every 3rd frame, for speed), running inference and drawing bounding boxes.
  6. 6.The moment fire is detected, it captures that annotated frame and — if email is configured — sends an alert email with the screenshot embedded and attached.
  7. 7.Writes an annotated output video and detection logs to fire_detection_output/.
  8. 8.Click Stop Detection at any time to interrupt processing; partial results are still saved.
  9. 9.Click Download CSV to save a copy of detection_log.csv anywhere on disk.

Requirements

opencv-python
yt-dlp
ultralytics
pandas
resend

tkinter ships with most standard Python installations (on some Linux distros you may need to install it separately, e.g. sudo apt install python3-tk).

ffmpeg should be available on your PATH for video format conversion in the fallback download path.

Installation

bash
pip install opencv-python yt-dlp ultralytics pandas resend

Usage

bash
jupyter YT_fire detection_Resend_GUI_fin.ipynb

This opens the GUI:

FieldRequiredNotes
YouTube URLThe video to analyze
Resend API KeyOnly needed if you want email alerts
RecipientsComma-separated email addresses; email alerts stay disabled unless both this and the API key are filled in
Confidence thresholdDefaults to 0.3

Buttons:

  • Start Detection / Stop Detection — toggles processing on and off
  • Download CSV — saves a copy of the current detection_log.csv to a location you choose
Note on live preview: unlike a plain OpenCV script, this GUI runs detection headlessly (no cv2.imshow preview window), since mixing an OpenCV GUI window with Tkinter's event loop across threads is unreliable on some platforms. The annotated video is still saved to disk, and progress/results stream into the log panel in real time.

Output Files

All outputs are written to fire_detection_output/:

FileDescription
detected_output.mp4Annotated video with bounding boxes and on-screen detection info
detection_log.csvEvery detection: timestamp, frame number, video time, class, confidence, bounding box
fire_summary_report.txtSummary of fire-only detections
detection_log.txtFull plain-text detection log
fire_smoke_best.ptThe downloaded YOLOv8 fire/smoke model weights

Email Alert Example

When fire is first detected, the alert email includes:

  • 🚨 A header banner and detection summary (time, video position, fire count, average confidence)
  • 📸 A screenshot of the fire, embedded directly in the email body and attached as fire_screenshot.jpg
  • ✅ Recommended next actions (confirm on-site situation, evacuate if necessary, contact the fire department, review the footage)

Limitations

  • Detection quality depends entirely on the underlying YOLOv8 fire/smoke model; false positives/negatives are possible, especially with sunset lighting, warm-colored objects, or heavy compression artifacts.
  • Only processes pre-recorded YouTube videos, not live streams or local webcams.
  • Requires a working internet connection to download the video and model, and to send email alerts.
  • Not a certified life-safety system — intended as a demo/prototype for research and educational purposes, not as a replacement for professional fire detection and alarm systems.
  • Email sending depends on your Resend account being properly configured (verified sender domain, valid API key, etc.).

License

MIT