| |
| """T S M.ipynb |
| |
| Automatically generated by Colab. |
| |
| Original file is located at |
| https://colab.research.google.com/drive/1aa7j80PEKtklLchunk-SKWhzhwCj-PMr |
| """ |
|
|
| |
| |
| |
| !pip install -q openai gradio pandas |
|
|
| |
| |
| |
| from openai import OpenAI |
| import os |
| import gradio as gr |
| import pandas as pd |
| from datetime import datetime |
|
|
| |
| |
| |
| os.environ["GROQ_API_KEY"] = "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" |
|
|
| |
| |
| |
| client = OpenAI( |
| api_key=os.environ.get("GROQ_API_KEY"), |
| base_url="https://api.groq.com/openai/v1", |
| ) |
|
|
| |
| |
| |
| users = {} |
| bookings = [] |
| notifications = [] |
| ADMIN_CREDENTIALS = {"admin": "admin123"} |
|
|
| |
| |
| |
| system_prompt = """ |
| You are TravelGenZ AI, a smart travel assistant. |
| You give: |
| 1. Distance between departure and destination |
| 2. Airplane vs Bus comparison (time, cost, comfort) |
| 3. Popular attractions & best hotels |
| 4. Estimated cost & travel tips |
| 5. Friendly, GenZ tone with emojis |
| 6. Keep structured output |
| """ |
|
|
| |
| |
| |
| def register_user(name, password): |
| if name in users: |
| return "β User already exists" |
| users[name] = password |
| return f"β
Registered successfully! Welcome, {name}" |
|
|
| def login_user(name, password): |
| if name not in users: |
| return "β User not found. Please register." |
| if users[name] != password: |
| return "β Wrong password." |
| return f"β
Logged in successfully! Welcome back, {name}" |
|
|
| |
| def travel_chat_ai(departure, destination, travelers, mode, date, name): |
| prompt = f"{system_prompt}\nUser is {name}. Traveling from {departure} to {destination} on {date} for {travelers} people by {mode}. Provide distance, travel comparison, popular places and hotels, estimated cost." |
| response = client.responses.create( |
| model="openai/gpt-oss-20b", |
| input=prompt |
| ) |
| return response.output_text |
|
|
| |
| def make_booking(name, departure, destination, travelers, mode, date, mobile): |
| booking_id = len(bookings)+1 |
| booking = { |
| "Booking ID": booking_id, |
| "Name": name, |
| "Mobile": mobile, |
| "Departure": departure, |
| "Destination": destination, |
| "Travelers": travelers, |
| "Mode": mode, |
| "Date": date, |
| "Status": "Pending" |
| } |
| bookings.append(booking) |
| return f"β
Booking submitted! Your Booking ID is {booking_id}. Admin will review soon." |
|
|
| |
| def admin_login(name, password): |
| if name not in ADMIN_CREDENTIALS or ADMIN_CREDENTIALS[name] != password: |
| return "β Wrong Admin credentials" |
| return "β
Admin login successful" |
|
|
| def view_bookings(admin_name, admin_password): |
| if admin_name not in ADMIN_CREDENTIALS or ADMIN_CREDENTIALS[admin_name] != admin_password: |
| return "β Wrong Admin credentials" |
| if not bookings: |
| return "No bookings yet." |
| return pd.DataFrame(bookings) |
|
|
| def process_booking(admin_name, admin_password, booking_id, action): |
| if admin_name not in ADMIN_CREDENTIALS or ADMIN_CREDENTIALS[admin_name] != admin_password: |
| return "β Wrong Admin credentials" |
| global bookings |
| for b in bookings: |
| if b["Booking ID"] == int(booking_id): |
| if action == "Accept": |
| b["Status"] = "Accepted" |
| notifications.append(f"β
Your booking {booking_id} has been accepted by admin!") |
| return f"Booking {booking_id} accepted" |
| elif action == "Reject": |
| b["Status"] = "Rejected" |
| notifications.append(f"β Your booking {booking_id} has been rejected by admin.") |
| return f"Booking {booking_id} rejected" |
| return "Booking ID not found" |
|
|
| def get_notifications(): |
| return "\n".join(notifications) if notifications else "No new messages" |
|
|
| |
| |
| |
| with gr.Blocks(theme=gr.themes.Soft(), title="TravelGenZ AI") as app: |
|
|
| gr.Markdown("# πβ TravelGenZ AI Booking System") |
| gr.Markdown("### Professional travel booking with AI guidance, hotels & attractions π") |
|
|
| with gr.Tab("π User Login/Register"): |
| with gr.Row(): |
| reg_name = gr.Textbox(label="Name") |
| reg_pass = gr.Textbox(label="Password", type="password") |
| reg_btn = gr.Button("Register") |
| reg_out = gr.Textbox() |
| reg_btn.click(register_user, [reg_name, reg_pass], reg_out) |
|
|
| with gr.Row(): |
| login_name = gr.Textbox(label="Name") |
| login_pass = gr.Textbox(label="Password", type="password") |
| login_btn = gr.Button("Login") |
| login_out = gr.Textbox() |
| login_btn.click(login_user, [login_name, login_pass], login_out) |
|
|
| with gr.Tab("π¬ Travel Assistant"): |
| dep_city = gr.Textbox(label="Departure City") |
| dest_city = gr.Textbox(label="Destination City") |
| travelers = gr.Number(label="Number of Travelers") |
| travel_mode = gr.Radio(["Airplane", "Bus"], label="Travel Mode") |
| travel_date = gr.Textbox(label="Travel Date (YYYY-MM-DD)") |
| user_name = gr.Textbox(label="Your Name") |
| mobile = gr.Textbox(label="Mobile Number") |
|
|
| chat_btn = gr.Button("Get AI Travel Info & Book") |
| chat_out = gr.Textbox() |
|
|
| chat_btn.click( |
| lambda d, dst, t, m, date, n, mob: travel_chat_ai(d, dst, t, m, date, n) + "\n\n" + make_booking(n, d, dst, t, m, date, mob), |
| [dep_city, dest_city, travelers, travel_mode, travel_date, user_name, mobile], |
| chat_out |
| ) |
|
|
| with gr.Tab("π¨ User Notifications"): |
| notif_btn = gr.Button("Check Notifications") |
| notif_out = gr.Textbox() |
| notif_btn.click(get_notifications, [], notif_out) |
|
|
| with gr.Tab("π¨βπΌ Admin Panel"): |
| admin_name = gr.Textbox(label="Admin Name") |
| admin_pass = gr.Textbox(label="Password", type="password") |
| admin_login_btn = gr.Button("Login") |
| admin_login_out = gr.Textbox() |
| admin_login_btn.click(admin_login, [admin_name, admin_pass], admin_login_out) |
|
|
| view_btn = gr.Button("View Bookings") |
| bookings_out = gr.Dataframe() |
| view_btn.click(view_bookings, [admin_name, admin_pass], bookings_out) |
|
|
| booking_id = gr.Number(label="Booking ID") |
| action = gr.Radio(["Accept", "Reject"], label="Action") |
| process_btn = gr.Button("Process Booking") |
| process_out = gr.Textbox() |
| process_btn.click(process_booking, [admin_name, admin_pass, booking_id, action], process_out) |
|
|
| app.launch(share=True) |
|
|
| |
| |
| |
| !pip install -q openai gradio pandas |
|
|
| |
| |
| |
| from openai import OpenAI |
| import os |
| import gradio as gr |
| import pandas as pd |
| from datetime import datetime |
|
|
| |
| |
| |
| os.environ["GROQ_API_KEY"] = "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" |
|
|
| |
| |
| |
| client = OpenAI( |
| api_key=os.environ.get("GROQ_API_KEY"), |
| base_url="https://api.groq.com/openai/v1", |
| ) |
|
|
| |
| |
| |
| users = {} |
| bookings = [] |
| notifications = {} |
| ADMIN_USERNAME = "admin" |
| ADMIN_PASSWORD = "admin123" |
|
|
| |
| |
| |
| def ai_travel_guide(departure, destination, travelers, mode): |
| """Get AI-guided info about destination, hotels, attractions, distance & estimated cost""" |
| prompt = f""" |
| You are a professional travel guide. |
| A user wants to travel from {departure} to {destination}. |
| Travelers: {travelers}, Mode: {mode}. |
| Provide: |
| 1. Distance in km |
| 2. Estimated travel time |
| 3. Estimated cost (simulate realistic) |
| 4. Best hotels (top 3) |
| 5. Popular attractions & museums |
| Format it with sections and emojis. |
| """ |
| response = client.responses.create( |
| model="openai/gpt-oss-20b", |
| input=prompt |
| ) |
| return response.output_text |
|
|
| def register_user(username, password): |
| if username in users: |
| return "β Username already exists." |
| users[username] = password |
| notifications[username] = [] |
| return "β
Registration successful! Please login." |
|
|
| def login_user(username, password): |
| if username not in users: |
| return None, "β User not found. Please register." |
| if users[username] != password: |
| return None, "β Incorrect password." |
| return username, f"β
Welcome {username}! Ready to plan your travel journey βοΈπ" |
|
|
| def make_booking(username, departure, destination, travelers, mode, mobile): |
| booking_id = len(bookings) + 1 |
| time_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| booking = { |
| "Booking ID": booking_id, |
| "Username": username, |
| "Departure": departure, |
| "Destination": destination, |
| "Travelers": travelers, |
| "Mode": mode, |
| "Mobile": mobile, |
| "Status": "Pending", |
| "Time": time_now |
| } |
| bookings.append(booking) |
| return f"β
Booking submitted! Your booking ID is {booking_id}. Admin will review it shortly." |
|
|
| def admin_login(username, password): |
| if username != ADMIN_USERNAME or password != ADMIN_PASSWORD: |
| return None, "β Incorrect admin credentials." |
| return True, f"β
Welcome Admin {username}!" |
|
|
| def admin_accept_reject(booking_id, action): |
| global bookings |
| for b in bookings: |
| if b["Booking ID"] == int(booking_id): |
| if action == "Accept": |
| b["Status"] = "Accepted" |
| |
| msg = f""" |
| πβ¨ Your Booking is Confirmed! β¨π |
| Hello {b['Username']}! π |
| Great news! Your travel plans with T S M from {b['Departure']} to {b['Destination']} are now confirmed! π«π¨π |
| Travelers: {b['Travelers']}, Mode: {b['Mode']} |
| Your flight & hotel details are all set πβοΈπ¨ |
| Safe travels & happy adventures! πππ§³ |
| """ |
| notifications[b["Username"]].append(msg) |
| return f"β
Booking {booking_id} accepted & notification sent!" |
| else: |
| b["Status"] = "Rejected" |
| notifications[b["Username"]].append(f"β Booking {booking_id} has been rejected by admin.") |
| return f"β
Booking {booking_id} rejected." |
| return f"β Booking ID {booking_id} not found." |
|
|
| |
| |
| |
| with gr.Blocks(theme=gr.themes.Soft(), title="TSM Travel Agency") as app: |
| gr.Markdown("# π TSM Travel Agency AI π") |
| gr.Markdown("Welcome to TSM Travel Agency! Plan your journey, explore destinations & book hassle-free βοΈπ¨π") |
|
|
| with gr.Tab("π User Portal"): |
| |
| reg_username = gr.Textbox(label="Username") |
| reg_password = gr.Textbox(label="Password", type="password") |
| reg_btn = gr.Button("Register") |
| login_btn = gr.Button("Login") |
| login_msg = gr.Textbox() |
| current_user = gr.State() |
|
|
| reg_btn.click(register_user, [reg_username, reg_password], login_msg) |
| login_btn.click(login_user, [reg_username, reg_password], [current_user, login_msg]) |
|
|
| |
| dep_city = gr.Textbox(label="Departure City") |
| dest_city = gr.Textbox(label="Destination City") |
| travelers = gr.Number(label="Number of Travelers") |
| travel_mode = gr.Radio(["Airplane", "Bus"], label="Travel Mode") |
| mobile = gr.Textbox(label="Mobile Number") |
| guide_btn = gr.Button("Get Travel Guide & Book") |
| guide_output = gr.Textbox() |
| booking_output = gr.Textbox() |
|
|
| def guide_and_book(dep, dest, trav, mode, username, mobile): |
| if not username: |
| return "β Please login first.", "" |
| guide_info = ai_travel_guide(dep, dest, trav, mode) |
| book_msg = make_booking(username, dep, dest, trav, mode, mobile) |
| return guide_info, book_msg |
|
|
| guide_btn.click(guide_and_book, [dep_city, dest_city, travelers, travel_mode, current_user, mobile], [guide_output, booking_output]) |
|
|
| with gr.Tab("π¨βπΌ Admin Panel"): |
| admin_user = gr.Textbox(label="Admin Username") |
| admin_pass = gr.Textbox(label="Admin Password", type="password") |
| admin_login_btn = gr.Button("Login as Admin") |
| admin_login_msg = gr.Textbox() |
| admin_state = gr.State() |
|
|
| view_bookings_btn = gr.Button("View All Bookings") |
| admin_bookings_output = gr.Dataframe() |
| booking_id_input = gr.Number(label="Booking ID") |
| accept_btn = gr.Button("Accept Booking") |
| reject_btn = gr.Button("Reject Booking") |
| admin_action_output = gr.Textbox() |
|
|
| admin_login_btn.click(admin_login, [admin_user, admin_pass], [admin_state, admin_login_msg]) |
| view_bookings_btn.click(lambda: pd.DataFrame(bookings), [], admin_bookings_output) |
| accept_btn.click(admin_accept_reject, [booking_id_input, gr.State("Accept")], admin_action_output) |
| reject_btn.click(admin_accept_reject, [booking_id_input, gr.State("Reject")], admin_action_output) |
|
|
| with gr.Tab("π¬ Notifications"): |
| notif_user = gr.Textbox(label="Enter your username to see notifications") |
| notif_output = gr.Textbox() |
| def show_notifications(u): |
| msgs = notifications.get(u, []) |
| if not msgs: |
| return "No notifications yet." |
| return "\n\n".join(msgs) |
| gr.Button("Show Notifications").click(show_notifications, notif_user, notif_output) |
|
|
| app.launch(share=True) |