antfraia commited on
Commit
0563ad7
·
1 Parent(s): 97e5dbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -1,14 +1,13 @@
1
  import streamlit as st
2
  from serpapi import GoogleSearch
3
 
4
- def fetch_google_maps_results(query=None, location=None, search_type="search"):
5
  if not query and not location:
6
  raise ValueError("Either 'query' or 'location' must be provided.")
7
 
8
  params = {
9
  "api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
10
- "engine": "google_maps",
11
- "type": search_type,
12
  "google_domain": "google.it",
13
  "hl": "it",
14
  "gl": "it"
@@ -23,23 +22,27 @@ def fetch_google_maps_results(query=None, location=None, search_type="search"):
23
  results = search.get_dict()
24
  return results
25
 
26
- st.title("Google Maps API Search via SerpAPI")
27
- st.write("Enter a search query or a geographic location to fetch results from Google Maps.")
28
 
29
  # Input fields
30
- search_type = st.selectbox("Select Search Type:", ["search", "place"])
31
- query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
32
 
33
  location = st.text_input("Geographic Location (ll): (Format: '@latitude,longitude,zoom')")
34
 
35
  # Button to trigger the API call
36
- if st.button("Search"):
37
  if not query and not location:
38
  st.error("Please enter either a search query or a geographic location.")
39
  else:
40
  try:
41
- results = fetch_google_maps_results(query=query, location=location, search_type=search_type)
42
- # Display the results (you might want to format or filter this)
43
- st.write(results)
 
 
 
 
 
44
  except Exception as e:
45
- st.error(f"Couldn't fetch the results. Error: {e}")
 
1
  import streamlit as st
2
  from serpapi import GoogleSearch
3
 
4
+ def fetch_google_maps_reviews(query=None, location=None):
5
  if not query and not location:
6
  raise ValueError("Either 'query' or 'location' must be provided.")
7
 
8
  params = {
9
  "api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
10
+ "engine": "google_maps_reviews",
 
11
  "google_domain": "google.it",
12
  "hl": "it",
13
  "gl": "it"
 
22
  results = search.get_dict()
23
  return results
24
 
25
+ st.title("Google Maps Reviews via SerpAPI")
26
+ st.write("Enter a search query or a geographic location to fetch reviews from Google Maps.")
27
 
28
  # Input fields
29
+ query = st.text_input("Search Query (q): (Use for fetching reviews)")
 
30
 
31
  location = st.text_input("Geographic Location (ll): (Format: '@latitude,longitude,zoom')")
32
 
33
  # Button to trigger the API call
34
+ if st.button("Fetch Reviews"):
35
  if not query and not location:
36
  st.error("Please enter either a search query or a geographic location.")
37
  else:
38
  try:
39
+ results = fetch_google_maps_reviews(query=query, location=location)
40
+ # Extract reviews from the results
41
+ reviews = results.get("reviews", [])
42
+ if reviews:
43
+ for review in reviews:
44
+ st.write(f"{review['author']} said: {review['text']}")
45
+ else:
46
+ st.write("No reviews found.")
47
  except Exception as e:
48
+ st.error(f"Couldn't fetch the reviews. Error: {e}")