Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,29 +32,70 @@
|
|
32 |
|
33 |
# demo.launch()
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
import gradio as gr
|
36 |
import datetime
|
37 |
|
38 |
-
def
|
39 |
-
|
40 |
-
alert = f"π¨ Theft detected at {
|
41 |
-
map_embed = f"""
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.Markdown("## π¨ Theft
|
46 |
|
47 |
with gr.Row():
|
48 |
-
|
49 |
with gr.Column():
|
50 |
lat = gr.Number(label="Latitude", value=24.8607)
|
51 |
lon = gr.Number(label="Longitude", value=67.0011)
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
map_html = gr.HTML(label="Live Location Map")
|
57 |
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
demo.launch()
|
|
|
|
32 |
|
33 |
# demo.launch()
|
34 |
|
35 |
+
# import gradio as gr
|
36 |
+
# import datetime
|
37 |
+
|
38 |
+
# def detect_theft(frame, lat, lon):
|
39 |
+
# time_detected = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
40 |
+
# alert = f"π¨ Theft detected at {time_detected}!"
|
41 |
+
# map_embed = f"""<iframe width="100%" height="300" src="https://maps.google.com/maps?q={lat},{lon}&z=15&output=embed"></iframe>"""
|
42 |
+
# return alert, frame, map_embed
|
43 |
+
|
44 |
+
# with gr.Blocks() as demo:
|
45 |
+
# gr.Markdown("## π¨ Theft Detection & Live Location Surveillance AI")
|
46 |
+
|
47 |
+
# with gr.Row():
|
48 |
+
# cam = gr.Image(label="Upload Thief Image", type="pil")
|
49 |
+
# with gr.Column():
|
50 |
+
# lat = gr.Number(label="Latitude", value=24.8607)
|
51 |
+
# lon = gr.Number(label="Longitude", value=67.0011)
|
52 |
+
# detect_btn = gr.Button("π Show Location on Map")
|
53 |
+
|
54 |
+
# alert = gr.Textbox(label="Alert")
|
55 |
+
# captured = gr.Image(label="Thief Image")
|
56 |
+
# map_html = gr.HTML(label="Live Location Map")
|
57 |
+
|
58 |
+
# detect_btn.click(fn=detect_theft, inputs=[cam, lat, lon], outputs=[alert, captured, map_html])
|
59 |
+
|
60 |
+
# demo.launch()
|
61 |
+
|
62 |
import gradio as gr
|
63 |
import datetime
|
64 |
|
65 |
+
def show_thief_location(image, lat, lon):
|
66 |
+
time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
67 |
+
alert = f"π¨ Theft detected at {time}!"
|
68 |
+
map_embed = f"""
|
69 |
+
<div style="display: flex; gap: 20px;">
|
70 |
+
<iframe width="400" height="300" style="border-radius:12px" src="https://maps.google.com/maps?q={lat},{lon}&z=15&output=embed"></iframe>
|
71 |
+
<div>
|
72 |
+
<p><b>Thief Image:</b></p>
|
73 |
+
<img src="data:image/png;base64,{image}" width="200" style="border:2px solid red; border-radius:12px"/>
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
"""
|
77 |
+
return alert, map_embed
|
78 |
|
79 |
with gr.Blocks() as demo:
|
80 |
+
gr.Markdown("## π¨ Theft Image Upload with Live Map Display")
|
81 |
|
82 |
with gr.Row():
|
83 |
+
img_input = gr.Image(type="filepath", label="Upload Thief Image")
|
84 |
with gr.Column():
|
85 |
lat = gr.Number(label="Latitude", value=24.8607)
|
86 |
lon = gr.Number(label="Longitude", value=67.0011)
|
87 |
+
btn = gr.Button("π Show Image on Map")
|
88 |
|
89 |
+
alert_box = gr.Textbox(label="Alert")
|
90 |
+
map_out = gr.HTML(label="Map with Image")
|
|
|
91 |
|
92 |
+
def generate_base64_map(image_path, lat, lon):
|
93 |
+
import base64
|
94 |
+
with open(image_path, "rb") as img_file:
|
95 |
+
encoded = base64.b64encode(img_file.read()).decode("utf-8")
|
96 |
+
return show_thief_location(encoded, lat, lon)
|
97 |
+
|
98 |
+
btn.click(fn=generate_base64_map, inputs=[img_input, lat, lon], outputs=[alert_box, map_out])
|
99 |
|
100 |
demo.launch()
|
101 |
+
|