antfraia's picture
Update app.py
ff80b22
import streamlit as st
from serpapi import GoogleSearch
def fetch_google_maps_results(query=None, search_type="search"):
if not query:
raise ValueError("The 'query' must be provided.")
params = {
"api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
"type": search_type,
"google_domain": "google.it",
"hl": "it",
"gl": "it",
"q": query
}
search = GoogleSearch(params)
results = search.get_dict()
return results
st.title("Google Maps API Search via SerpAPI")
st.write("Enter a search query to fetch results from Google Maps.")
# Input field
query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
# Button to trigger the API call
if st.button("Search"):
if not query:
st.error("Please enter a search query.")
else:
try:
results = fetch_google_maps_results(query=query)
st.write(results) # Display the results
except Exception as e:
st.error(f"Couldn't fetch the results. Error: {e}")