File size: 1,657 Bytes
376bc29 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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()
|