Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
from serpapi import GoogleSearch
|
3 |
|
4 |
-
def fetch_google_maps_results(query=None,
|
5 |
-
if not query
|
6 |
-
raise ValueError("
|
7 |
|
8 |
params = {
|
9 |
"api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
|
@@ -11,35 +11,27 @@ def fetch_google_maps_results(query=None, location=None, search_type="search"):
|
|
11 |
"type": search_type,
|
12 |
"google_domain": "google.it",
|
13 |
"hl": "it",
|
14 |
-
"gl": "it"
|
|
|
15 |
}
|
16 |
|
17 |
-
if query:
|
18 |
-
params["q"] = query
|
19 |
-
if location:
|
20 |
-
params["ll"] = location
|
21 |
-
|
22 |
search = GoogleSearch(params)
|
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
|
28 |
|
29 |
-
# Input
|
30 |
-
search_type = st.selectbox("Select Search Type:", ["place"])
|
31 |
query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
|
32 |
|
33 |
-
# Since we removed the search option for ll, we can use a simple text input for the geographic location.
|
34 |
-
location = st.text_input("Geographic Location (ll): (Format: 'latitude,longitude,zoom')")
|
35 |
-
|
36 |
# Button to trigger the API call
|
37 |
if st.button("Search"):
|
38 |
-
if not query
|
39 |
-
st.error("Please enter
|
40 |
else:
|
41 |
try:
|
42 |
-
results = fetch_google_maps_results(query=query
|
43 |
st.write(results) # Display the 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_results(query=None, search_type="search"):
|
5 |
+
if not query:
|
6 |
+
raise ValueError("The 'query' must be provided.")
|
7 |
|
8 |
params = {
|
9 |
"api_key": "b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a",
|
|
|
11 |
"type": search_type,
|
12 |
"google_domain": "google.it",
|
13 |
"hl": "it",
|
14 |
+
"gl": "it",
|
15 |
+
"q": query
|
16 |
}
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
search = GoogleSearch(params)
|
19 |
results = search.get_dict()
|
20 |
return results
|
21 |
|
22 |
st.title("Google Maps API Search via SerpAPI")
|
23 |
+
st.write("Enter a search query to fetch results from Google Maps.")
|
24 |
|
25 |
+
# Input field
|
|
|
26 |
query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
|
27 |
|
|
|
|
|
|
|
28 |
# Button to trigger the API call
|
29 |
if st.button("Search"):
|
30 |
+
if not query:
|
31 |
+
st.error("Please enter a search query.")
|
32 |
else:
|
33 |
try:
|
34 |
+
results = fetch_google_maps_results(query=query)
|
35 |
st.write(results) # Display the results
|
36 |
except Exception as e:
|
37 |
st.error(f"Couldn't fetch the results. Error: {e}")
|