import gradio as gr
import re
def embed_google_map(map_url):
"""
Extracts a textual location from the Google Maps URL and returns
an embedded Google Map iframe.
"""
# Simple approach: try to extract "San+Francisco,+CA" from the URL
# by capturing what's after '/maps/place/'
match = re.search(r'/maps/place/([^/]+)', map_url)
if not match:
return "Invalid Google Maps URL. Could not extract location."
location_text = match.group(1)
# location_text might contain extra parameters, so let's just
# strip everything after the first '?' or '/':
location_text = re.split(r'[/?]', location_text)[0]
embed_html = f"""
"""
return embed_html
with gr.Blocks() as demo:
map_url_input = gr.Textbox(label="Enter Google Maps URL")
map_output = gr.HTML(label="Embedded Google Map")
map_url_input.change(embed_google_map, inputs=map_url_input, outputs=map_output)
demo.launch()
#