|
import gradio as gr |
|
from llm_utils import process_natural_language_query |
|
from data import flights_db, users_db, bookings_db |
|
import uuid |
|
import datetime |
|
|
|
def search_flights(query): |
|
criteria = process_natural_language_query(query) |
|
results = [ |
|
f for f in flights_db |
|
if f['source'].lower() == criteria['source'].lower() |
|
and f['destination'].lower() == criteria['destination'].lower() |
|
and f['date'] == criteria['date'] |
|
] |
|
return results |
|
|
|
def book_flight(user_id, flight_id): |
|
user = next((u for u in users_db if u['id'] == user_id), None) |
|
flight = next((f for f in flights_db if f['id'] == flight_id), None) |
|
if not user or not flight: |
|
return "β User or flight not found." |
|
booking_id = str(uuid.uuid4()) |
|
bookings_db.append({ |
|
'id': booking_id, |
|
'user_id': user_id, |
|
'flight_id': flight_id, |
|
'timestamp': str(datetime.datetime.now()) |
|
}) |
|
return f"β
Booking confirmed! ID: {booking_id}" |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## βοΈ Secure Flight Booking System with LLM") |
|
|
|
with gr.Row(): |
|
query = gr.Textbox(label="Enter your flight query") |
|
search_btn = gr.Button("Search Flights") |
|
|
|
results = gr.JSON(label="Available Flights") |
|
|
|
with gr.Row(): |
|
user_id = gr.Textbox(label="User ID") |
|
flight_id = gr.Textbox(label="Flight ID") |
|
book_btn = gr.Button("Book Flight") |
|
|
|
booking_output = gr.Textbox(label="Booking Status") |
|
|
|
search_btn.click(fn=search_flights, inputs=query, outputs=results) |
|
book_btn.click(fn=book_flight, inputs=[user_id, flight_id], outputs=booking_output) |
|
|
|
demo.launch() |
|
|