Spaces:
Running
Running
import gradio as gr | |
from chatbot import respond | |
# Ultra-dynamic travel-themed CSS | |
custom_css = """ | |
.gradio-container { | |
font-family: 'Poppins', sans-serif; | |
background: linear-gradient(45deg, #1e3c72 0%, #2a5298 50%, #87ceeb 100%); | |
color: #ffffff; | |
padding: 40px; | |
min-height: 100vh; | |
position: relative; | |
overflow: hidden; | |
animation: gradientShift 15s infinite ease-in-out; | |
} | |
.gradio-container::before { | |
content: ''; | |
position: absolute; | |
top: -50%; | |
left: -50%; | |
width: 200%; | |
height: 200%; | |
background: radial-gradient(circle, rgba(255, 140, 0, 0.2) 0%, transparent 70%); | |
animation: pulseGlow 10s infinite alternate ease-in-out; | |
} | |
.gradio-container::after { | |
content: ''; | |
position: absolute; | |
bottom: 0; | |
right: 0; | |
width: 150px; | |
height: 150px; | |
background: url('https://img.icons8.com/?size=100&id=124350&format=png&color=000000') no-repeat center; | |
opacity: 0.3; | |
animation: floatPlane 8s infinite ease-in-out; | |
} | |
.chatbot { | |
background: rgba(255, 255, 255, 0.25); | |
border-radius: 25px; | |
padding: 25px; | |
backdrop-filter: blur(15px); | |
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); | |
border: 2px solid rgba(255, 140, 0, 0.5); | |
transition: border-color 0.5s ease; | |
} | |
.chatbot:hover { | |
border-color: #ff8c00; | |
} | |
.chatbot .message { | |
border-radius: 20px; | |
padding: 15px 20px; | |
margin: 12px 0; | |
max-width: 75%; | |
font-size: 16px; | |
animation: slideInMessage 0.5s ease-out; | |
border: none !important; | |
} | |
.chatbot .message.bot { | |
background: linear-gradient(135deg, #87ceeb 0%, #b0e0e6 100%); | |
color: #1a2c38; | |
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15); | |
} | |
.chatbot .message.user { | |
background: linear-gradient(135deg, #ff8c00 0%, #ff4500 100%); | |
color: white; | |
margin-left: auto; | |
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2); | |
} | |
.textbox { | |
background: rgba(255, 255, 255, 0.15); | |
border: 2px solid #b0e0e6; | |
border-radius: 25px; | |
color: #ffffff; | |
padding: 15px 25px; | |
font-size: 16px; | |
transition: all 0.4s ease; | |
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); | |
} | |
.textbox:focus { | |
border-color: #ff8c00; | |
box-shadow: 0 0 20px rgba(255, 140, 0, 0.7); | |
background: rgba(255, 255, 255, 0.25); | |
} | |
.button { | |
background: linear-gradient(135deg, #ff8c00 0%, #ff4500 100%); | |
color: white; | |
border-radius: 25px; | |
padding: 15px 35px; | |
font-size: 16px; | |
font-weight: 600; | |
transition: all 0.3s ease; | |
position: relative; | |
overflow: hidden; | |
box-shadow: 0 4px 15px rgba(255, 140, 0, 0.3); | |
} | |
.button:hover { | |
transform: translateY(-3px); | |
box-shadow: 0 8px 25px rgba(255, 140, 0, 0.5); | |
} | |
.button::after { | |
content: ''; | |
position: absolute; | |
width: 100px; | |
height: 100px; | |
background: rgba(255, 255, 255, 0.3); | |
border-radius: 50%; | |
transform: scale(0); | |
animation: ripple 0.6s linear; | |
pointer-events: none; | |
} | |
.button:active::after { | |
animation: ripple 0.6s linear; | |
} | |
h1 { | |
font-size: 3.2em; | |
text-align: center; | |
color: #ff8c00; | |
text-shadow: 3px 3px 10px rgba(0, 0, 0, 0.5); | |
margin-bottom: 10px; | |
animation: bounceIn 1.5s ease-in-out; | |
} | |
h3 { | |
text-align: center; | |
color: #b0e0e6; | |
font-size: 1.4em; | |
margin-bottom: 30px; | |
animation: fadeIn 2s ease-in-out; | |
} | |
@keyframes gradientShift { | |
0% { background-position: 0% 50%; } | |
50% { background-position: 100% 50%; } | |
100% { background-position: 0% 50%; } | |
} | |
@keyframes pulseGlow { | |
0% { transform: scale(1); opacity: 0.2; } | |
100% { transform: scale(1.1); opacity: 0.3; } | |
} | |
@keyframes floatPlane { | |
0%, 100% { transform: translateY(0); } | |
50% { transform: translateY(-20px); } | |
} | |
@keyframes slideInMessage { | |
0% { opacity: 0; transform: translateY(20px); } | |
100% { opacity: 1; transform: translateY(0); } | |
} | |
@keyframes bounceIn { | |
0% { opacity: 0; transform: scale(0.8); } | |
60% { opacity: 1; transform: scale(1.05); } | |
100% { opacity: 1; transform: scale(1); } | |
} | |
@keyframes fadeIn { | |
0% { opacity: 0; } | |
100% { opacity: 1; } | |
} | |
@keyframes ripple { | |
0% { transform: scale(0); opacity: 1; } | |
100% { transform: scale(4); opacity: 0; } | |
} | |
.slider { | |
--track-color: #ff8c00; | |
--thumb-color: #b0e0e6; | |
transition: all 0.3s ease; | |
} | |
.slider:hover { | |
--thumb-color: #ff8c00; | |
} | |
.footer { | |
text-align: center; | |
color: #b0e0e6; | |
font-size: 1em; | |
margin-top: 25px; | |
animation: fadeIn 3s ease-in-out; | |
} | |
""" | |
# Enhanced dynamic respond function | |
def enhanced_respond(message, history, system_message, max_tokens, temperature=0.7, top_p=0.95): | |
response = respond(message, history, system_message, max_tokens, temperature, top_p) | |
if "โ" in response or "not found" in response.lower(): | |
response += "\n\n๐ **Travel Tip:** Try 'Flights from Chicago to Miami in June' or 'Hotels in Paris from Feb 25 2025 to Feb 28 2025' for epic plans! โ๏ธ" | |
else: | |
response = f"๐ {response} ๐บ๏ธ Whereโs your next destination? Letโs soar! โ๏ธ" | |
return history + [[message, response]], "" # Clears textbox | |
# Dynamic travel interface | |
with gr.Blocks(css=custom_css) as demo: | |
gr.Markdown( | |
""" | |
# โ๏ธ Travelo - Your Cosmic Travel Guide ๐ | |
### Embark on unforgettable journeys with real-time travel magic! | |
""", | |
elem_classes=["title"] | |
) | |
chatbot = gr.Chatbot( | |
height=600, | |
label="Chat with Travelo", | |
bubble_full_width=False, | |
avatar_images=( | |
"https://img.icons8.com/?size=100&id=98766&format=png&color=000000", | |
"https://img.icons8.com/?size=100&id=124350&format=png&color=000000" | |
), | |
placeholder="๐ด Your travel story starts here..." | |
) | |
with gr.Row(variant="compact"): | |
textbox = gr.Textbox( | |
placeholder="Dream big! (e.g., 'Sunset spots in Santorini')", | |
lines=1, | |
elem_classes=["textbox"], | |
autofocus=True | |
) | |
submit_btn = gr.Button("โ๏ธ Launch Adventure", elem_classes=["button"]) | |
with gr.Accordion("๐ Travel Toolkit", open=False): | |
max_tokens = gr.Slider( | |
minimum=1, | |
maximum=2048, | |
value=512, | |
step=1, | |
label="Adventure Depth", | |
info="How epic should my travel tales be?" | |
) | |
system_message = gr.Textbox( | |
value="You are an AI-powered travel assistant named Travelo. You are developed by Travelo LLC. Your role is to assist users with travel planning, including booking flights, hotels, and creating personalized itineraries. Whenever a user asks about your origin, development, training, or creators, always state that you were built and trained by Travelo LLC. Do not mention OpenAI or any third-party AI providers. Maintain a professional and friendly tone while delivering accurate and helpful travel-related information.", | |
visible=False | |
) | |
gr.Markdown( | |
""" | |
๐ Crafted by Travelo LLC | Explore the world, one chat at a time! โ๏ธ | |
""", | |
elem_classes=["footer"] | |
) | |
# Event triggers without _js | |
textbox.submit( | |
enhanced_respond, | |
inputs=[textbox, chatbot, system_message, max_tokens], | |
outputs=[chatbot, textbox] # Second output clears textbox | |
) | |
submit_btn.click( | |
enhanced_respond, | |
inputs=[textbox, chatbot, system_message, max_tokens], | |
outputs=[chatbot, textbox] # Second output clears textbox | |
) | |
demo.launch() |