Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -967,51 +967,7 @@ def handle_retrieval_mode_change(choice):
|
|
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):
|
@@ -1124,6 +1080,19 @@ def fetch_yelp_restaurants():
|
|
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:"
|
@@ -1154,6 +1123,7 @@ def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_o
|
|
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 |
|
@@ -1165,25 +1135,86 @@ def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_o
|
|
1165 |
total_rate,
|
1166 |
description,
|
1167 |
check_in_time,
|
1168 |
-
check_out_time
|
|
|
1169 |
)
|
1170 |
|
1171 |
return hotel_info
|
1172 |
|
1173 |
|
1174 |
|
1175 |
-
def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="2024-08-14", return_date="2024-08-20"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1178 |
params = {
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
}
|
1188 |
|
1189 |
search = GoogleSearch(params)
|
@@ -1191,12 +1222,10 @@ def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="20
|
|
1191 |
|
1192 |
# Extract flight details from the results
|
1193 |
best_flights = results.get('best_flights', [])
|
1194 |
-
|
1195 |
|
1196 |
# Process each flight in the best_flights list
|
1197 |
for i, flight in enumerate(best_flights, start=1):
|
1198 |
-
flight_info = f"Flight {i}:\n"
|
1199 |
-
|
1200 |
for segment in flight.get('flights', []):
|
1201 |
departure_airport = segment.get('departure_airport', {}).get('name', 'Unknown Departure Airport')
|
1202 |
departure_time = segment.get('departure_airport', {}).get('time', 'Unknown Time')
|
@@ -1206,22 +1235,17 @@ def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="20
|
|
1206 |
airplane = segment.get('airplane', 'Unknown Airplane')
|
1207 |
|
1208 |
# Format the flight segment details
|
1209 |
-
flight_info +=
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
return final_output
|
1223 |
-
|
1224 |
-
|
1225 |
|
1226 |
|
1227 |
|
|
|
967 |
|
968 |
|
969 |
|
|
|
|
|
|
|
970 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
971 |
|
972 |
|
973 |
def format_restaurant_hotel_info(name, link, location, phone, rating, reviews, snippet):
|
|
|
1080 |
|
1081 |
|
1082 |
|
1083 |
+
def format_hotel_info(name, link, location, rate_per_night, total_rate, description, check_in_time, check_out_time, amenities):
|
1084 |
+
return f"""
|
1085 |
+
{name}
|
1086 |
+
|
1087 |
+
- Link: {link}
|
1088 |
+
- Location: {location}
|
1089 |
+
- Rate per Night: {rate_per_night} (Before taxes/fees: {total_rate})
|
1090 |
+
- Check-in Time: {check_in_time}
|
1091 |
+
- Check-out Time: {check_out_time}
|
1092 |
+
- Amenities: {amenities}
|
1093 |
+
- Description: {description}
|
1094 |
+
"""
|
1095 |
+
|
1096 |
def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_out="2024-08-15", adults=2):
|
1097 |
# Introductory prompt for hotels
|
1098 |
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:"
|
|
|
1123 |
rate_per_night = hotel.get('rate_per_night', {}).get('lowest', 'N/A')
|
1124 |
before_taxes_fees = hotel.get('rate_per_night', {}).get('before_taxes_fees', 'N/A')
|
1125 |
total_rate = hotel.get('total_rate', {}).get('lowest', 'N/A')
|
1126 |
+
amenities = ", ".join(hotel.get('amenities', [])) if hotel.get('amenities') else "Not Available"
|
1127 |
|
1128 |
location = f"{name}, Birmingham, AL"
|
1129 |
|
|
|
1135 |
total_rate,
|
1136 |
description,
|
1137 |
check_in_time,
|
1138 |
+
check_out_time,
|
1139 |
+
amenities
|
1140 |
)
|
1141 |
|
1142 |
return hotel_info
|
1143 |
|
1144 |
|
1145 |
|
1146 |
+
# def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="2024-08-14", return_date="2024-08-20"):
|
1147 |
+
|
1148 |
+
|
1149 |
+
# params = {
|
1150 |
+
# "engine": "google_flights",
|
1151 |
+
# "departure_id": departure_id,
|
1152 |
+
# "arrival_id": arrival_id,
|
1153 |
+
# "outbound_date": outbound_date,
|
1154 |
+
# "return_date": return_date,
|
1155 |
+
# "currency": "USD",
|
1156 |
+
# "hl": "en",
|
1157 |
+
# "api_key": os.getenv("SERP_API") # Replace with your actual API key
|
1158 |
+
# }
|
1159 |
+
|
1160 |
+
# search = GoogleSearch(params)
|
1161 |
+
# results = search.get_dict()
|
1162 |
|
1163 |
+
# # Extract flight details from the results
|
1164 |
+
# best_flights = results.get('best_flights', [])
|
1165 |
+
# formatted_flights = []
|
1166 |
+
|
1167 |
+
# # Process each flight in the best_flights list
|
1168 |
+
# for i, flight in enumerate(best_flights, start=1):
|
1169 |
+
# flight_info = f"Flight {i}:\n"
|
1170 |
+
|
1171 |
+
# for segment in flight.get('flights', []):
|
1172 |
+
# departure_airport = segment.get('departure_airport', {}).get('name', 'Unknown Departure Airport')
|
1173 |
+
# departure_time = segment.get('departure_airport', {}).get('time', 'Unknown Time')
|
1174 |
+
# arrival_airport = segment.get('arrival_airport', {}).get('name', 'Unknown Arrival Airport')
|
1175 |
+
# arrival_time = segment.get('arrival_airport', {}).get('time', 'Unknown Time')
|
1176 |
+
# duration = segment.get('duration', 'Unknown Duration')
|
1177 |
+
# airplane = segment.get('airplane', 'Unknown Airplane')
|
1178 |
+
|
1179 |
+
# # Format the flight segment details
|
1180 |
+
# flight_info += f" - Departure: {departure_airport} at {departure_time}\n"
|
1181 |
+
# flight_info += f" - Arrival: {arrival_airport} at {arrival_time}\n"
|
1182 |
+
# flight_info += f" - Duration: {duration} minutes\n"
|
1183 |
+
# flight_info += f" - Airplane: {airplane}\n"
|
1184 |
+
|
1185 |
+
# formatted_flights.append(flight_info)
|
1186 |
+
|
1187 |
+
# # Combine the formatted flight information into a single output
|
1188 |
+
# final_output = "Here are some available flights for today:\n\n" + "\n".join(formatted_flights)
|
1189 |
+
|
1190 |
+
|
1191 |
|
1192 |
+
|
1193 |
+
# return final_output
|
1194 |
+
|
1195 |
+
def format_flight_info(flight_number, departure_airport, departure_time, arrival_airport, arrival_time, duration, airplane):
|
1196 |
+
return f"""
|
1197 |
+
Flight {flight_number}
|
1198 |
+
|
1199 |
+
- Departure: {departure_airport} at {departure_time}
|
1200 |
+
- Arrival: {arrival_airport} at {arrival_time}
|
1201 |
+
- Duration: {duration} minutes
|
1202 |
+
- Airplane: {airplane}
|
1203 |
+
"""
|
1204 |
+
|
1205 |
+
def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="2024-08-14", return_date="2024-08-20"):
|
1206 |
+
# Introductory prompt for flights
|
1207 |
+
intro_prompt = "Here are some available flights from JFK to Birmingham, Alabama. These options provide a range of times and durations to fit your travel needs:"
|
1208 |
+
|
1209 |
params = {
|
1210 |
+
"engine": "google_flights",
|
1211 |
+
"departure_id": departure_id,
|
1212 |
+
"arrival_id": arrival_id,
|
1213 |
+
"outbound_date": outbound_date,
|
1214 |
+
"return_date": return_date,
|
1215 |
+
"currency": "USD",
|
1216 |
+
"hl": "en",
|
1217 |
+
"api_key": os.getenv("SERP_API")
|
1218 |
}
|
1219 |
|
1220 |
search = GoogleSearch(params)
|
|
|
1222 |
|
1223 |
# Extract flight details from the results
|
1224 |
best_flights = results.get('best_flights', [])
|
1225 |
+
flight_info = f"{intro_prompt}\n"
|
1226 |
|
1227 |
# Process each flight in the best_flights list
|
1228 |
for i, flight in enumerate(best_flights, start=1):
|
|
|
|
|
1229 |
for segment in flight.get('flights', []):
|
1230 |
departure_airport = segment.get('departure_airport', {}).get('name', 'Unknown Departure Airport')
|
1231 |
departure_time = segment.get('departure_airport', {}).get('time', 'Unknown Time')
|
|
|
1235 |
airplane = segment.get('airplane', 'Unknown Airplane')
|
1236 |
|
1237 |
# Format the flight segment details
|
1238 |
+
flight_info += format_flight_info(
|
1239 |
+
flight_number=i,
|
1240 |
+
departure_airport=departure_airport,
|
1241 |
+
departure_time=departure_time,
|
1242 |
+
arrival_airport=arrival_airport,
|
1243 |
+
arrival_time=arrival_time,
|
1244 |
+
duration=duration,
|
1245 |
+
airplane=airplane
|
1246 |
+
)
|
1247 |
|
1248 |
+
return flight_info
|
|
|
|
|
|
|
|
|
|
|
1249 |
|
1250 |
|
1251 |
|