Download app.py from Muhanuri/Location: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/Muhanuri/Location/resolve/main/app.py
- Command line
-
hf download hf://spaces/Muhanuri/Location/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Muhanuri/Location/resolve/main/app.py
1.29 kB
| import requests | |
| import folium | |
| import gradio as gr | |
| # Google SERP API ν€ μ€μ | |
| api_key = "e312d83a4f8dc1ea07419ea7d234d3aacd0abe11f781504d554f06c2ac1db0ab" | |
| def search_and_display_map(query): | |
| # Google SERP API URL κ΅¬μ± | |
| url = f"https://serpapi.com/search.json?q={query}&hl=en&gl=us&google_domain=google.com&api_key={api_key}" | |
| # API μμ² | |
| response = requests.get(url) | |
| # μλ΅ νμΈ λ° μ§λ μμ± | |
| if response.status_code == 200: | |
| data = response.json() | |
| # μμλ‘ μμΈμ μλμ κ²½λλ₯Ό μ¬μ©ν©λλ€. μ€μ μλ΅μμ μμΉ μ 보λ₯Ό μΆμΆνμ¬ μ¬μ©ν΄μΌ ν©λλ€. | |
| latitude = 37.5665 | |
| longitude = 126.9780 | |
| # Foliumμ μ¬μ©νμ¬ μ§λ μμ± | |
| map = folium.Map(location=[latitude, longitude], zoom_start=13) | |
| # μ§λμ λ§μ»€ μΆκ° | |
| folium.Marker([latitude, longitude], popup=query).add_to(map) | |
| # μ§λλ₯Ό HTML λ¬Έμμ΄λ‘ λ³ν | |
| map_html = map._repr_html_() | |
| return map_html | |
| else: | |
| return "Error: API μμ²μ μ€ν¨νμ΅λλ€." | |
| # Gradio μΈν°νμ΄μ€ μ μ | |
| iface = gr.Interface(fn=search_and_display_map, inputs=gr.Text(label="κ²μν μ₯μλ₯Ό μ λ ₯νμΈμ"), outputs="html") | |
| # μΈν°νμ΄μ€ μ€ν | |
| iface.launch() |