Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
|
|
7 |
places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
|
8 |
|
9 |
# Your actual Google API Key (replace with your key)
|
10 |
-
api_key = "GOOGLE_API_KEY"
|
11 |
|
12 |
def get_places_data(query, location, radius, next_page_token=None):
|
13 |
params = {
|
@@ -43,13 +43,13 @@ def get_all_places(query, location, radius):
|
|
43 |
while True:
|
44 |
data = get_places_data(query, location, radius, next_page_token)
|
45 |
if "error" in data:
|
46 |
-
return [data]
|
47 |
results = data.get('results', [])
|
48 |
for place in results:
|
49 |
place_id = place.get("place_id")
|
50 |
details = get_place_details(place_id)
|
51 |
if "error" in details:
|
52 |
-
return [details]
|
53 |
all_results.append({**place, **details})
|
54 |
|
55 |
next_page_token = data.get('next_page_token')
|
@@ -59,10 +59,13 @@ def get_all_places(query, location, radius):
|
|
59 |
|
60 |
def display_data(query, location, radius):
|
61 |
results = get_all_places(query, location, radius)
|
62 |
-
if isinstance(results
|
63 |
-
|
|
|
|
|
|
|
64 |
else:
|
65 |
-
return pd.DataFrame(results
|
66 |
|
67 |
iface = gr.Interface(
|
68 |
fn=display_data,
|
@@ -76,4 +79,4 @@ iface = gr.Interface(
|
|
76 |
description="Find wellness professionals in Hawaii using the Google Places API."
|
77 |
)
|
78 |
|
79 |
-
iface.launch(share=True)
|
|
|
7 |
places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
|
8 |
|
9 |
# Your actual Google API Key (replace with your key)
|
10 |
+
api_key = "GOOGLE_API_KEY"
|
11 |
|
12 |
def get_places_data(query, location, radius, next_page_token=None):
|
13 |
params = {
|
|
|
43 |
while True:
|
44 |
data = get_places_data(query, location, radius, next_page_token)
|
45 |
if "error" in data:
|
46 |
+
return [data] # Return error message
|
47 |
results = data.get('results', [])
|
48 |
for place in results:
|
49 |
place_id = place.get("place_id")
|
50 |
details = get_place_details(place_id)
|
51 |
if "error" in details:
|
52 |
+
return [details] # Return error message
|
53 |
all_results.append({**place, **details})
|
54 |
|
55 |
next_page_token = data.get('next_page_token')
|
|
|
59 |
|
60 |
def display_data(query, location, radius):
|
61 |
results = get_all_places(query, location, radius)
|
62 |
+
if isinstance(results, list):
|
63 |
+
if results and isinstance(results[0], dict):
|
64 |
+
return pd.DataFrame(results)
|
65 |
+
else:
|
66 |
+
return pd.DataFrame() # Return an empty DataFrame if results is empty or not a list of dicts
|
67 |
else:
|
68 |
+
return pd.DataFrame() # Return an empty DataFrame if results is not a list
|
69 |
|
70 |
iface = gr.Interface(
|
71 |
fn=display_data,
|
|
|
79 |
description="Find wellness professionals in Hawaii using the Google Places API."
|
80 |
)
|
81 |
|
82 |
+
iface.launch(share=True)
|