| import gradio as gr |
| import random |
| import time |
| from transformers import pipeline |
|
|
| def flight_booking(airline, departure, destination, date): |
| return f"Flight booked with {airline} from {departure} to {destination} on {date}. Confirmation: #{random.randint(10000, 99999)}" |
|
|
| def flight_status(flight_number): |
| status = random.choice(["On Time", "Delayed", "Cancelled", "Boarding"]) |
| return f"Flight {flight_number} status: {status}" |
|
|
| def baggage_policy(airline): |
| policies = { |
| "Airline A": "20kg checked baggage, 7kg carry-on.", |
| "Airline B": "25kg checked baggage, 10kg carry-on.", |
| "Airline C": "30kg checked baggage, 8kg carry-on." |
| } |
| return policies.get(airline, "Check airline website for baggage policy.") |
|
|
| def detect_threat(text): |
| threat_model = pipeline("text-classification", model="mrm8488/bert-mini-finetuned-age_news-classification") |
| prediction = threat_model(text) |
| return "Threat Detected! Authorities Notified." if "threat" in prediction[0]['label'].lower() else "No Threat Detected." |
|
|
| def plane_tracking(flight_number): |
| locations = ["Over Pacific Ocean", "Above London", "Near JFK Airport", "En Route to Dubai"] |
| return f"Flight {flight_number} is currently {random.choice(locations)}." |
|
|
| def cancel_flight(flight_number): |
| return f"Flight {flight_number} has been successfully cancelled. Refund processed in 5-7 business days." |
|
|
| def travel_assistance(country): |
| return f"Travel checklist for {country}: Passport, Visa, COVID restrictions, Currency Exchange." |
|
|
| def ai_chatbot(message): |
| return f"AI Assistant: {random.choice(['Let me help you with that!', 'Can you provide more details?', 'Sure, I can assist!'])}" |
|
|
| |
| demo = gr.Interface( |
| fn=lambda function, *args: globals()[function](*args), |
| inputs=[ |
| gr.Radio(["flight_booking", "flight_status", "baggage_policy", "detect_threat", "plane_tracking", "cancel_flight", "travel_assistance", "ai_chatbot"], label="Select Function"), |
| gr.Textbox(label="Input 1"), |
| gr.Textbox(label="Input 2"), |
| gr.Textbox(label="Input 3"), |
| gr.Textbox(label="Input 4"), |
| ], |
| outputs=gr.Textbox(label="Output"), |
| title="UpStairs Flight Services AI", |
| description="AI-Powered Flight Assistance & Security Monitoring" |
| ) |
|
|
| demo.launch() |