Spaces:
Sleeping
Sleeping
Ritvik
commited on
Commit
ยท
41958d2
1
Parent(s):
05c9eb2
Save local changes before pull
Browse files
app.py
CHANGED
|
@@ -1,64 +1,249 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from chatbot import respond
|
| 3 |
|
|
|
|
| 4 |
custom_css = """
|
| 5 |
.gradio-container {
|
| 6 |
-
font-family: '
|
| 7 |
-
background: #
|
| 8 |
-
color: #
|
| 9 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
}
|
| 11 |
.chatbot .message {
|
| 12 |
-
border-radius:
|
| 13 |
-
padding: 15px;
|
| 14 |
-
margin:
|
| 15 |
-
max-width:
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
.chatbot .message.bot {
|
| 18 |
-
background: #
|
| 19 |
-
color: #
|
|
|
|
| 20 |
}
|
| 21 |
.chatbot .message.user {
|
| 22 |
-
background: #ff8c00;
|
| 23 |
color: white;
|
| 24 |
margin-left: auto;
|
|
|
|
| 25 |
}
|
| 26 |
.textbox {
|
| 27 |
-
background:
|
| 28 |
-
border: 2px solid #
|
| 29 |
-
border-radius:
|
| 30 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
.button {
|
| 33 |
-
background: #ff8c00;
|
| 34 |
color: white;
|
| 35 |
-
border-radius:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
.button:hover {
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
"""
|
| 41 |
|
| 42 |
-
#
|
| 43 |
def enhanced_respond(message, history, system_message, max_tokens, temperature=0.7, top_p=0.95):
|
| 44 |
response = respond(message, history, system_message, max_tokens, temperature, top_p)
|
| 45 |
if "โ" in response or "not found" in response.lower():
|
| 46 |
-
response += "\n\n
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
gr.
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
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.",
|
| 57 |
-
label="System Message",
|
| 58 |
-
visible=False
|
| 59 |
),
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from chatbot import respond
|
| 3 |
|
| 4 |
+
# Ultra-dynamic travel-themed CSS
|
| 5 |
custom_css = """
|
| 6 |
.gradio-container {
|
| 7 |
+
font-family: 'Poppins', sans-serif;
|
| 8 |
+
background: linear-gradient(45deg, #1e3c72 0%, #2a5298 50%, #87ceeb 100%);
|
| 9 |
+
color: #ffffff;
|
| 10 |
+
padding: 40px;
|
| 11 |
+
min-height: 100vh;
|
| 12 |
+
position: relative;
|
| 13 |
+
overflow: hidden;
|
| 14 |
+
animation: gradientShift 15s infinite ease-in-out;
|
| 15 |
+
}
|
| 16 |
+
.gradio-container::before {
|
| 17 |
+
content: '';
|
| 18 |
+
position: absolute;
|
| 19 |
+
top: -50%;
|
| 20 |
+
left: -50%;
|
| 21 |
+
width: 200%;
|
| 22 |
+
height: 200%;
|
| 23 |
+
background: radial-gradient(circle, rgba(255, 140, 0, 0.2) 0%, transparent 70%);
|
| 24 |
+
animation: pulseGlow 10s infinite alternate ease-in-out;
|
| 25 |
+
}
|
| 26 |
+
.gradio-container::after {
|
| 27 |
+
content: '';
|
| 28 |
+
position: absolute;
|
| 29 |
+
bottom: 0;
|
| 30 |
+
right: 0;
|
| 31 |
+
width: 150px;
|
| 32 |
+
height: 150px;
|
| 33 |
+
background: url('https://img.icons8.com/?size=100&id=124350&format=png&color=000000') no-repeat center;
|
| 34 |
+
opacity: 0.3;
|
| 35 |
+
animation: floatPlane 8s infinite ease-in-out;
|
| 36 |
+
}
|
| 37 |
+
.chatbot {
|
| 38 |
+
background: rgba(255, 255, 255, 0.25);
|
| 39 |
+
border-radius: 25px;
|
| 40 |
+
padding: 25px;
|
| 41 |
+
backdrop-filter: blur(15px);
|
| 42 |
+
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
|
| 43 |
+
border: 2px solid rgba(255, 140, 0, 0.5);
|
| 44 |
+
transition: border-color 0.5s ease;
|
| 45 |
+
}
|
| 46 |
+
.chatbot:hover {
|
| 47 |
+
border-color: #ff8c00;
|
| 48 |
}
|
| 49 |
.chatbot .message {
|
| 50 |
+
border-radius: 20px;
|
| 51 |
+
padding: 15px 20px;
|
| 52 |
+
margin: 12px 0;
|
| 53 |
+
max-width: 75%;
|
| 54 |
+
font-size: 16px;
|
| 55 |
+
animation: slideInMessage 0.5s ease-out;
|
| 56 |
+
border: none !important;
|
| 57 |
}
|
| 58 |
.chatbot .message.bot {
|
| 59 |
+
background: linear-gradient(135deg, #87ceeb 0%, #b0e0e6 100%);
|
| 60 |
+
color: #1a2c38;
|
| 61 |
+
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
|
| 62 |
}
|
| 63 |
.chatbot .message.user {
|
| 64 |
+
background: linear-gradient(135deg, #ff8c00 0%, #ff4500 100%);
|
| 65 |
color: white;
|
| 66 |
margin-left: auto;
|
| 67 |
+
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.2);
|
| 68 |
}
|
| 69 |
.textbox {
|
| 70 |
+
background: rgba(255, 255, 255, 0.15);
|
| 71 |
+
border: 2px solid #b0e0e6;
|
| 72 |
+
border-radius: 25px;
|
| 73 |
+
color: #ffffff;
|
| 74 |
+
padding: 15px 25px;
|
| 75 |
+
font-size: 16px;
|
| 76 |
+
transition: all 0.4s ease;
|
| 77 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 78 |
+
}
|
| 79 |
+
.textbox:focus {
|
| 80 |
+
border-color: #ff8c00;
|
| 81 |
+
box-shadow: 0 0 20px rgba(255, 140, 0, 0.7);
|
| 82 |
+
background: rgba(255, 255, 255, 0.25);
|
| 83 |
}
|
| 84 |
.button {
|
| 85 |
+
background: linear-gradient(135deg, #ff8c00 0%, #ff4500 100%);
|
| 86 |
color: white;
|
| 87 |
+
border-radius: 25px;
|
| 88 |
+
padding: 15px 35px;
|
| 89 |
+
font-size: 16px;
|
| 90 |
+
font-weight: 600;
|
| 91 |
+
transition: all 0.3s ease;
|
| 92 |
+
position: relative;
|
| 93 |
+
overflow: hidden;
|
| 94 |
+
box-shadow: 0 4px 15px rgba(255, 140, 0, 0.3);
|
| 95 |
}
|
| 96 |
.button:hover {
|
| 97 |
+
transform: translateY(-3px);
|
| 98 |
+
box-shadow: 0 8px 25px rgba(255, 140, 0, 0.5);
|
| 99 |
+
}
|
| 100 |
+
.button::after {
|
| 101 |
+
content: '';
|
| 102 |
+
position: absolute;
|
| 103 |
+
width: 100px;
|
| 104 |
+
height: 100px;
|
| 105 |
+
background: rgba(255, 255, 255, 0.3);
|
| 106 |
+
border-radius: 50%;
|
| 107 |
+
transform: scale(0);
|
| 108 |
+
animation: ripple 0.6s linear;
|
| 109 |
+
pointer-events: none;
|
| 110 |
+
}
|
| 111 |
+
.button:active::after {
|
| 112 |
+
animation: ripple 0.6s linear;
|
| 113 |
+
}
|
| 114 |
+
h1 {
|
| 115 |
+
font-size: 3.2em;
|
| 116 |
+
text-align: center;
|
| 117 |
+
color: #ff8c00;
|
| 118 |
+
text-shadow: 3px 3px 10px rgba(0, 0, 0, 0.5);
|
| 119 |
+
margin-bottom: 10px;
|
| 120 |
+
animation: bounceIn 1.5s ease-in-out;
|
| 121 |
+
}
|
| 122 |
+
h3 {
|
| 123 |
+
text-align: center;
|
| 124 |
+
color: #b0e0e6;
|
| 125 |
+
font-size: 1.4em;
|
| 126 |
+
margin-bottom: 30px;
|
| 127 |
+
animation: fadeIn 2s ease-in-out;
|
| 128 |
+
}
|
| 129 |
+
@keyframes gradientShift {
|
| 130 |
+
0% { background-position: 0% 50%; }
|
| 131 |
+
50% { background-position: 100% 50%; }
|
| 132 |
+
100% { background-position: 0% 50%; }
|
| 133 |
+
}
|
| 134 |
+
@keyframes pulseGlow {
|
| 135 |
+
0% { transform: scale(1); opacity: 0.2; }
|
| 136 |
+
100% { transform: scale(1.1); opacity: 0.3; }
|
| 137 |
+
}
|
| 138 |
+
@keyframes floatPlane {
|
| 139 |
+
0%, 100% { transform: translateY(0); }
|
| 140 |
+
50% { transform: translateY(-20px); }
|
| 141 |
+
}
|
| 142 |
+
@keyframes slideInMessage {
|
| 143 |
+
0% { opacity: 0; transform: translateY(20px); }
|
| 144 |
+
100% { opacity: 1; transform: translateY(0); }
|
| 145 |
+
}
|
| 146 |
+
@keyframes bounceIn {
|
| 147 |
+
0% { opacity: 0; transform: scale(0.8); }
|
| 148 |
+
60% { opacity: 1; transform: scale(1.05); }
|
| 149 |
+
100% { opacity: 1; transform: scale(1); }
|
| 150 |
+
}
|
| 151 |
+
@keyframes fadeIn {
|
| 152 |
+
0% { opacity: 0; }
|
| 153 |
+
100% { opacity: 1; }
|
| 154 |
+
}
|
| 155 |
+
@keyframes ripple {
|
| 156 |
+
0% { transform: scale(0); opacity: 1; }
|
| 157 |
+
100% { transform: scale(4); opacity: 0; }
|
| 158 |
+
}
|
| 159 |
+
.slider {
|
| 160 |
+
--track-color: #ff8c00;
|
| 161 |
+
--thumb-color: #b0e0e6;
|
| 162 |
+
transition: all 0.3s ease;
|
| 163 |
+
}
|
| 164 |
+
.slider:hover {
|
| 165 |
+
--thumb-color: #ff8c00;
|
| 166 |
+
}
|
| 167 |
+
.footer {
|
| 168 |
+
text-align: center;
|
| 169 |
+
color: #b0e0e6;
|
| 170 |
+
font-size: 1em;
|
| 171 |
+
margin-top: 25px;
|
| 172 |
+
animation: fadeIn 3s ease-in-out;
|
| 173 |
}
|
| 174 |
"""
|
| 175 |
|
| 176 |
+
# Enhanced dynamic respond function
|
| 177 |
def enhanced_respond(message, history, system_message, max_tokens, temperature=0.7, top_p=0.95):
|
| 178 |
response = respond(message, history, system_message, max_tokens, temperature, top_p)
|
| 179 |
if "โ" in response or "not found" in response.lower():
|
| 180 |
+
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! โ๏ธ"
|
| 181 |
+
else:
|
| 182 |
+
response = f"๐ {response} ๐บ๏ธ Whereโs your next destination? Letโs soar! โ๏ธ"
|
| 183 |
+
return history + [[message, response]], "" # Clears textbox
|
| 184 |
+
|
| 185 |
+
# Dynamic travel interface
|
| 186 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 187 |
+
gr.Markdown(
|
| 188 |
+
"""
|
| 189 |
+
# โ๏ธ Travelo - Your Cosmic Travel Guide ๐
|
| 190 |
+
### Embark on unforgettable journeys with real-time travel magic!
|
| 191 |
+
""",
|
| 192 |
+
elem_classes=["title"]
|
| 193 |
+
)
|
| 194 |
|
| 195 |
+
chatbot = gr.Chatbot(
|
| 196 |
+
height=600,
|
| 197 |
+
label="Chat with Travelo",
|
| 198 |
+
bubble_full_width=False,
|
| 199 |
+
avatar_images=(
|
| 200 |
+
"https://img.icons8.com/?size=100&id=98766&format=png&color=000000",
|
| 201 |
+
"https://img.icons8.com/?size=100&id=124350&format=png&color=000000"
|
|
|
|
|
|
|
|
|
|
| 202 |
),
|
| 203 |
+
placeholder="๐ด Your travel story starts here..."
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
with gr.Row(variant="compact"):
|
| 207 |
+
textbox = gr.Textbox(
|
| 208 |
+
placeholder="Dream big! (e.g., 'Sunset spots in Santorini')",
|
| 209 |
+
lines=1,
|
| 210 |
+
elem_classes=["textbox"],
|
| 211 |
+
autofocus=True
|
| 212 |
+
)
|
| 213 |
+
submit_btn = gr.Button("โ๏ธ Launch Adventure", elem_classes=["button"])
|
| 214 |
+
|
| 215 |
+
with gr.Accordion("๐ Travel Toolkit", open=False):
|
| 216 |
+
max_tokens = gr.Slider(
|
| 217 |
+
minimum=1,
|
| 218 |
+
maximum=2048,
|
| 219 |
+
value=512,
|
| 220 |
+
step=1,
|
| 221 |
+
label="Adventure Depth",
|
| 222 |
+
info="How epic should my travel tales be?"
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
system_message = gr.Textbox(
|
| 226 |
+
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.",
|
| 227 |
+
visible=False
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
gr.Markdown(
|
| 231 |
+
"""
|
| 232 |
+
๐ Crafted by Travelo LLC | Explore the world, one chat at a time! โ๏ธ
|
| 233 |
+
""",
|
| 234 |
+
elem_classes=["footer"]
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
# Event triggers without _js
|
| 238 |
+
textbox.submit(
|
| 239 |
+
enhanced_respond,
|
| 240 |
+
inputs=[textbox, chatbot, system_message, max_tokens],
|
| 241 |
+
outputs=[chatbot, textbox] # Second output clears textbox
|
| 242 |
+
)
|
| 243 |
+
submit_btn.click(
|
| 244 |
+
enhanced_respond,
|
| 245 |
+
inputs=[textbox, chatbot, system_message, max_tokens],
|
| 246 |
+
outputs=[chatbot, textbox] # Second output clears textbox
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
demo.launch()
|