antfraia commited on
Commit
5662517
·
1 Parent(s): 959a504

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -6,7 +6,7 @@ def fetch_google_maps_results(query=None, location=None, search_type="search"):
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",
@@ -23,13 +23,25 @@ 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
@@ -39,7 +51,6 @@ if st.button("Search"):
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}")
 
6
  raise ValueError("Either 'query' or 'location' must be provided.")
7
 
8
  params = {
9
+ "api_key": "YOUR_API_KEY",
10
  "engine": "google_maps",
11
  "type": search_type,
12
  "google_domain": "google.it",
 
23
  results = search.get_dict()
24
  return results
25
 
26
+ def display_reviews(results):
27
+ # Extract customer reviews
28
+ reviews = results.get('reviews', [])
29
+
30
+ if reviews:
31
+ for review in reviews:
32
+ st.write("Reviewer:", review.get('author'))
33
+ st.write("Rating:", review.get('rating'))
34
+ st.write("Review:", review.get('text'))
35
+ st.write('---') # Line separator for better readability
36
+ else:
37
+ st.write("No reviews found.")
38
+
39
  st.title("Google Maps API Search via SerpAPI")
40
  st.write("Enter a search query or a geographic location to fetch results from Google Maps.")
41
 
42
  # Input fields
43
  search_type = st.selectbox("Select Search Type:", ["search", "place"])
44
  query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
 
45
  location = st.text_input("Geographic Location (ll): (Format: '@latitude,longitude,zoom')")
46
 
47
  # Button to trigger the API call
 
51
  else:
52
  try:
53
  results = fetch_google_maps_results(query=query, location=location, search_type=search_type)
54
+ display_reviews(results)
 
55
  except Exception as e:
56
  st.error(f"Couldn't fetch the results. Error: {e}")