Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1007,14 +1007,14 @@ def fetch_yelp_restaurants():
|
|
1007 |
results = search.get_dict()
|
1008 |
organic_results = results.get("organic_results", [])
|
1009 |
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
)
|
1015 |
-
yelp_text += "-"*120 + "\n"
|
1016 |
|
1017 |
-
|
|
|
|
|
1018 |
name = result.get("title", "No name")
|
1019 |
rating = result.get("rating", "No rating")
|
1020 |
reviews = result.get("reviews", "No reviews")
|
@@ -1022,16 +1022,18 @@ def fetch_yelp_restaurants():
|
|
1022 |
snippet = result.get("snippet", "Not Available")
|
1023 |
services = result.get("service_options", "Not Known")
|
1024 |
|
1025 |
-
if isinstance(
|
1026 |
-
|
1027 |
-
elif isinstance(services, dict):
|
1028 |
-
services = ", ".join([f"{key}: {value}" for key, value in services.items()])
|
1029 |
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
|
|
|
|
|
|
|
|
|
|
1033 |
|
1034 |
-
return yelp_text
|
1035 |
|
1036 |
|
1037 |
|
|
|
1007 |
results = search.get_dict()
|
1008 |
organic_results = results.get("organic_results", [])
|
1009 |
|
1010 |
+
def star_rating(rating):
|
1011 |
+
full_stars = int(float(rating))
|
1012 |
+
half_star = 1 if float(rating) - full_stars >= 0.5 else 0
|
1013 |
+
return "★" * full_stars + "☆" * (5 - full_stars - half_star)
|
|
|
|
|
1014 |
|
1015 |
+
response_text = ""
|
1016 |
+
|
1017 |
+
for result in organic_results[:5]: # Limiting to top 5 restaurants
|
1018 |
name = result.get("title", "No name")
|
1019 |
rating = result.get("rating", "No rating")
|
1020 |
reviews = result.get("reviews", "No reviews")
|
|
|
1022 |
snippet = result.get("snippet", "Not Available")
|
1023 |
services = result.get("service_options", "Not Known")
|
1024 |
|
1025 |
+
if isinstance(snippet, list):
|
1026 |
+
snippet = " | ".join(snippet[:5]) # Limiting to top 5 snippets
|
|
|
|
|
1027 |
|
1028 |
+
# Format the output for each restaurant
|
1029 |
+
response_text += f"***{name}***\n" # Name in bold and italic
|
1030 |
+
response_text += f"**Contact No:** {phone}\n"
|
1031 |
+
response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
|
1032 |
+
response_text += f"**Snippet:** {snippet}\n"
|
1033 |
+
response_text += "-" * 50 + "\n"
|
1034 |
+
|
1035 |
+
return response_text
|
1036 |
|
|
|
1037 |
|
1038 |
|
1039 |
|