Pijush2023 commited on
Commit
35dedb5
·
verified ·
1 Parent(s): 58d891d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
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":
@@ -962,6 +967,41 @@ def fetch_yelp_restaurants():
962
 
963
  return response_text
964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965
 
966
 
967
 
 
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":
 
967
 
968
  return response_text
969
 
970
+ def fetch_hotels_in_birmingham():
971
+ params = {
972
+ "engine": "google_hotels",
973
+ "q": "Hotels in Birmingham, AL",
974
+ "check_in_date": "2024-08-14",
975
+ "check_out_date": "2024-08-15",
976
+ "adults": "2",
977
+ "currency": "USD",
978
+ "gl": "us",
979
+ "hl": "en",
980
+ "api_key": os.getenv("SERP_API")
981
+ }
982
+
983
+ search = GoogleSearch(params)
984
+ results = search.get_dict()
985
+ hotels = results.get("organic_results", [])
986
+
987
+ response_text = ""
988
+
989
+ for hotel in hotels[:5]: # Limiting to top 5 hotels
990
+ name = hotel.get("title", "No name")
991
+ rating = hotel.get("rating", "No rating")
992
+ reviews = hotel.get("reviews", "No reviews")
993
+ price = hotel.get("price", "No price")
994
+ location = f"{name}, Birmingham, AL"
995
+ link = hotel.get("link", "#")
996
+
997
+ # Format the output for each hotel
998
+ response_text += f"[{name}]({link})\n"
999
+ response_text += f"*{location}*\n"
1000
+ response_text += f"**Price:** {price}\n"
1001
+ response_text += f"**Rating:** {rating} ({reviews} reviews)\n"
1002
+ response_text += "-" * 50 + "\n"
1003
+
1004
+ return response_text
1005
 
1006
 
1007