asad231 commited on
Commit
5b9b4a7
·
verified ·
1 Parent(s): 3483658

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from detect import detect_theft
3
+ from gps import generate_map
4
+ from gtts import gTTS
5
+ import base64
6
+
7
+ def run_system(image):
8
+ # Step 1: Run theft detection
9
+ detected_img, thief_img_path = detect_theft(image)
10
+
11
+ # Step 2: Generate map
12
+ map_file = generate_map()
13
+
14
+ # Step 3: Voice alert
15
+ message = "Alert! Thief detected near GPS location twenty-four point eight six zero seven, sixty-seven point zero zero one one."
16
+ tts = gTTS(message)
17
+ tts.save("alert.mp3")
18
+ audio_file = "alert.mp3"
19
+
20
+ # Step 4: Convert thief image to HTML
21
+ with open(thief_img_path, "rb") as f:
22
+ thief_image_bytes = f.read()
23
+ thief_image_base64 = base64.b64encode(thief_image_bytes).decode()
24
+ thief_image_html = f'<img src="data:image/jpeg;base64,{thief_image_base64}" width="400"/>'
25
+
26
+ # Step 5: Read map HTML
27
+ with open(map_file, "r", encoding="utf-8") as f:
28
+ map_html = f.read()
29
+
30
+ return detected_img, thief_image_html, map_html, audio_file
31
+
32
+ # Gradio UI
33
+ gr.Interface(
34
+ fn=run_system,
35
+ inputs=gr.Image(type="pil", label="Live CCTV Frame (Auto-detect mode)"),
36
+ outputs=[
37
+ gr.Image(type="pil", label="🔍 Detected Theft"),
38
+ gr.HTML(label="🕵️‍♂️ Thief's Photo"),
39
+ gr.HTML(label="📍 GPS Map"),
40
+ gr.Audio(label="🗣️ Voice Alert"),
41
+ ],
42
+ title="🚨 Theft Detection & Live Location Surveillance AI",
43
+ description="AI-based surveillance system to detect theft, capture thief's photo, show location, and generate voice alert automatically."
44
+ ).launch()