Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -316,6 +316,10 @@ def generate_answer(message, choice, retrieval_mode):
|
|
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 |
|
@@ -1032,6 +1036,50 @@ def fetch_google_hotels(query="Birmingham Hotel", check_in="2024-08-14", check_o
|
|
1032 |
|
1033 |
return hotel_info
|
1034 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1035 |
|
1036 |
|
1037 |
|
|
|
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
|
320 |
+
if "flight" in message.lower() and ("JFK" in message or "BHM" in message):
|
321 |
+
response = fetch_google_flights()
|
322 |
+
return response, extract_addresses(response)
|
323 |
|
324 |
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
325 |
|
|
|
1036 |
|
1037 |
return hotel_info
|
1038 |
|
1039 |
+
from serpapi import GoogleSearch
|
1040 |
+
|
1041 |
+
def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="2024-08-14", return_date="2024-08-20"):
|
1042 |
+
params = {
|
1043 |
+
"engine": "google_flights",
|
1044 |
+
"departure_id": departure_id,
|
1045 |
+
"arrival_id": arrival_id,
|
1046 |
+
"outbound_date": outbound_date,
|
1047 |
+
"return_date": return_date,
|
1048 |
+
"currency": "USD",
|
1049 |
+
"hl": "en",
|
1050 |
+
"api_key": os.getenv("SERP_API")
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
search = GoogleSearch(params)
|
1054 |
+
results = search.get_dict()
|
1055 |
+
|
1056 |
+
flight_info = ""
|
1057 |
+
best_flights = results.get('best_flights', [])
|
1058 |
+
|
1059 |
+
for flight in best_flights[:5]: # Limiting to top 5 flights
|
1060 |
+
flight_segments = flight.get('flights', [])
|
1061 |
+
if not flight_segments:
|
1062 |
+
continue
|
1063 |
+
|
1064 |
+
for segment in flight_segments:
|
1065 |
+
departure_airport = segment.get('departure_airport', {}).get('name', 'Unknown Departure Airport')
|
1066 |
+
departure_time = segment.get('departure_airport', {}).get('time', 'Unknown Time')
|
1067 |
+
arrival_airport = segment.get('arrival_airport', {}).get('name', 'Unknown Arrival Airport')
|
1068 |
+
arrival_time = segment.get('arrival_airport', {}).get('time', 'Unknown Time')
|
1069 |
+
duration = segment.get('duration', 'Unknown Duration')
|
1070 |
+
airplane = segment.get('airplane', 'Unknown Airplane')
|
1071 |
+
|
1072 |
+
flight_info += f"**Flight Segment:**\n"
|
1073 |
+
flight_info += f" - **Departure:** {departure_airport} at {departure_time}\n"
|
1074 |
+
flight_info += f" - **Arrival:** {arrival_airport} at {arrival_time}\n"
|
1075 |
+
flight_info += f" - **Duration:** {duration} minutes\n"
|
1076 |
+
flight_info += f" - **Airplane:** {airplane}\n"
|
1077 |
+
|
1078 |
+
flight_info += "-" * 50 + "\n"
|
1079 |
+
|
1080 |
+
return flight_info
|
1081 |
+
|
1082 |
+
|
1083 |
|
1084 |
|
1085 |
|