Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -312,6 +312,11 @@ def generate_answer(message, choice, retrieval_mode):
|
|
312 |
response = fetch_yelp_restaurants()
|
313 |
return response, extract_addresses(response)
|
314 |
|
|
|
|
|
|
|
|
|
|
|
315 |
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
316 |
|
317 |
if retrieval_mode == "VDB":
|
@@ -332,6 +337,7 @@ def generate_answer(message, choice, retrieval_mode):
|
|
332 |
return "Invalid retrieval mode selected.", []
|
333 |
|
334 |
|
|
|
335 |
def bot(history, choice, tts_choice, retrieval_mode):
|
336 |
if not history:
|
337 |
return history
|
@@ -911,87 +917,7 @@ def handle_retrieval_mode_change(choice):
|
|
911 |
return gr.update(interactive=True), gr.update(interactive=True)
|
912 |
|
913 |
|
914 |
-
|
915 |
-
# from serpapi.google_search import GoogleSearch
|
916 |
-
# import os
|
917 |
-
|
918 |
-
# params = {
|
919 |
-
# "engine": "yelp",
|
920 |
-
# "find_desc": "Restaurant",
|
921 |
-
# "find_loc": "Birmingham, AL, USA",
|
922 |
-
# "api_key": os.getenv("SERP_API")
|
923 |
-
# }
|
924 |
-
|
925 |
-
# search = GoogleSearch(params)
|
926 |
-
# results = search.get_dict()
|
927 |
-
# organic_results = results.get("organic_results", [])
|
928 |
-
|
929 |
-
# yelp_html = """
|
930 |
-
# <h2 style="font-family: 'Georgia', serif; color: #ff0000; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Top Restaurants</h2>
|
931 |
-
# <style>
|
932 |
-
# table {
|
933 |
-
# font-family: 'Verdana', sans-serif;
|
934 |
-
# color: #333;
|
935 |
-
# border-collapse: collapse;
|
936 |
-
# width: 100%;
|
937 |
-
# }
|
938 |
-
# th, td {
|
939 |
-
# border: 1px solid #fff !important;
|
940 |
-
# padding: 8px;
|
941 |
-
# }
|
942 |
-
# th {
|
943 |
-
# background-color: #f2f2f2;
|
944 |
-
# color: #333;
|
945 |
-
# text-align: left;
|
946 |
-
# }
|
947 |
-
# tr:hover {
|
948 |
-
# background-color: #f5f5f5;
|
949 |
-
# }
|
950 |
-
# .restaurant-link {
|
951 |
-
# color: #1E90FF;
|
952 |
-
# text-decoration: none;
|
953 |
-
# }
|
954 |
-
# .restaurant-link:hover {
|
955 |
-
# text-decoration: underline;
|
956 |
-
# }
|
957 |
-
# </style>
|
958 |
-
# <table>
|
959 |
-
# <tr>
|
960 |
-
# <th>Name</th>
|
961 |
-
# <th>Rating</th>
|
962 |
-
# <th>Reviews</th>
|
963 |
-
# <th>Phone</th>
|
964 |
-
# <th>Snippet</th>
|
965 |
-
# <th>Services</th>
|
966 |
-
# </tr>
|
967 |
-
# """
|
968 |
-
# for result in organic_results:
|
969 |
-
# name = result.get("title", "No name")
|
970 |
-
# rating = result.get("rating", "No rating")
|
971 |
-
# reviews = result.get("reviews", "No reviews")
|
972 |
-
# phone = result.get("phone", "Not Available")
|
973 |
-
# snippet = result.get("snippet", "No Available")
|
974 |
-
# services = result.get("service_options", "Not Known")
|
975 |
-
|
976 |
-
# if isinstance(services, list):
|
977 |
-
# services = ", ".join(services)
|
978 |
-
# elif isinstance(services, dict):
|
979 |
-
# services = ", ".join([f"{key}: {value}" for key, value in services.items()])
|
980 |
-
|
981 |
-
# link = result.get("link", "#")
|
982 |
-
|
983 |
-
# yelp_html += f"""
|
984 |
-
# <tr>
|
985 |
-
# <td><a class='restaurant-link' href='{link}' target='_blank'>{name}</a></td>
|
986 |
-
# <td>{rating}</td>
|
987 |
-
# <td>{reviews}</td>
|
988 |
-
# <td>{phone}</td>
|
989 |
-
# <td>{snippet}</td>
|
990 |
-
# <td>{services}</td>
|
991 |
-
# </tr>
|
992 |
-
# """
|
993 |
-
# yelp_html += "</table>"
|
994 |
-
# return yelp_html
|
995 |
def fetch_yelp_restaurants():
|
996 |
from serpapi.google_search import GoogleSearch
|
997 |
import os
|
@@ -1016,7 +942,7 @@ def fetch_yelp_restaurants():
|
|
1016 |
|
1017 |
response_text = ""
|
1018 |
|
1019 |
-
for result in organic_results[:
|
1020 |
name = result.get("title", "No name")
|
1021 |
rating = result.get("rating", "No rating")
|
1022 |
reviews = result.get("reviews", "No reviews")
|
@@ -1039,6 +965,66 @@ def fetch_yelp_restaurants():
|
|
1039 |
return response_text
|
1040 |
|
1041 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1042 |
|
1043 |
|
1044 |
|
|
|
312 |
response = fetch_yelp_restaurants()
|
313 |
return response, extract_addresses(response)
|
314 |
|
315 |
+
# Check if the question is about hotels
|
316 |
+
elif "hotels" in message.lower() and "birmingham" in message.lower():
|
317 |
+
response = fetch_hotels_birmingham()
|
318 |
+
return response, extract_addresses(response)
|
319 |
+
|
320 |
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
321 |
|
322 |
if retrieval_mode == "VDB":
|
|
|
337 |
return "Invalid retrieval mode selected.", []
|
338 |
|
339 |
|
340 |
+
|
341 |
def bot(history, choice, tts_choice, retrieval_mode):
|
342 |
if not history:
|
343 |
return history
|
|
|
917 |
return gr.update(interactive=True), gr.update(interactive=True)
|
918 |
|
919 |
|
920 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
921 |
def fetch_yelp_restaurants():
|
922 |
from serpapi.google_search import GoogleSearch
|
923 |
import os
|
|
|
942 |
|
943 |
response_text = ""
|
944 |
|
945 |
+
for result in organic_results[:5]: # Limiting to top 10 restaurants
|
946 |
name = result.get("title", "No name")
|
947 |
rating = result.get("rating", "No rating")
|
948 |
reviews = result.get("reviews", "No reviews")
|
|
|
965 |
return response_text
|
966 |
|
967 |
|
968 |
+
from serpapi import GoogleSearch
|
969 |
+
from datetime import datetime, timedelta
|
970 |
+
|
971 |
+
def fetch_hotels_birmingham():
|
972 |
+
current_date = datetime.now().strftime("%Y-%m-%d")
|
973 |
+
|
974 |
+
params = {
|
975 |
+
"engine": "google_hotels",
|
976 |
+
"q": "Birmingham,AL",
|
977 |
+
"check_in_date": current_date,
|
978 |
+
"check_out_date": (datetime.now() + timedelta(days=2)).strftime("%Y-%m-%d"),
|
979 |
+
"vacation_rentals": "true",
|
980 |
+
"amenities": "2,4,10,15,16,20,21,24,29,32",
|
981 |
+
"rating": "7,8,9",
|
982 |
+
"hotel_class": "2,3,4,5",
|
983 |
+
"currency": "USD",
|
984 |
+
"gl": "us",
|
985 |
+
"hl": "en",
|
986 |
+
"api_key": "74972e6cc9f9e092bd86764a78f7d18c1d71b156eca8b1fe7fd65c2406cfb588"
|
987 |
+
}
|
988 |
+
|
989 |
+
search = GoogleSearch(params)
|
990 |
+
results = search.get_dict()
|
991 |
+
hotels = results.get("hotels_results", [])
|
992 |
+
|
993 |
+
def star_rating(rating):
|
994 |
+
full_stars = int(float(rating))
|
995 |
+
half_star = 1 if (float(rating) - full_stars) >= 0.5 else 0
|
996 |
+
empty_stars = 5 - full_stars - half_star
|
997 |
+
stars = "★" * full_stars + "½" * half_star + "☆" * empty_stars
|
998 |
+
return stars
|
999 |
+
|
1000 |
+
response_text = ""
|
1001 |
+
|
1002 |
+
for hotel in hotels[:5]: # Limiting to top 10 hotels
|
1003 |
+
name = hotel.get("title", "No name")
|
1004 |
+
rating = hotel.get("rating", "No rating")
|
1005 |
+
reviews = hotel.get("reviews", "No reviews")
|
1006 |
+
location = f"{name}, Birmingham, AL"
|
1007 |
+
price = hotel.get("price", "Price not available")
|
1008 |
+
link = hotel.get("link", "#")
|
1009 |
+
hotel_class = hotel.get("hotel_class", "Not available")
|
1010 |
+
amenities = hotel.get("amenities", "Amenities not available")
|
1011 |
+
|
1012 |
+
if isinstance(amenities, list):
|
1013 |
+
amenities = ", ".join(amenities)
|
1014 |
+
|
1015 |
+
# Format the output for each hotel
|
1016 |
+
response_text += f"[{name}]({link})\n" # Name with clickable link, no bold
|
1017 |
+
response_text += f"*{location}*\n" # Location with hotel name and "Birmingham, AL"
|
1018 |
+
response_text += f"**Price:** {price}\n"
|
1019 |
+
response_text += f"**Hotel Class:** {hotel_class} stars\n"
|
1020 |
+
response_text += f"**Amenities:** {amenities}\n"
|
1021 |
+
response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
|
1022 |
+
response_text += "-" * 50 + "\n"
|
1023 |
+
|
1024 |
+
return response_text
|
1025 |
+
|
1026 |
+
|
1027 |
+
|
1028 |
|
1029 |
|
1030 |
|