Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -308,12 +308,12 @@ 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 |
# Check if the question is about flights
|
@@ -600,8 +600,54 @@ def show_map_if_details(history, choice):
|
|
600 |
else:
|
601 |
return gr.update(visible(False), "")
|
602 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
def generate_audio_elevenlabs(text):
|
604 |
-
XI_API_KEY = os.
|
605 |
VOICE_ID = 'd9MIrwLnvDeH7aZb61E9'
|
606 |
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
607 |
headers = {
|
@@ -609,7 +655,7 @@ def generate_audio_elevenlabs(text):
|
|
609 |
"xi-api-key": XI_API_KEY
|
610 |
}
|
611 |
data = {
|
612 |
-
"text":
|
613 |
"model_id": "eleven_multilingual_v2",
|
614 |
"voice_settings": {
|
615 |
"stability": 1.0,
|
@@ -620,26 +666,17 @@ def generate_audio_elevenlabs(text):
|
|
620 |
}
|
621 |
response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
622 |
if response.ok:
|
623 |
-
audio_segments = []
|
624 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
625 |
for chunk in response.iter_content(chunk_size=1024):
|
626 |
if chunk:
|
627 |
f.write(chunk)
|
628 |
-
|
629 |
-
temp_audio_path = f.name
|
630 |
-
|
631 |
-
# Combine all audio chunks into a single file
|
632 |
-
combined_audio = AudioSegment.from_file(temp_audio_path, format="mp3")
|
633 |
-
combined_audio_path = os.path.join(tempfile.gettempdir(), "elevenlabs_combined_audio.mp3")
|
634 |
-
combined_audio.export(combined_audio_path, format="mp3")
|
635 |
-
|
636 |
-
logging.debug(f"Audio saved to {combined_audio_path}")
|
637 |
-
return combined_audio_path
|
638 |
else:
|
639 |
logging.error(f"Error generating audio: {response.text}")
|
640 |
return None
|
641 |
|
642 |
|
|
|
643 |
repo_id = "parler-tts/parler-tts-mini-expresso"
|
644 |
|
645 |
parler_model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
|
@@ -930,31 +967,82 @@ def handle_retrieval_mode_change(choice):
|
|
930 |
|
931 |
|
932 |
|
933 |
-
def fetch_yelp_restaurants():
|
934 |
-
|
935 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
936 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
937 |
params = {
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
}
|
943 |
|
944 |
search = GoogleSearch(params)
|
945 |
results = search.get_dict()
|
946 |
organic_results = results.get("organic_results", [])
|
947 |
|
948 |
-
|
949 |
-
full_stars = int(float(rating))
|
950 |
-
half_star = 1 if (float(rating) - full_stars) >= 0.5 else 0
|
951 |
-
empty_stars = 5 - full_stars - half_star
|
952 |
-
stars = "★" * full_stars + "½" * half_star + "☆" * empty_stars
|
953 |
-
return stars
|
954 |
-
|
955 |
-
response_text = ""
|
956 |
|
957 |
-
for result in organic_results[:5]: # Limiting to top
|
958 |
name = result.get("title", "No name")
|
959 |
rating = result.get("rating", "No rating")
|
960 |
reviews = result.get("reviews", "No reviews")
|
@@ -963,22 +1051,83 @@ def fetch_yelp_restaurants():
|
|
963 |
location = f"{name}, Birmingham, AL"
|
964 |
link = result.get("link", "#")
|
965 |
|
966 |
-
|
967 |
-
|
|
|
|
|
968 |
|
969 |
-
# Format the output for each restaurant
|
970 |
-
response_text += f"[{name}]({link})\n" # Name with clickable link, no bold
|
971 |
-
response_text += f"*{location}*\n" # Location with restaurant name and "Birmingham, AL"
|
972 |
-
response_text += f"**Contact No:** {phone}\n"
|
973 |
-
response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
|
974 |
-
response_text += f"**Snippet:** {snippet}\n"
|
975 |
-
response_text += "-" * 50 + "\n"
|
976 |
|
977 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
978 |
|
979 |
|
980 |
|
981 |
def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_out="2024-08-15", adults=2):
|
|
|
|
|
|
|
982 |
params = {
|
983 |
"engine": "google_hotels",
|
984 |
"q": query,
|
@@ -995,49 +1144,7 @@ def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_o
|
|
995 |
results = search.get_dict()
|
996 |
hotel_results = results.get("properties", [])
|
997 |
|
998 |
-
|
999 |
-
# for hotel in hotel_results[:5]: # Limiting to top 5 hotels
|
1000 |
-
# name = hotel.get('name', 'No name')
|
1001 |
-
# description = hotel.get('description', 'No description')
|
1002 |
-
# link = hotel.get('link', '#')
|
1003 |
-
# check_in_time = hotel.get('check_in_time', 'N/A')
|
1004 |
-
# check_out_time = hotel.get('check_out_time', 'N/A')
|
1005 |
-
# rate_per_night = hotel.get('rate_per_night', {}).get('lowest', 'N/A')
|
1006 |
-
# before_taxes_fees = hotel.get('rate_per_night', {}).get('before_taxes_fees', 'N/A')
|
1007 |
-
# total_rate = hotel.get('total_rate', {}).get('lowest', 'N/A')
|
1008 |
-
# deal = hotel.get('deal', 'N/A')
|
1009 |
-
# deal_description = hotel.get('deal_description', 'N/A')
|
1010 |
-
# nearby_places = hotel.get('nearby_places', [])
|
1011 |
-
# amenities = hotel.get('amenities', [])
|
1012 |
-
|
1013 |
-
# hotel_info += f"**Hotel Name:** [{name}]({link})\n"
|
1014 |
-
# hotel_info += f"**Description:** {description}\n"
|
1015 |
-
# hotel_info += f"**Check-in Time:** {check_in_time}\n"
|
1016 |
-
# hotel_info += f"**Check-out Time:** {check_out_time}\n"
|
1017 |
-
# hotel_info += f"**Rate per Night:** {rate_per_night} (Before taxes/fees: {before_taxes_fees})\n"
|
1018 |
-
# hotel_info += f"**Total Rate:** {total_rate}\n"
|
1019 |
-
# hotel_info += f"**Deal:** {deal} ({deal_description})\n"
|
1020 |
-
|
1021 |
-
# if nearby_places:
|
1022 |
-
# hotel_info += "**Nearby Places:**\n"
|
1023 |
-
# for place in nearby_places:
|
1024 |
-
# place_name = place.get('name', 'Unknown Place')
|
1025 |
-
# transportations = place.get('transportations', [])
|
1026 |
-
# hotel_info += f" - {place_name}:\n"
|
1027 |
-
# for transport in transportations:
|
1028 |
-
# transport_type = transport.get('type', 'N/A')
|
1029 |
-
# duration = transport.get('duration', 'N/A')
|
1030 |
-
# hotel_info += f" - {transport_type}: {duration}\n"
|
1031 |
-
|
1032 |
-
# if amenities:
|
1033 |
-
# hotel_info += "**Amenities:**\n"
|
1034 |
-
# hotel_info += ", ".join(amenities) + "\n"
|
1035 |
-
|
1036 |
-
# hotel_info += "-" * 50 + "\n"
|
1037 |
-
|
1038 |
-
# return hotel_info
|
1039 |
-
|
1040 |
-
hotel_info = ""
|
1041 |
for hotel in hotel_results[:5]: # Limiting to top 5 hotels
|
1042 |
name = hotel.get('name', 'No name')
|
1043 |
description = hotel.get('description', 'No description')
|
@@ -1047,40 +1154,20 @@ def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_o
|
|
1047 |
rate_per_night = hotel.get('rate_per_night', {}).get('lowest', 'N/A')
|
1048 |
before_taxes_fees = hotel.get('rate_per_night', {}).get('before_taxes_fees', 'N/A')
|
1049 |
total_rate = hotel.get('total_rate', {}).get('lowest', 'N/A')
|
1050 |
-
|
1051 |
-
deal_description = hotel.get('deal_description', 'N/A')
|
1052 |
-
nearby_places = hotel.get('nearby_places', [])
|
1053 |
-
amenities = hotel.get('amenities', [])
|
1054 |
-
|
1055 |
-
# Adding the "Location" field
|
1056 |
location = f"{name}, Birmingham, AL"
|
1057 |
-
|
1058 |
-
hotel_info += f"**Hotel Name:** [{name}]({link})\n"
|
1059 |
-
hotel_info += f"**Location:** {location}\n"
|
1060 |
-
hotel_info += f"**Description:** {description}\n"
|
1061 |
-
hotel_info += f"**Check-in Time:** {check_in_time}\n"
|
1062 |
-
hotel_info += f"**Check-out Time:** {check_out_time}\n"
|
1063 |
-
hotel_info += f"**Rate per Night:** {rate_per_night} (Before taxes/fees: {before_taxes_fees})\n"
|
1064 |
-
hotel_info += f"**Total Rate:** {total_rate}\n"
|
1065 |
-
hotel_info += f"**Deal:** {deal} ({deal_description})\n"
|
1066 |
-
|
1067 |
-
if nearby_places:
|
1068 |
-
hotel_info += "**Nearby Places:**\n"
|
1069 |
-
for place in nearby_places:
|
1070 |
-
place_name = place.get('name', 'Unknown Place')
|
1071 |
-
transportations = place.get('transportations', [])
|
1072 |
-
hotel_info += f" - {place_name}:\n"
|
1073 |
-
for transport in transportations:
|
1074 |
-
transport_type = transport.get('type', 'N/A')
|
1075 |
-
duration = transport.get('duration', 'N/A')
|
1076 |
-
hotel_info += f" - {transport_type}: {duration}\n"
|
1077 |
-
|
1078 |
-
if amenities:
|
1079 |
-
hotel_info += "**Amenities:**\n"
|
1080 |
-
hotel_info += ", ".join(amenities) + "\n"
|
1081 |
-
|
1082 |
-
hotel_info += "-" * 50 + "\n"
|
1083 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1084 |
return hotel_info
|
1085 |
|
1086 |
|
|
|
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() or if "hotels" 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() or "restaurants" in message.lower() and "birmingham" in message.lower():
|
317 |
response = fetch_yelp_restaurants()
|
318 |
return response, extract_addresses(response)
|
319 |
# Check if the question is about flights
|
|
|
600 |
else:
|
601 |
return gr.update(visible(False), "")
|
602 |
|
603 |
+
# def generate_audio_elevenlabs(text):
|
604 |
+
# XI_API_KEY = os.environ['ELEVENLABS_API']
|
605 |
+
# VOICE_ID = 'd9MIrwLnvDeH7aZb61E9'
|
606 |
+
# tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
607 |
+
# headers = {
|
608 |
+
# "Accept": "application/json",
|
609 |
+
# "xi-api-key": XI_API_KEY
|
610 |
+
# }
|
611 |
+
# data = {
|
612 |
+
# "text": str(text),
|
613 |
+
# "model_id": "eleven_multilingual_v2",
|
614 |
+
# "voice_settings": {
|
615 |
+
# "stability": 1.0,
|
616 |
+
# "similarity_boost": 0.0,
|
617 |
+
# "style": 0.60,
|
618 |
+
# "use_speaker_boost": False
|
619 |
+
# }
|
620 |
+
# }
|
621 |
+
# response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
622 |
+
# if response.ok:
|
623 |
+
# audio_segments = []
|
624 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
625 |
+
# for chunk in response.iter_content(chunk_size=1024):
|
626 |
+
# if chunk:
|
627 |
+
# f.write(chunk)
|
628 |
+
# audio_segments.append(chunk)
|
629 |
+
# temp_audio_path = f.name
|
630 |
+
|
631 |
+
# # Combine all audio chunks into a single file
|
632 |
+
# combined_audio = AudioSegment.from_file(temp_audio_path, format="mp3")
|
633 |
+
# combined_audio_path = os.path.join(tempfile.gettempdir(), "elevenlabs_combined_audio.mp3")
|
634 |
+
# combined_audio.export(combined_audio_path, format="mp3")
|
635 |
+
|
636 |
+
# logging.debug(f"Audio saved to {combined_audio_path}")
|
637 |
+
# return combined_audio_path
|
638 |
+
# else:
|
639 |
+
# logging.error(f"Error generating audio: {response.text}")
|
640 |
+
# return None
|
641 |
+
|
642 |
+
|
643 |
+
def preprocess_for_tts(text):
|
644 |
+
# Remove the word "Link" and any URLs from the text
|
645 |
+
text = re.sub(r'\bLink\b', '', text) # Remove the word "Link"
|
646 |
+
text = re.sub(r'http\S+', '', text) # Remove URLs
|
647 |
+
return text.strip() # Remove any extra spaces
|
648 |
+
|
649 |
def generate_audio_elevenlabs(text):
|
650 |
+
XI_API_KEY = os.getenv('ELEVENLABS_API')
|
651 |
VOICE_ID = 'd9MIrwLnvDeH7aZb61E9'
|
652 |
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
653 |
headers = {
|
|
|
655 |
"xi-api-key": XI_API_KEY
|
656 |
}
|
657 |
data = {
|
658 |
+
"text": preprocess_for_tts(text), # Apply preprocessing before sending to TTS
|
659 |
"model_id": "eleven_multilingual_v2",
|
660 |
"voice_settings": {
|
661 |
"stability": 1.0,
|
|
|
666 |
}
|
667 |
response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
668 |
if response.ok:
|
|
|
669 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
670 |
for chunk in response.iter_content(chunk_size=1024):
|
671 |
if chunk:
|
672 |
f.write(chunk)
|
673 |
+
return f.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
674 |
else:
|
675 |
logging.error(f"Error generating audio: {response.text}")
|
676 |
return None
|
677 |
|
678 |
|
679 |
+
|
680 |
repo_id = "parler-tts/parler-tts-mini-expresso"
|
681 |
|
682 |
parler_model = ParlerTTSForConditionalGeneration.from_pretrained(repo_id).to(device)
|
|
|
967 |
|
968 |
|
969 |
|
970 |
+
# def fetch_yelp_restaurants():
|
971 |
+
# from serpapi.google_search import GoogleSearch
|
972 |
+
# import os
|
973 |
+
|
974 |
+
# params = {
|
975 |
+
# "engine": "yelp",
|
976 |
+
# "find_desc": "Restaurant",
|
977 |
+
# "find_loc": "Birmingham, AL, USA",
|
978 |
+
# "api_key": os.getenv("SERP_API")
|
979 |
+
# }
|
980 |
+
|
981 |
+
# search = GoogleSearch(params)
|
982 |
+
# results = search.get_dict()
|
983 |
+
# organic_results = results.get("organic_results", [])
|
984 |
|
985 |
+
# def star_rating(rating):
|
986 |
+
# full_stars = int(float(rating))
|
987 |
+
# half_star = 1 if (float(rating) - full_stars) >= 0.5 else 0
|
988 |
+
# empty_stars = 5 - full_stars - half_star
|
989 |
+
# stars = "★" * full_stars + "½" * half_star + "☆" * empty_stars
|
990 |
+
# return stars
|
991 |
+
|
992 |
+
# response_text = ""
|
993 |
+
|
994 |
+
# for result in organic_results[:5]: # Limiting to top 10 restaurants
|
995 |
+
# name = result.get("title", "No name")
|
996 |
+
# rating = result.get("rating", "No rating")
|
997 |
+
# reviews = result.get("reviews", "No reviews")
|
998 |
+
# phone = result.get("phone", "Not Available")
|
999 |
+
# snippet = result.get("snippet", "Not Available")
|
1000 |
+
# location = f"{name}, Birmingham, AL"
|
1001 |
+
# link = result.get("link", "#")
|
1002 |
+
|
1003 |
+
# if isinstance(snippet, list):
|
1004 |
+
# snippet = " | ".join(snippet[:5]) # Limiting to top 5 snippets
|
1005 |
+
|
1006 |
+
# # Format the output for each restaurant
|
1007 |
+
# response_text += f"[{name}]({link})\n" # Name with clickable link, no bold
|
1008 |
+
# response_text += f"*{location}*\n" # Location with restaurant name and "Birmingham, AL"
|
1009 |
+
# response_text += f"**Contact No:** {phone}\n"
|
1010 |
+
# response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
|
1011 |
+
# response_text += f"**Snippet:** {snippet}\n"
|
1012 |
+
# response_text += "-" * 50 + "\n"
|
1013 |
+
|
1014 |
+
# return response_text
|
1015 |
+
|
1016 |
+
|
1017 |
+
def format_restaurant_hotel_info(name, link, location, phone, rating, reviews, snippet):
|
1018 |
+
return f"""
|
1019 |
+
{name}
|
1020 |
+
|
1021 |
+
- Link: {link}
|
1022 |
+
- Location: {location}
|
1023 |
+
- Contact No: {phone}
|
1024 |
+
- Rating: {rating} stars ({reviews} reviews)
|
1025 |
+
- Snippet: {snippet}
|
1026 |
+
"""
|
1027 |
+
|
1028 |
+
def fetch_yelp_restaurants():
|
1029 |
+
# Introductory prompt for restaurants
|
1030 |
+
intro_prompt = "Here are some of the top-rated restaurants in Birmingham, Alabama. I hope these suggestions help you find the perfect place to enjoy your meal:"
|
1031 |
+
|
1032 |
params = {
|
1033 |
+
"engine": "yelp",
|
1034 |
+
"find_desc": "Restaurant",
|
1035 |
+
"find_loc": "Birmingham, AL, USA",
|
1036 |
+
"api_key": os.getenv("SERP_API")
|
1037 |
}
|
1038 |
|
1039 |
search = GoogleSearch(params)
|
1040 |
results = search.get_dict()
|
1041 |
organic_results = results.get("organic_results", [])
|
1042 |
|
1043 |
+
response_text = f"{intro_prompt}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1044 |
|
1045 |
+
for result in organic_results[:5]: # Limiting to top 5 restaurants
|
1046 |
name = result.get("title", "No name")
|
1047 |
rating = result.get("rating", "No rating")
|
1048 |
reviews = result.get("reviews", "No reviews")
|
|
|
1051 |
location = f"{name}, Birmingham, AL"
|
1052 |
link = result.get("link", "#")
|
1053 |
|
1054 |
+
response_text += format_restaurant_hotel_info(name, link, location, phone, rating, reviews, snippet)
|
1055 |
+
|
1056 |
+
return response_text
|
1057 |
+
|
1058 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1059 |
|
1060 |
+
# def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_out="2024-08-15", adults=2):
|
1061 |
+
# params = {
|
1062 |
+
# "engine": "google_hotels",
|
1063 |
+
# "q": query,
|
1064 |
+
# "check_in_date": check_in,
|
1065 |
+
# "check_out_date": check_out,
|
1066 |
+
# "adults": str(adults),
|
1067 |
+
# "currency": "USD",
|
1068 |
+
# "gl": "us",
|
1069 |
+
# "hl": "en",
|
1070 |
+
# "api_key": os.getenv("SERP_API")
|
1071 |
+
# }
|
1072 |
+
|
1073 |
+
# search = GoogleSearch(params)
|
1074 |
+
# results = search.get_dict()
|
1075 |
+
# hotel_results = results.get("properties", [])
|
1076 |
+
|
1077 |
+
|
1078 |
+
|
1079 |
+
# hotel_info = ""
|
1080 |
+
# for hotel in hotel_results[:5]: # Limiting to top 5 hotels
|
1081 |
+
# name = hotel.get('name', 'No name')
|
1082 |
+
# description = hotel.get('description', 'No description')
|
1083 |
+
# link = hotel.get('link', '#')
|
1084 |
+
# check_in_time = hotel.get('check_in_time', 'N/A')
|
1085 |
+
# check_out_time = hotel.get('check_out_time', 'N/A')
|
1086 |
+
# rate_per_night = hotel.get('rate_per_night', {}).get('lowest', 'N/A')
|
1087 |
+
# before_taxes_fees = hotel.get('rate_per_night', {}).get('before_taxes_fees', 'N/A')
|
1088 |
+
# total_rate = hotel.get('total_rate', {}).get('lowest', 'N/A')
|
1089 |
+
# deal = hotel.get('deal', 'N/A')
|
1090 |
+
# deal_description = hotel.get('deal_description', 'N/A')
|
1091 |
+
# nearby_places = hotel.get('nearby_places', [])
|
1092 |
+
# amenities = hotel.get('amenities', [])
|
1093 |
+
|
1094 |
+
# # Adding the "Location" field
|
1095 |
+
# location = f"{name}, Birmingham, AL"
|
1096 |
+
|
1097 |
+
# hotel_info += f"**Hotel Name:** [{name}]({link})\n"
|
1098 |
+
# hotel_info += f"**Location:** {location}\n"
|
1099 |
+
# hotel_info += f"**Description:** {description}\n"
|
1100 |
+
# hotel_info += f"**Check-in Time:** {check_in_time}\n"
|
1101 |
+
# hotel_info += f"**Check-out Time:** {check_out_time}\n"
|
1102 |
+
# hotel_info += f"**Rate per Night:** {rate_per_night} (Before taxes/fees: {before_taxes_fees})\n"
|
1103 |
+
# hotel_info += f"**Total Rate:** {total_rate}\n"
|
1104 |
+
# hotel_info += f"**Deal:** {deal} ({deal_description})\n"
|
1105 |
+
|
1106 |
+
# if nearby_places:
|
1107 |
+
# hotel_info += "**Nearby Places:**\n"
|
1108 |
+
# for place in nearby_places:
|
1109 |
+
# place_name = place.get('name', 'Unknown Place')
|
1110 |
+
# transportations = place.get('transportations', [])
|
1111 |
+
# hotel_info += f" - {place_name}:\n"
|
1112 |
+
# for transport in transportations:
|
1113 |
+
# transport_type = transport.get('type', 'N/A')
|
1114 |
+
# duration = transport.get('duration', 'N/A')
|
1115 |
+
# hotel_info += f" - {transport_type}: {duration}\n"
|
1116 |
+
|
1117 |
+
# if amenities:
|
1118 |
+
# hotel_info += "**Amenities:**\n"
|
1119 |
+
# hotel_info += ", ".join(amenities) + "\n"
|
1120 |
+
|
1121 |
+
# hotel_info += "-" * 50 + "\n"
|
1122 |
+
|
1123 |
+
# return hotel_info
|
1124 |
|
1125 |
|
1126 |
|
1127 |
def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_out="2024-08-15", adults=2):
|
1128 |
+
# Introductory prompt for hotels
|
1129 |
+
intro_prompt = "Here are some of the best hotels in Birmingham, Alabama, for your stay. Each of these options offers a unique experience, whether you're looking for luxury, comfort, or convenience:"
|
1130 |
+
|
1131 |
params = {
|
1132 |
"engine": "google_hotels",
|
1133 |
"q": query,
|
|
|
1144 |
results = search.get_dict()
|
1145 |
hotel_results = results.get("properties", [])
|
1146 |
|
1147 |
+
hotel_info = f"{intro_prompt}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1148 |
for hotel in hotel_results[:5]: # Limiting to top 5 hotels
|
1149 |
name = hotel.get('name', 'No name')
|
1150 |
description = hotel.get('description', 'No description')
|
|
|
1154 |
rate_per_night = hotel.get('rate_per_night', {}).get('lowest', 'N/A')
|
1155 |
before_taxes_fees = hotel.get('rate_per_night', {}).get('before_taxes_fees', 'N/A')
|
1156 |
total_rate = hotel.get('total_rate', {}).get('lowest', 'N/A')
|
1157 |
+
|
|
|
|
|
|
|
|
|
|
|
1158 |
location = f"{name}, Birmingham, AL"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1159 |
|
1160 |
+
hotel_info += format_hotel_info(
|
1161 |
+
name,
|
1162 |
+
link,
|
1163 |
+
location,
|
1164 |
+
rate_per_night,
|
1165 |
+
total_rate,
|
1166 |
+
description,
|
1167 |
+
check_in_time,
|
1168 |
+
check_out_time
|
1169 |
+
)
|
1170 |
+
|
1171 |
return hotel_info
|
1172 |
|
1173 |
|