Pradeepthi30 commited on
Commit
376bc29
·
verified ·
1 Parent(s): 1fc59e0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from llm_utils import process_natural_language_query
3
+ from data import flights_db, users_db, bookings_db
4
+ import uuid
5
+ import datetime
6
+
7
+ def search_flights(query):
8
+ criteria = process_natural_language_query(query)
9
+ results = [
10
+ f for f in flights_db
11
+ if f['source'].lower() == criteria['source'].lower()
12
+ and f['destination'].lower() == criteria['destination'].lower()
13
+ and f['date'] == criteria['date']
14
+ ]
15
+ return results
16
+
17
+ def book_flight(user_id, flight_id):
18
+ user = next((u for u in users_db if u['id'] == user_id), None)
19
+ flight = next((f for f in flights_db if f['id'] == flight_id), None)
20
+ if not user or not flight:
21
+ return "❌ User or flight not found."
22
+ booking_id = str(uuid.uuid4())
23
+ bookings_db.append({
24
+ 'id': booking_id,
25
+ 'user_id': user_id,
26
+ 'flight_id': flight_id,
27
+ 'timestamp': str(datetime.datetime.now())
28
+ })
29
+ return f"✅ Booking confirmed! ID: {booking_id}"
30
+
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("## ✈️ Secure Flight Booking System with LLM")
33
+
34
+ with gr.Row():
35
+ query = gr.Textbox(label="Enter your flight query")
36
+ search_btn = gr.Button("Search Flights")
37
+
38
+ results = gr.JSON(label="Available Flights")
39
+
40
+ with gr.Row():
41
+ user_id = gr.Textbox(label="User ID")
42
+ flight_id = gr.Textbox(label="Flight ID")
43
+ book_btn = gr.Button("Book Flight")
44
+
45
+ booking_output = gr.Textbox(label="Booking Status")
46
+
47
+ search_btn.click(fn=search_flights, inputs=query, outputs=results)
48
+ book_btn.click(fn=book_flight, inputs=[user_id, flight_id], outputs=booking_output)
49
+
50
+ demo.launch()