File size: 3,775 Bytes
f69d799
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5af1c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d239b7e
 
 
f5af1c5
 
 
 
 
 
 
 
 
 
 
 
 
d239b7e
 
f5af1c5
46032a9
d239b7e
f5af1c5
d239b7e
46032a9
 
f5af1c5
d239b7e
f5af1c5
 
d239b7e
f5af1c5
 
 
 
 
 
 
d239b7e
 
f5af1c5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# import gradio as gr
# import datetime
# import random

# def detect_theft(frame, lat, lon):
#     # Simulate detection
#     is_theft = random.choice([True, False])
#     time_detected = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

#     if is_theft:
#         alert = f"🚨 Theft detected at {time_detected}!"
#         map_embed = f"""<iframe width="100%" height="300" src="https://maps.google.com/maps?q={lat},{lon}&z=15&output=embed"></iframe>"""
#         return alert, frame, map_embed
#     else:
#         return "βœ… No theft detected", None, None

# with gr.Blocks() as demo:
#     gr.Markdown("## 🚨 Theft Detection & Live Location Surveillance AI")

#     with gr.Row():
#         cam = gr.Image(label="Upload CCTV Frame / Snapshot", type="pil")
#         with gr.Column():
#             lat = gr.Number(label="Latitude", value=24.8607)
#             lon = gr.Number(label="Longitude", value=67.0011)
#             detect_btn = gr.Button("Detect Theft")

#     alert = gr.Textbox(label="Alert")
#     captured = gr.Image(label="Thief Frame")
#     map_html = gr.HTML(label="Live Location Map")

#     detect_btn.click(fn=detect_theft, inputs=[cam, lat, lon], outputs=[alert, captured, map_html])

# demo.launch()

# import gradio as gr
# import datetime

# def detect_theft(frame, lat, lon):
#     time_detected = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#     alert = f"🚨 Theft detected at {time_detected}!"
#     map_embed = f"""<iframe width="100%" height="300" src="https://maps.google.com/maps?q={lat},{lon}&z=15&output=embed"></iframe>"""
#     return alert, frame, map_embed

# with gr.Blocks() as demo:
#     gr.Markdown("## 🚨 Theft Detection & Live Location Surveillance AI")

#     with gr.Row():
#         cam = gr.Image(label="Upload Thief Image", type="pil")
#         with gr.Column():
#             lat = gr.Number(label="Latitude", value=24.8607)
#             lon = gr.Number(label="Longitude", value=67.0011)
#             detect_btn = gr.Button("πŸ“ Show Location on Map")

#     alert = gr.Textbox(label="Alert")
#     captured = gr.Image(label="Thief Image")
#     map_html = gr.HTML(label="Live Location Map")

#     detect_btn.click(fn=detect_theft, inputs=[cam, lat, lon], outputs=[alert, captured, map_html])

# demo.launch()

import gradio as gr
import datetime

def show_thief_location(image, lat, lon):
    time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    alert = f"🚨 Theft detected at {time}!"
    map_embed = f"""
    <div style="display: flex; gap: 20px;">
        <iframe width="400" height="300" style="border-radius:12px" src="https://maps.google.com/maps?q={lat},{lon}&z=15&output=embed"></iframe>
        <div>
            <p><b>Thief Image:</b></p>
            <img src="data:image/png;base64,{image}" width="200" style="border:2px solid red; border-radius:12px"/>
        </div>
    </div>
    """
    return alert, map_embed

with gr.Blocks() as demo:
    gr.Markdown("## 🚨 Theft Image Upload with Live Map Display")

    with gr.Row():
        img_input = gr.Image(type="filepath", label="Upload Thief Image")
        with gr.Column():
            lat = gr.Number(label="Latitude", value=24.8607)
            lon = gr.Number(label="Longitude", value=67.0011)
            btn = gr.Button("πŸ“ Show Image on Map")

    alert_box = gr.Textbox(label="Alert")
    map_out = gr.HTML(label="Map with Image")

    def generate_base64_map(image_path, lat, lon):
        import base64
        with open(image_path, "rb") as img_file:
            encoded = base64.b64encode(img_file.read()).decode("utf-8")
        return show_thief_location(encoded, lat, lon)

    btn.click(fn=generate_base64_map, inputs=[img_input, lat, lon], outputs=[alert_box, map_out])

demo.launch()