Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -307,16 +307,16 @@ chain_neo4j = (
|
|
307 |
def generate_answer(message, choice, retrieval_mode):
|
308 |
logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
309 |
|
|
|
|
|
|
|
|
|
|
|
310 |
# Check if the question is about restaurants
|
311 |
if "restaurant" in message.lower() and "birmingham" in message.lower():
|
312 |
response = fetch_yelp_restaurants()
|
313 |
return response, extract_addresses(response)
|
314 |
|
315 |
-
# Check if the question is about hotels
|
316 |
-
if "hotel" in message.lower() and "birmingham" in message.lower():
|
317 |
-
response = fetch_hotels_in_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":
|
@@ -341,6 +341,7 @@ def generate_answer(message, choice, retrieval_mode):
|
|
341 |
|
342 |
|
343 |
|
|
|
344 |
def bot(history, choice, tts_choice, retrieval_mode):
|
345 |
if not history:
|
346 |
return history
|
@@ -967,60 +968,38 @@ def fetch_yelp_restaurants():
|
|
967 |
|
968 |
return response_text
|
969 |
|
970 |
-
def
|
971 |
params = {
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
}
|
982 |
-
|
983 |
search = GoogleSearch(params)
|
984 |
results = search.get_dict()
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
<table style="width:100%; border-collapse: collapse; font-family: Arial, sans-serif;">
|
990 |
-
<tr style="background-color: #f2f2f2;">
|
991 |
-
<th style="padding: 8px; border: 1px solid #ddd;">Name</th>
|
992 |
-
<th style="padding: 8px; border: 1px solid #ddd;">Location</th>
|
993 |
-
<th style="padding: 8px; border: 1px solid #ddd;">Rating</th>
|
994 |
-
<th style="padding: 8px; border: 1px solid #ddd;">Reviews</th>
|
995 |
-
<th style="padding: 8px; border: 1px solid #ddd;">Price</th>
|
996 |
-
<th style="padding: 8px; border: 1px solid #ddd;">Link</th>
|
997 |
-
</tr>
|
998 |
-
"""
|
999 |
-
|
1000 |
-
for hotel in hotels:
|
1001 |
name = hotel.get("title", "No name")
|
|
|
1002 |
rating = hotel.get("rating", "No rating")
|
1003 |
-
reviews = hotel.get("reviews", "No reviews")
|
1004 |
price = hotel.get("price", "No price")
|
1005 |
link = hotel.get("link", "#")
|
1006 |
-
location = f"{name}, Birmingham, AL"
|
1007 |
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
<td style="padding: 8px; border: 1px solid #ddd;">{rating}</td>
|
1014 |
-
<td style="padding: 8px; border: 1px solid #ddd;">{reviews}</td>
|
1015 |
-
<td style="padding: 8px; border: 1px solid #ddd;">{price}</td>
|
1016 |
-
<td style="padding: 8px; border: 1px solid #ddd;"><a href="{link}" target="_blank">View</a></td>
|
1017 |
-
</tr>
|
1018 |
-
"""
|
1019 |
-
|
1020 |
-
table_html += "</table>"
|
1021 |
-
|
1022 |
-
return table_html
|
1023 |
|
|
|
1024 |
|
1025 |
|
1026 |
|
@@ -1090,7 +1069,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
1090 |
events_output = gr.HTML(value=fetch_local_events())
|
1091 |
# restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
|
1092 |
|
1093 |
-
|
1094 |
|
1095 |
|
1096 |
with gr.Column():
|
|
|
307 |
def generate_answer(message, choice, retrieval_mode):
|
308 |
logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
309 |
|
310 |
+
# Check if the question is about hotels
|
311 |
+
if "hotel" in message.lower() and "birmingham" in message.lower():
|
312 |
+
response = fetch_google_hotels()
|
313 |
+
return response, extract_addresses(response)
|
314 |
+
|
315 |
# Check if the question is about restaurants
|
316 |
if "restaurant" in message.lower() and "birmingham" in message.lower():
|
317 |
response = fetch_yelp_restaurants()
|
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":
|
|
|
341 |
|
342 |
|
343 |
|
344 |
+
|
345 |
def bot(history, choice, tts_choice, retrieval_mode):
|
346 |
if not history:
|
347 |
return history
|
|
|
968 |
|
969 |
return response_text
|
970 |
|
971 |
+
def fetch_google_hotels(query="Birmingham hotels", check_in="2024-08-14", check_out="2024-08-15", adults=2):
|
972 |
params = {
|
973 |
+
"engine": "google_hotels",
|
974 |
+
"q": query,
|
975 |
+
"check_in_date": check_in,
|
976 |
+
"check_out_date": check_out,
|
977 |
+
"adults": str(adults),
|
978 |
+
"currency": "USD",
|
979 |
+
"gl": "us",
|
980 |
+
"hl": "en",
|
981 |
+
"api_key": os.getenv("SERP_API")
|
982 |
}
|
983 |
+
|
984 |
search = GoogleSearch(params)
|
985 |
results = search.get_dict()
|
986 |
+
hotel_results = results.get("hotel_results", [])
|
987 |
+
|
988 |
+
response_text = ""
|
989 |
+
for hotel in hotel_results[:5]: # Limiting to top 5 hotels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
990 |
name = hotel.get("title", "No name")
|
991 |
+
address = hotel.get("address", "No address")
|
992 |
rating = hotel.get("rating", "No rating")
|
|
|
993 |
price = hotel.get("price", "No price")
|
994 |
link = hotel.get("link", "#")
|
|
|
995 |
|
996 |
+
response_text += f"[{name}]({link})\n"
|
997 |
+
response_text += f"*{address}*\n"
|
998 |
+
response_text += f"**Rating:** {rating} stars\n"
|
999 |
+
response_text += f"**Price:** {price}\n"
|
1000 |
+
response_text += "-" * 50 + "\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1001 |
|
1002 |
+
return response_text
|
1003 |
|
1004 |
|
1005 |
|
|
|
1069 |
events_output = gr.HTML(value=fetch_local_events())
|
1070 |
# restaurant_output=gr.HTML(value=fetch_yelp_restaurants())
|
1071 |
|
1072 |
+
|
1073 |
|
1074 |
|
1075 |
with gr.Column():
|