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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""T S M.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1aa7j80PEKtklLchunk-SKWhzhwCj-PMr
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# ==============================
|
| 11 |
+
# INSTALL DEPENDENCIES
|
| 12 |
+
# ==============================
|
| 13 |
+
!pip install -q openai gradio pandas
|
| 14 |
+
|
| 15 |
+
# ==============================
|
| 16 |
+
# IMPORT LIBRARIES
|
| 17 |
+
# ==============================
|
| 18 |
+
from openai import OpenAI
|
| 19 |
+
import os
|
| 20 |
+
import gradio as gr
|
| 21 |
+
import pandas as pd
|
| 22 |
+
from datetime import datetime
|
| 23 |
+
|
| 24 |
+
# ==============================
|
| 25 |
+
# ADD YOUR GROQ API KEY HERE
|
| 26 |
+
# ==============================
|
| 27 |
+
os.environ["GROQ_API_KEY"] = "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"
|
| 28 |
+
|
| 29 |
+
# ==============================
|
| 30 |
+
# SETUP GROQ CLIENT
|
| 31 |
+
# ==============================
|
| 32 |
+
client = OpenAI(
|
| 33 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 34 |
+
base_url="https://api.groq.com/openai/v1",
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# ==============================
|
| 38 |
+
# GLOBAL STORAGE
|
| 39 |
+
# ==============================
|
| 40 |
+
users = {} # {username: password}
|
| 41 |
+
bookings = [] # list of booking dicts
|
| 42 |
+
notifications = [] # list of messages to users
|
| 43 |
+
ADMIN_CREDENTIALS = {"admin": "admin123"} # default admin
|
| 44 |
+
|
| 45 |
+
# ==============================
|
| 46 |
+
# SYSTEM PROMPT (AI TRAVEL ASSISTANT)
|
| 47 |
+
# ==============================
|
| 48 |
+
system_prompt = """
|
| 49 |
+
You are TravelGenZ AI, a smart travel assistant.
|
| 50 |
+
You give:
|
| 51 |
+
1. Distance between departure and destination
|
| 52 |
+
2. Airplane vs Bus comparison (time, cost, comfort)
|
| 53 |
+
3. Popular attractions & best hotels
|
| 54 |
+
4. Estimated cost & travel tips
|
| 55 |
+
5. Friendly, GenZ tone with emojis
|
| 56 |
+
6. Keep structured output
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
# ==============================
|
| 60 |
+
# USER FUNCTIONS
|
| 61 |
+
# ==============================
|
| 62 |
+
def register_user(name, password):
|
| 63 |
+
if name in users:
|
| 64 |
+
return "β User already exists"
|
| 65 |
+
users[name] = password
|
| 66 |
+
return f"β
Registered successfully! Welcome, {name}"
|
| 67 |
+
|
| 68 |
+
def login_user(name, password):
|
| 69 |
+
if name not in users:
|
| 70 |
+
return "β User not found. Please register."
|
| 71 |
+
if users[name] != password:
|
| 72 |
+
return "β Wrong password."
|
| 73 |
+
return f"β
Logged in successfully! Welcome back, {name}"
|
| 74 |
+
|
| 75 |
+
# Travel Chat AI
|
| 76 |
+
def travel_chat_ai(departure, destination, travelers, mode, date, name):
|
| 77 |
+
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."
|
| 78 |
+
response = client.responses.create(
|
| 79 |
+
model="openai/gpt-oss-20b",
|
| 80 |
+
input=prompt
|
| 81 |
+
)
|
| 82 |
+
return response.output_text
|
| 83 |
+
|
| 84 |
+
# Make booking
|
| 85 |
+
def make_booking(name, departure, destination, travelers, mode, date, mobile):
|
| 86 |
+
booking_id = len(bookings)+1
|
| 87 |
+
booking = {
|
| 88 |
+
"Booking ID": booking_id,
|
| 89 |
+
"Name": name,
|
| 90 |
+
"Mobile": mobile,
|
| 91 |
+
"Departure": departure,
|
| 92 |
+
"Destination": destination,
|
| 93 |
+
"Travelers": travelers,
|
| 94 |
+
"Mode": mode,
|
| 95 |
+
"Date": date,
|
| 96 |
+
"Status": "Pending"
|
| 97 |
+
}
|
| 98 |
+
bookings.append(booking)
|
| 99 |
+
return f"β
Booking submitted! Your Booking ID is {booking_id}. Admin will review soon."
|
| 100 |
+
|
| 101 |
+
# Admin functions
|
| 102 |
+
def admin_login(name, password):
|
| 103 |
+
if name not in ADMIN_CREDENTIALS or ADMIN_CREDENTIALS[name] != password:
|
| 104 |
+
return "β Wrong Admin credentials"
|
| 105 |
+
return "β
Admin login successful"
|
| 106 |
+
|
| 107 |
+
def view_bookings(admin_name, admin_password):
|
| 108 |
+
if admin_name not in ADMIN_CREDENTIALS or ADMIN_CREDENTIALS[admin_name] != admin_password:
|
| 109 |
+
return "β Wrong Admin credentials"
|
| 110 |
+
if not bookings:
|
| 111 |
+
return "No bookings yet."
|
| 112 |
+
return pd.DataFrame(bookings)
|
| 113 |
+
|
| 114 |
+
def process_booking(admin_name, admin_password, booking_id, action):
|
| 115 |
+
if admin_name not in ADMIN_CREDENTIALS or ADMIN_CREDENTIALS[admin_name] != admin_password:
|
| 116 |
+
return "β Wrong Admin credentials"
|
| 117 |
+
global bookings
|
| 118 |
+
for b in bookings:
|
| 119 |
+
if b["Booking ID"] == int(booking_id):
|
| 120 |
+
if action == "Accept":
|
| 121 |
+
b["Status"] = "Accepted"
|
| 122 |
+
notifications.append(f"β
Your booking {booking_id} has been accepted by admin!")
|
| 123 |
+
return f"Booking {booking_id} accepted"
|
| 124 |
+
elif action == "Reject":
|
| 125 |
+
b["Status"] = "Rejected"
|
| 126 |
+
notifications.append(f"β Your booking {booking_id} has been rejected by admin.")
|
| 127 |
+
return f"Booking {booking_id} rejected"
|
| 128 |
+
return "Booking ID not found"
|
| 129 |
+
|
| 130 |
+
def get_notifications():
|
| 131 |
+
return "\n".join(notifications) if notifications else "No new messages"
|
| 132 |
+
|
| 133 |
+
# ==============================
|
| 134 |
+
# GRADIO UI
|
| 135 |
+
# ==============================
|
| 136 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="TravelGenZ AI") as app:
|
| 137 |
+
|
| 138 |
+
gr.Markdown("# πβ TravelGenZ AI Booking System")
|
| 139 |
+
gr.Markdown("### Professional travel booking with AI guidance, hotels & attractions π")
|
| 140 |
+
|
| 141 |
+
with gr.Tab("π User Login/Register"):
|
| 142 |
+
with gr.Row():
|
| 143 |
+
reg_name = gr.Textbox(label="Name")
|
| 144 |
+
reg_pass = gr.Textbox(label="Password", type="password")
|
| 145 |
+
reg_btn = gr.Button("Register")
|
| 146 |
+
reg_out = gr.Textbox()
|
| 147 |
+
reg_btn.click(register_user, [reg_name, reg_pass], reg_out)
|
| 148 |
+
|
| 149 |
+
with gr.Row():
|
| 150 |
+
login_name = gr.Textbox(label="Name")
|
| 151 |
+
login_pass = gr.Textbox(label="Password", type="password")
|
| 152 |
+
login_btn = gr.Button("Login")
|
| 153 |
+
login_out = gr.Textbox()
|
| 154 |
+
login_btn.click(login_user, [login_name, login_pass], login_out)
|
| 155 |
+
|
| 156 |
+
with gr.Tab("π¬ Travel Assistant"):
|
| 157 |
+
dep_city = gr.Textbox(label="Departure City")
|
| 158 |
+
dest_city = gr.Textbox(label="Destination City")
|
| 159 |
+
travelers = gr.Number(label="Number of Travelers")
|
| 160 |
+
travel_mode = gr.Radio(["Airplane", "Bus"], label="Travel Mode")
|
| 161 |
+
travel_date = gr.Textbox(label="Travel Date (YYYY-MM-DD)")
|
| 162 |
+
user_name = gr.Textbox(label="Your Name")
|
| 163 |
+
mobile = gr.Textbox(label="Mobile Number")
|
| 164 |
+
|
| 165 |
+
chat_btn = gr.Button("Get AI Travel Info & Book")
|
| 166 |
+
chat_out = gr.Textbox()
|
| 167 |
+
|
| 168 |
+
chat_btn.click(
|
| 169 |
+
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),
|
| 170 |
+
[dep_city, dest_city, travelers, travel_mode, travel_date, user_name, mobile],
|
| 171 |
+
chat_out
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
with gr.Tab("π¨ User Notifications"):
|
| 175 |
+
notif_btn = gr.Button("Check Notifications")
|
| 176 |
+
notif_out = gr.Textbox()
|
| 177 |
+
notif_btn.click(get_notifications, [], notif_out)
|
| 178 |
+
|
| 179 |
+
with gr.Tab("π¨βπΌ Admin Panel"):
|
| 180 |
+
admin_name = gr.Textbox(label="Admin Name")
|
| 181 |
+
admin_pass = gr.Textbox(label="Password", type="password")
|
| 182 |
+
admin_login_btn = gr.Button("Login")
|
| 183 |
+
admin_login_out = gr.Textbox()
|
| 184 |
+
admin_login_btn.click(admin_login, [admin_name, admin_pass], admin_login_out)
|
| 185 |
+
|
| 186 |
+
view_btn = gr.Button("View Bookings")
|
| 187 |
+
bookings_out = gr.Dataframe()
|
| 188 |
+
view_btn.click(view_bookings, [admin_name, admin_pass], bookings_out)
|
| 189 |
+
|
| 190 |
+
booking_id = gr.Number(label="Booking ID")
|
| 191 |
+
action = gr.Radio(["Accept", "Reject"], label="Action")
|
| 192 |
+
process_btn = gr.Button("Process Booking")
|
| 193 |
+
process_out = gr.Textbox()
|
| 194 |
+
process_btn.click(process_booking, [admin_name, admin_pass, booking_id, action], process_out)
|
| 195 |
+
|
| 196 |
+
app.launch(share=True)
|
| 197 |
+
|
| 198 |
+
# ==============================
|
| 199 |
+
# INSTALL DEPENDENCIES
|
| 200 |
+
# ==============================
|
| 201 |
+
!pip install -q openai gradio pandas
|
| 202 |
+
|
| 203 |
+
# ==============================
|
| 204 |
+
# IMPORT LIBRARIES
|
| 205 |
+
# ==============================
|
| 206 |
+
from openai import OpenAI
|
| 207 |
+
import os
|
| 208 |
+
import gradio as gr
|
| 209 |
+
import pandas as pd
|
| 210 |
+
from datetime import datetime
|
| 211 |
+
|
| 212 |
+
# ==============================
|
| 213 |
+
# SET YOUR GROQ KEY HERE
|
| 214 |
+
# ==============================
|
| 215 |
+
os.environ["GROQ_API_KEY"] = "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"
|
| 216 |
+
|
| 217 |
+
# ==============================
|
| 218 |
+
# GROQ CLIENT
|
| 219 |
+
# ==============================
|
| 220 |
+
client = OpenAI(
|
| 221 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 222 |
+
base_url="https://api.groq.com/openai/v1",
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
# ==============================
|
| 226 |
+
# GLOBAL STORAGE
|
| 227 |
+
# ==============================
|
| 228 |
+
users = {} # username -> password
|
| 229 |
+
bookings = [] # all bookings
|
| 230 |
+
notifications = {} # username -> messages
|
| 231 |
+
ADMIN_USERNAME = "admin"
|
| 232 |
+
ADMIN_PASSWORD = "admin123"
|
| 233 |
+
|
| 234 |
+
# ==============================
|
| 235 |
+
# HELPER FUNCTIONS
|
| 236 |
+
# ==============================
|
| 237 |
+
def ai_travel_guide(departure, destination, travelers, mode):
|
| 238 |
+
"""Get AI-guided info about destination, hotels, attractions, distance & estimated cost"""
|
| 239 |
+
prompt = f"""
|
| 240 |
+
You are a professional travel guide.
|
| 241 |
+
A user wants to travel from {departure} to {destination}.
|
| 242 |
+
Travelers: {travelers}, Mode: {mode}.
|
| 243 |
+
Provide:
|
| 244 |
+
1. Distance in km
|
| 245 |
+
2. Estimated travel time
|
| 246 |
+
3. Estimated cost (simulate realistic)
|
| 247 |
+
4. Best hotels (top 3)
|
| 248 |
+
5. Popular attractions & museums
|
| 249 |
+
Format it with sections and emojis.
|
| 250 |
+
"""
|
| 251 |
+
response = client.responses.create(
|
| 252 |
+
model="openai/gpt-oss-20b",
|
| 253 |
+
input=prompt
|
| 254 |
+
)
|
| 255 |
+
return response.output_text
|
| 256 |
+
|
| 257 |
+
def register_user(username, password):
|
| 258 |
+
if username in users:
|
| 259 |
+
return "β Username already exists."
|
| 260 |
+
users[username] = password
|
| 261 |
+
notifications[username] = []
|
| 262 |
+
return "β
Registration successful! Please login."
|
| 263 |
+
|
| 264 |
+
def login_user(username, password):
|
| 265 |
+
if username not in users:
|
| 266 |
+
return None, "β User not found. Please register."
|
| 267 |
+
if users[username] != password:
|
| 268 |
+
return None, "β Incorrect password."
|
| 269 |
+
return username, f"β
Welcome {username}! Ready to plan your travel journey βοΈπ"
|
| 270 |
+
|
| 271 |
+
def make_booking(username, departure, destination, travelers, mode, mobile):
|
| 272 |
+
booking_id = len(bookings) + 1
|
| 273 |
+
time_now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 274 |
+
booking = {
|
| 275 |
+
"Booking ID": booking_id,
|
| 276 |
+
"Username": username,
|
| 277 |
+
"Departure": departure,
|
| 278 |
+
"Destination": destination,
|
| 279 |
+
"Travelers": travelers,
|
| 280 |
+
"Mode": mode,
|
| 281 |
+
"Mobile": mobile,
|
| 282 |
+
"Status": "Pending",
|
| 283 |
+
"Time": time_now
|
| 284 |
+
}
|
| 285 |
+
bookings.append(booking)
|
| 286 |
+
return f"β
Booking submitted! Your booking ID is {booking_id}. Admin will review it shortly."
|
| 287 |
+
|
| 288 |
+
def admin_login(username, password):
|
| 289 |
+
if username != ADMIN_USERNAME or password != ADMIN_PASSWORD:
|
| 290 |
+
return None, "β Incorrect admin credentials."
|
| 291 |
+
return True, f"β
Welcome Admin {username}!"
|
| 292 |
+
|
| 293 |
+
def admin_accept_reject(booking_id, action):
|
| 294 |
+
global bookings
|
| 295 |
+
for b in bookings:
|
| 296 |
+
if b["Booking ID"] == int(booking_id):
|
| 297 |
+
if action == "Accept":
|
| 298 |
+
b["Status"] = "Accepted"
|
| 299 |
+
# Notify user
|
| 300 |
+
msg = f"""
|
| 301 |
+
πβ¨ Your Booking is Confirmed! β¨π
|
| 302 |
+
Hello {b['Username']}! π
|
| 303 |
+
Great news! Your travel plans with T S M from {b['Departure']} to {b['Destination']} are now confirmed! π«π¨π
|
| 304 |
+
Travelers: {b['Travelers']}, Mode: {b['Mode']}
|
| 305 |
+
Your flight & hotel details are all set πβοΈπ¨
|
| 306 |
+
Safe travels & happy adventures! πππ§³
|
| 307 |
+
"""
|
| 308 |
+
notifications[b["Username"]].append(msg)
|
| 309 |
+
return f"β
Booking {booking_id} accepted & notification sent!"
|
| 310 |
+
else:
|
| 311 |
+
b["Status"] = "Rejected"
|
| 312 |
+
notifications[b["Username"]].append(f"β Booking {booking_id} has been rejected by admin.")
|
| 313 |
+
return f"β
Booking {booking_id} rejected."
|
| 314 |
+
return f"β Booking ID {booking_id} not found."
|
| 315 |
+
|
| 316 |
+
# ==============================
|
| 317 |
+
# GRADIO UI
|
| 318 |
+
# ==============================
|
| 319 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="TSM Travel Agency") as app:
|
| 320 |
+
gr.Markdown("# π TSM Travel Agency AI π")
|
| 321 |
+
gr.Markdown("Welcome to TSM Travel Agency! Plan your journey, explore destinations & book hassle-free βοΈπ¨π")
|
| 322 |
+
|
| 323 |
+
with gr.Tab("π User Portal"):
|
| 324 |
+
# Registration/Login
|
| 325 |
+
reg_username = gr.Textbox(label="Username")
|
| 326 |
+
reg_password = gr.Textbox(label="Password", type="password")
|
| 327 |
+
reg_btn = gr.Button("Register")
|
| 328 |
+
login_btn = gr.Button("Login")
|
| 329 |
+
login_msg = gr.Textbox()
|
| 330 |
+
current_user = gr.State()
|
| 331 |
+
|
| 332 |
+
reg_btn.click(register_user, [reg_username, reg_password], login_msg)
|
| 333 |
+
login_btn.click(login_user, [reg_username, reg_password], [current_user, login_msg])
|
| 334 |
+
|
| 335 |
+
# Travel Planning (after login)
|
| 336 |
+
dep_city = gr.Textbox(label="Departure City")
|
| 337 |
+
dest_city = gr.Textbox(label="Destination City")
|
| 338 |
+
travelers = gr.Number(label="Number of Travelers")
|
| 339 |
+
travel_mode = gr.Radio(["Airplane", "Bus"], label="Travel Mode")
|
| 340 |
+
mobile = gr.Textbox(label="Mobile Number")
|
| 341 |
+
guide_btn = gr.Button("Get Travel Guide & Book")
|
| 342 |
+
guide_output = gr.Textbox()
|
| 343 |
+
booking_output = gr.Textbox()
|
| 344 |
+
|
| 345 |
+
def guide_and_book(dep, dest, trav, mode, username, mobile):
|
| 346 |
+
if not username:
|
| 347 |
+
return "β Please login first.", ""
|
| 348 |
+
guide_info = ai_travel_guide(dep, dest, trav, mode)
|
| 349 |
+
book_msg = make_booking(username, dep, dest, trav, mode, mobile)
|
| 350 |
+
return guide_info, book_msg
|
| 351 |
+
|
| 352 |
+
guide_btn.click(guide_and_book, [dep_city, dest_city, travelers, travel_mode, current_user, mobile], [guide_output, booking_output])
|
| 353 |
+
|
| 354 |
+
with gr.Tab("π¨βπΌ Admin Panel"):
|
| 355 |
+
admin_user = gr.Textbox(label="Admin Username")
|
| 356 |
+
admin_pass = gr.Textbox(label="Admin Password", type="password")
|
| 357 |
+
admin_login_btn = gr.Button("Login as Admin")
|
| 358 |
+
admin_login_msg = gr.Textbox()
|
| 359 |
+
admin_state = gr.State()
|
| 360 |
+
|
| 361 |
+
view_bookings_btn = gr.Button("View All Bookings")
|
| 362 |
+
admin_bookings_output = gr.Dataframe()
|
| 363 |
+
booking_id_input = gr.Number(label="Booking ID")
|
| 364 |
+
accept_btn = gr.Button("Accept Booking")
|
| 365 |
+
reject_btn = gr.Button("Reject Booking")
|
| 366 |
+
admin_action_output = gr.Textbox()
|
| 367 |
+
|
| 368 |
+
admin_login_btn.click(admin_login, [admin_user, admin_pass], [admin_state, admin_login_msg])
|
| 369 |
+
view_bookings_btn.click(lambda: pd.DataFrame(bookings), [], admin_bookings_output)
|
| 370 |
+
accept_btn.click(admin_accept_reject, [booking_id_input, gr.State("Accept")], admin_action_output)
|
| 371 |
+
reject_btn.click(admin_accept_reject, [booking_id_input, gr.State("Reject")], admin_action_output)
|
| 372 |
+
|
| 373 |
+
with gr.Tab("π¬ Notifications"):
|
| 374 |
+
notif_user = gr.Textbox(label="Enter your username to see notifications")
|
| 375 |
+
notif_output = gr.Textbox()
|
| 376 |
+
def show_notifications(u):
|
| 377 |
+
msgs = notifications.get(u, [])
|
| 378 |
+
if not msgs:
|
| 379 |
+
return "No notifications yet."
|
| 380 |
+
return "\n\n".join(msgs)
|
| 381 |
+
gr.Button("Show Notifications").click(show_notifications, notif_user, notif_output)
|
| 382 |
+
|
| 383 |
+
app.launch(share=True)
|