Pijush2023 commited on
Commit
5c00774
·
verified ·
1 Parent(s): 1c3e2c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -35
app.py CHANGED
@@ -314,7 +314,7 @@ def generate_answer(message, choice, retrieval_mode):
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
@@ -968,33 +968,27 @@ def fetch_yelp_restaurants():
968
  from serpapi.google_search import GoogleSearch
969
  from datetime import datetime, timedelta
970
 
971
- def fetch_hotels_birmingham():
 
 
 
972
  params = {
973
- "engine": "google_hotels",
974
- "q": "Birmingham Resorts,AL",
975
- "check_in_date": "2024-08-14",
976
- "check_out_date": "2024-08-15",
977
- "adults": "2",
978
- "currency": "USD",
979
- "gl": "us",
980
- "hl": "en",
981
- "api_key": "74972e6cc9f9e092bd86764a78f7d18c1d71b156eca8b1fe7fd65c2406cfb588"
982
  }
983
 
984
- # Send the request to the Google Hotels API
985
  search = GoogleSearch(params)
986
  results = search.get_dict()
987
-
988
- # Extract the hotel results from the response
989
- hotels = results.get("hotels_results", [])
990
-
991
- # Check if any hotels were found
992
- if not hotels:
993
- print("No resorts found in the response.")
994
- return "No resort information available."
995
 
996
  def star_rating(rating):
997
- # Convert the rating to a star format with half-stars if necessary
998
  full_stars = int(float(rating))
999
  half_star = 1 if (float(rating) - full_stars) >= 0.5 else 0
1000
  empty_stars = 5 - full_stars - half_star
@@ -1003,28 +997,21 @@ def fetch_hotels_birmingham():
1003
 
1004
  response_text = ""
1005
 
1006
- # Iterate through the top 5 resorts and format the response
1007
- for hotel in hotels[:5]: # Limiting to top 5 resorts
1008
  name = hotel.get("title", "No name")
1009
  rating = hotel.get("rating", "No rating")
1010
  reviews = hotel.get("reviews", "No reviews")
1011
- location = f"{name}, Bali"
1012
- price = hotel.get("price", "Price not available")
1013
  link = hotel.get("link", "#")
1014
- amenities = hotel.get("amenities", "Amenities not available")
1015
-
1016
- if isinstance(amenities, list):
1017
- amenities = ", ".join(amenities)
1018
 
1019
- # Format the output for each resort
1020
- response_text += f"[{name}]({link})\n" # Name with clickable link
1021
- response_text += f"*{location}*\n" # Location with resort name and "Bali"
1022
- response_text += f"**Price:** {price}\n"
1023
- response_text += f"**Amenities:** {amenities}\n"
1024
  response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
 
1025
  response_text += "-" * 50 + "\n"
1026
 
1027
- # Return the formatted response
1028
  return response_text
1029
 
1030
 
@@ -1035,6 +1022,7 @@ def fetch_hotels_birmingham():
1035
 
1036
 
1037
 
 
1038
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1039
  with gr.Row():
1040
  with gr.Column():
 
314
 
315
  # Check if the question is about hotels
316
  elif "hotels" in message.lower() and "birmingham" in message.lower():
317
+ response = fetch_google_hotels()
318
  return response, extract_addresses(response)
319
 
320
  prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
 
968
  from serpapi.google_search import GoogleSearch
969
  from datetime import datetime, timedelta
970
 
971
+ def fetch_google_hotels():
972
+
973
+ import os
974
+
975
  params = {
976
+ "engine": "google_hotels",
977
+ "q": "Birmingham Resorts",
978
+ "check_in_date": "2024-08-14",
979
+ "check_out_date": "2024-08-15",
980
+ "adults": "2",
981
+ "currency": "USD",
982
+ "gl": "us",
983
+ "hl": "en",
984
+ "api_key": os.getenv("SERP_API") # Ensure you use your SERP API key
985
  }
986
 
 
987
  search = GoogleSearch(params)
988
  results = search.get_dict()
989
+ hotel_results = results.get("hotels_results", [])
 
 
 
 
 
 
 
990
 
991
  def star_rating(rating):
 
992
  full_stars = int(float(rating))
993
  half_star = 1 if (float(rating) - full_stars) >= 0.5 else 0
994
  empty_stars = 5 - full_stars - half_star
 
997
 
998
  response_text = ""
999
 
1000
+ for hotel in hotel_results[:5]: # Limiting to top 5 hotels
 
1001
  name = hotel.get("title", "No name")
1002
  rating = hotel.get("rating", "No rating")
1003
  reviews = hotel.get("reviews", "No reviews")
1004
+ address = hotel.get("address", "Not Available")
1005
+ price = hotel.get("price", "Not Available")
1006
  link = hotel.get("link", "#")
 
 
 
 
1007
 
1008
+ # Format the output for each hotel
1009
+ response_text += f"[{name}]({link})\n" # Name with clickable link, no bold
1010
+ response_text += f"*{name}, {address}*\n" # Location with hotel name and address
 
 
1011
  response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
1012
+ response_text += f"**Price:** {price}\n"
1013
  response_text += "-" * 50 + "\n"
1014
 
 
1015
  return response_text
1016
 
1017
 
 
1022
 
1023
 
1024
 
1025
+
1026
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1027
  with gr.Row():
1028
  with gr.Column():