Spaces:
Sleeping
Sleeping
| # 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() | |