antfraia's picture
Update app.py
a6bc7dc
raw
history blame
1.49 kB
import streamlit as st
from serpapi import GoogleSearch
def fetch_google_maps_reviews(query=None, location=None):
if not query and not location:
raise ValueError("Either 'query' or 'location' must be provided.")
params = {
"api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
"engine": "google_maps_reviews",
"google_domain": "google.it",
"hl": "it",
"gl": "it"
results = search.get_dict()
return results
st.title("Google Maps Reviews via SerpAPI")
st.write("Enter a search query or a geographic location to fetch reviews from Google Maps.")
# Input fields
query = st.text_input("Search Query (q): (Use for fetching reviews)")
location = st.text_input("Geographic Location (ll): (Format: '@latitude,longitude,zoom')")
# Button to trigger the API call
if st.button("Fetch Reviews"):
if not query and not location:
st.error("Please enter either a search query or a geographic location.")
else:
try:
results = fetch_google_maps_reviews(query=query, location=location)
# Extract reviews from the results
reviews = results.get("reviews", [])
if reviews:
for review in reviews:
st.write(f"{review['author']} said: {review['text']}")
else:
st.write("No reviews found.")
except Exception as e:
st.error(f"Couldn't fetch the reviews. Error: {e}")