asad231's picture
Create app.py
5b9b4a7 verified
import gradio as gr
from detect import detect_theft
from gps import generate_map
from gtts import gTTS
import base64
def run_system(image):
# Step 1: Run theft detection
detected_img, thief_img_path = detect_theft(image)
# Step 2: Generate map
map_file = generate_map()
# Step 3: Voice alert
message = "Alert! Thief detected near GPS location twenty-four point eight six zero seven, sixty-seven point zero zero one one."
tts = gTTS(message)
tts.save("alert.mp3")
audio_file = "alert.mp3"
# Step 4: Convert thief image to HTML
with open(thief_img_path, "rb") as f:
thief_image_bytes = f.read()
thief_image_base64 = base64.b64encode(thief_image_bytes).decode()
thief_image_html = f'<img src="data:image/jpeg;base64,{thief_image_base64}" width="400"/>'
# Step 5: Read map HTML
with open(map_file, "r", encoding="utf-8") as f:
map_html = f.read()
return detected_img, thief_image_html, map_html, audio_file
# Gradio UI
gr.Interface(
fn=run_system,
inputs=gr.Image(type="pil", label="Live CCTV Frame (Auto-detect mode)"),
outputs=[
gr.Image(type="pil", label="πŸ” Detected Theft"),
gr.HTML(label="πŸ•΅οΈβ€β™‚οΈ Thief's Photo"),
gr.HTML(label="πŸ“ GPS Map"),
gr.Audio(label="πŸ—£οΈ Voice Alert"),
],
title="🚨 Theft Detection & Live Location Surveillance AI",
description="AI-based surveillance system to detect theft, capture thief's photo, show location, and generate voice alert automatically."
).launch()