Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -307,16 +307,16 @@ chain_neo4j = (
|
|
| 307 |
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 restaurants
|
| 311 |
if "restaurant" in message.lower() and "birmingham" in message.lower():
|
| 312 |
response = fetch_yelp_restaurants()
|
| 313 |
return response, extract_addresses(response)
|
| 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
|
| 321 |
|
| 322 |
if retrieval_mode == "VDB":
|
|
@@ -338,6 +338,7 @@ def generate_answer(message, choice, retrieval_mode):
|
|
| 338 |
|
| 339 |
|
| 340 |
|
|
|
|
| 341 |
def bot(history, choice, tts_choice, retrieval_mode):
|
| 342 |
if not history:
|
| 343 |
return history
|
|
@@ -1014,6 +1015,48 @@ def fetch_google_hotels():
|
|
| 1014 |
|
| 1015 |
return response_text
|
| 1016 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
|
|
|
| 307 |
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 flights
|
| 311 |
+
if "flight" in message.lower() and ("to" in message.lower() or "from" in message.lower()):
|
| 312 |
+
response = fetch_flight_info(message)
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
| 321 |
|
| 322 |
if retrieval_mode == "VDB":
|
|
|
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
+
|
| 342 |
def bot(history, choice, tts_choice, retrieval_mode):
|
| 343 |
if not history:
|
| 344 |
return history
|
|
|
|
| 1015 |
|
| 1016 |
return response_text
|
| 1017 |
|
| 1018 |
+
def fetch_flight_info(message):
|
| 1019 |
+
|
| 1020 |
+
departure_id = "JFK" # Replace with parsed value from the message
|
| 1021 |
+
arrival_id = "BHM" # Replace with parsed value from the message
|
| 1022 |
+
outbound_date = "2024-08-14" # Replace with parsed date from the message
|
| 1023 |
+
return_date = "2024-08-20" # Replace with parsed date if applicable
|
| 1024 |
+
|
| 1025 |
+
params = {
|
| 1026 |
+
"engine": "google_flights",
|
| 1027 |
+
"departure_id": departure_id,
|
| 1028 |
+
"arrival_id": arrival_id,
|
| 1029 |
+
"outbound_date": outbound_date,
|
| 1030 |
+
"return_date": return_date,
|
| 1031 |
+
"currency": "USD",
|
| 1032 |
+
"hl": "en",
|
| 1033 |
+
"api_key": os.getenv("SERP_API")
|
| 1034 |
+
}
|
| 1035 |
+
|
| 1036 |
+
search = GoogleSearch(params)
|
| 1037 |
+
results = search.get_dict()
|
| 1038 |
+
flights_results = results.get("flights_results", [])
|
| 1039 |
+
|
| 1040 |
+
response_text = ""
|
| 1041 |
+
|
| 1042 |
+
for flight in flights_results[:5]: # Limiting to top 5 flight options
|
| 1043 |
+
price = flight.get("price", "No price")
|
| 1044 |
+
duration = flight.get("duration", "No duration")
|
| 1045 |
+
stops = flight.get("stops", "Direct flight")
|
| 1046 |
+
departure_time = flight.get("departure_time", "No departure time")
|
| 1047 |
+
arrival_time = flight.get("arrival_time", "No arrival time")
|
| 1048 |
+
airlines = flight.get("airlines", ["No airline"])
|
| 1049 |
+
|
| 1050 |
+
# Format the output for each flight
|
| 1051 |
+
response_text += f"Flight: {', '.join(airlines)}\n"
|
| 1052 |
+
response_text += f"Price: {price}\n"
|
| 1053 |
+
response_text += f"Duration: {duration}\n"
|
| 1054 |
+
response_text += f"Stops: {stops}\n"
|
| 1055 |
+
response_text += f"Departure: {departure_time}\n"
|
| 1056 |
+
response_text += f"Arrival: {arrival_time}\n"
|
| 1057 |
+
response_text += "-" * 50 + "\n"
|
| 1058 |
+
|
| 1059 |
+
return response_text
|
| 1060 |
|
| 1061 |
|
| 1062 |
|