Bagoodex-Web-Search / test_app.py
abdibrokhim's picture
tons of changes
21ffffb
raw
history blame
1.61 kB
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>