Spaces:
Runtime error
Runtime error
File size: 1,612 Bytes
21ffffb |
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 |
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"""
<iframe
width="600"
height="450"
style="border:0"
loading="lazy"
allowfullscreen
src="https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q={location_text}">
</iframe>
"""
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()
# <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d11988.613116381091!2d69.19850824650604!3d41.3055290002301!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x38ae8bc5b351bc23%3A0x707af898bf0cdb4d!2sEsenin%20St%2018%2C%20Tashkent%2C%20Uzbekistan!5e0!3m2!1sen!2s!4v1740469397909!5m2!1sen!2s" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe> |