Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,11 +111,11 @@ def openrouter_chat(user_message, history, use_web_search):
|
|
| 111 |
|
| 112 |
return history, ""
|
| 113 |
|
| 114 |
-
#
|
| 115 |
custom_css = """
|
| 116 |
-
/*
|
| 117 |
.gradio-container {
|
| 118 |
-
background: linear-gradient(135deg, #
|
| 119 |
min-height: 100vh;
|
| 120 |
padding: 20px;
|
| 121 |
}
|
|
@@ -126,22 +126,22 @@ custom_css = """
|
|
| 126 |
margin: 0 auto;
|
| 127 |
}
|
| 128 |
|
| 129 |
-
/* Chat container with glassmorphism
|
| 130 |
#component-0 {
|
| 131 |
-
background: rgba(255, 255, 255, 0.
|
| 132 |
backdrop-filter: blur(10px);
|
| 133 |
-
border-radius:
|
| 134 |
-
border: 1px solid rgba(255, 255, 255, 0.
|
| 135 |
-
box-shadow: 0
|
| 136 |
padding: 20px;
|
| 137 |
}
|
| 138 |
|
| 139 |
/* Chatbot styling */
|
| 140 |
.chatbot {
|
| 141 |
-
background: rgba(255, 255, 255, 0.
|
| 142 |
-
border-radius:
|
| 143 |
-
border:
|
| 144 |
-
box-shadow: 0 4px
|
| 145 |
}
|
| 146 |
|
| 147 |
/* Message bubbles */
|
|
@@ -152,70 +152,64 @@ custom_css = """
|
|
| 152 |
}
|
| 153 |
|
| 154 |
.user {
|
| 155 |
-
background-color: #
|
| 156 |
color: white !important;
|
| 157 |
margin-left: 20% !important;
|
| 158 |
}
|
| 159 |
|
| 160 |
.bot {
|
| 161 |
-
background-color: #
|
| 162 |
-
color: #
|
| 163 |
margin-right: 20% !important;
|
|
|
|
| 164 |
}
|
| 165 |
|
| 166 |
/* Input styling */
|
| 167 |
.textbox {
|
| 168 |
-
border-radius:
|
| 169 |
-
border: 2px solid #
|
| 170 |
-
background:
|
| 171 |
font-size: 16px !important;
|
| 172 |
}
|
| 173 |
|
| 174 |
.textbox:focus {
|
| 175 |
-
border-color: #
|
| 176 |
-
box-shadow: 0 0 0 3px rgba(
|
| 177 |
}
|
| 178 |
|
| 179 |
/* Checkbox styling */
|
| 180 |
.checkbox-group {
|
| 181 |
background: rgba(255, 255, 255, 0.8) !important;
|
| 182 |
-
border-radius:
|
| 183 |
padding: 10px !important;
|
| 184 |
margin: 10px 0 !important;
|
| 185 |
}
|
| 186 |
|
| 187 |
/* Button styling */
|
| 188 |
button {
|
| 189 |
-
background:
|
| 190 |
color: white !important;
|
| 191 |
border: none !important;
|
| 192 |
-
border-radius:
|
| 193 |
padding: 10px 20px !important;
|
| 194 |
-
font-weight:
|
| 195 |
-
transition: all 0.
|
| 196 |
}
|
| 197 |
|
| 198 |
button:hover {
|
| 199 |
-
|
| 200 |
-
|
|
|
|
| 201 |
}
|
| 202 |
|
| 203 |
/* Title styling */
|
| 204 |
h1, h2 {
|
| 205 |
-
color:
|
| 206 |
-
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3) !important;
|
| 207 |
-
}
|
| 208 |
-
|
| 209 |
-
/* Markdown styling */
|
| 210 |
-
.markdown-text {
|
| 211 |
-
color: white !important;
|
| 212 |
-
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3) !important;
|
| 213 |
}
|
| 214 |
|
| 215 |
-
/*
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
border-left: 4px solid #ff6b6b !important;
|
| 219 |
}
|
| 220 |
|
| 221 |
/* Responsive design */
|
|
@@ -233,62 +227,49 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 233 |
gr.Markdown(
|
| 234 |
"""
|
| 235 |
<div style="text-align: center; padding: 20px;">
|
| 236 |
-
<h1 style="font-size:
|
| 237 |
-
<
|
| 238 |
</div>
|
| 239 |
""",
|
| 240 |
elem_id="header"
|
| 241 |
)
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
with gr.Row():
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
with gr.Row():
|
| 261 |
-
use_web_search = gr.Checkbox(
|
| 262 |
-
label="🔍 Enable Web Search",
|
| 263 |
-
value=True,
|
| 264 |
-
info="Search the web for current information before answering"
|
| 265 |
-
)
|
| 266 |
-
clear_btn = gr.Button("🗑️ Clear Chat", size="sm")
|
| 267 |
-
|
| 268 |
-
with gr.Column(scale=1):
|
| 269 |
-
gr.Markdown(
|
| 270 |
-
"""
|
| 271 |
-
### 📋 Features
|
| 272 |
-
- 💬 Real-time chat with AI
|
| 273 |
-
- 🔍 Web search integration
|
| 274 |
-
- 📜 Conversation history
|
| 275 |
-
- 🎨 Beautiful gradient UI
|
| 276 |
-
|
| 277 |
-
### 🔧 Tips
|
| 278 |
-
- Enable web search for current events
|
| 279 |
-
- Ask follow-up questions
|
| 280 |
-
- Clear chat to start fresh
|
| 281 |
-
|
| 282 |
-
### ⚡ Shortcuts
|
| 283 |
-
- Enter: Send message
|
| 284 |
-
- Shift+Enter: New line
|
| 285 |
-
""",
|
| 286 |
-
elem_classes=["markdown-text"]
|
| 287 |
-
)
|
| 288 |
|
| 289 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
| 290 |
msg_in.submit(
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
inputs=[msg_in, chatbot, use_web_search],
|
| 293 |
outputs=[chatbot, msg_in]
|
| 294 |
)
|
|
@@ -305,7 +286,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 305 |
["What are the current stock market trends?", True]
|
| 306 |
],
|
| 307 |
inputs=[msg_in, use_web_search],
|
| 308 |
-
label="
|
| 309 |
)
|
| 310 |
|
| 311 |
demo.launch()
|
|
|
|
| 111 |
|
| 112 |
return history, ""
|
| 113 |
|
| 114 |
+
# Clean and professional CSS
|
| 115 |
custom_css = """
|
| 116 |
+
/* Clean gradient background */
|
| 117 |
.gradio-container {
|
| 118 |
+
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
| 119 |
min-height: 100vh;
|
| 120 |
padding: 20px;
|
| 121 |
}
|
|
|
|
| 126 |
margin: 0 auto;
|
| 127 |
}
|
| 128 |
|
| 129 |
+
/* Chat container with subtle glassmorphism */
|
| 130 |
#component-0 {
|
| 131 |
+
background: rgba(255, 255, 255, 0.9);
|
| 132 |
backdrop-filter: blur(10px);
|
| 133 |
+
border-radius: 15px;
|
| 134 |
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
| 135 |
+
box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.1);
|
| 136 |
padding: 20px;
|
| 137 |
}
|
| 138 |
|
| 139 |
/* Chatbot styling */
|
| 140 |
.chatbot {
|
| 141 |
+
background: rgba(255, 255, 255, 0.95) !important;
|
| 142 |
+
border-radius: 12px !important;
|
| 143 |
+
border: 1px solid #e0e0e0 !important;
|
| 144 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
|
| 145 |
}
|
| 146 |
|
| 147 |
/* Message bubbles */
|
|
|
|
| 152 |
}
|
| 153 |
|
| 154 |
.user {
|
| 155 |
+
background-color: #4a5568 !important;
|
| 156 |
color: white !important;
|
| 157 |
margin-left: 20% !important;
|
| 158 |
}
|
| 159 |
|
| 160 |
.bot {
|
| 161 |
+
background-color: #f7fafc !important;
|
| 162 |
+
color: #2d3748 !important;
|
| 163 |
margin-right: 20% !important;
|
| 164 |
+
border: 1px solid #e2e8f0 !important;
|
| 165 |
}
|
| 166 |
|
| 167 |
/* Input styling */
|
| 168 |
.textbox {
|
| 169 |
+
border-radius: 8px !important;
|
| 170 |
+
border: 2px solid #e2e8f0 !important;
|
| 171 |
+
background: white !important;
|
| 172 |
font-size: 16px !important;
|
| 173 |
}
|
| 174 |
|
| 175 |
.textbox:focus {
|
| 176 |
+
border-color: #4a5568 !important;
|
| 177 |
+
box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1) !important;
|
| 178 |
}
|
| 179 |
|
| 180 |
/* Checkbox styling */
|
| 181 |
.checkbox-group {
|
| 182 |
background: rgba(255, 255, 255, 0.8) !important;
|
| 183 |
+
border-radius: 8px !important;
|
| 184 |
padding: 10px !important;
|
| 185 |
margin: 10px 0 !important;
|
| 186 |
}
|
| 187 |
|
| 188 |
/* Button styling */
|
| 189 |
button {
|
| 190 |
+
background: #4a5568 !important;
|
| 191 |
color: white !important;
|
| 192 |
border: none !important;
|
| 193 |
+
border-radius: 8px !important;
|
| 194 |
padding: 10px 20px !important;
|
| 195 |
+
font-weight: 600 !important;
|
| 196 |
+
transition: all 0.2s ease !important;
|
| 197 |
}
|
| 198 |
|
| 199 |
button:hover {
|
| 200 |
+
background: #2d3748 !important;
|
| 201 |
+
transform: translateY(-1px) !important;
|
| 202 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
|
| 203 |
}
|
| 204 |
|
| 205 |
/* Title styling */
|
| 206 |
h1, h2 {
|
| 207 |
+
color: #2d3748 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
}
|
| 209 |
|
| 210 |
+
/* Remove excessive shadows and effects */
|
| 211 |
+
* {
|
| 212 |
+
text-shadow: none !important;
|
|
|
|
| 213 |
}
|
| 214 |
|
| 215 |
/* Responsive design */
|
|
|
|
| 227 |
gr.Markdown(
|
| 228 |
"""
|
| 229 |
<div style="text-align: center; padding: 20px;">
|
| 230 |
+
<h1 style="font-size: 2.5em; margin-bottom: 10px;">🤖 AI Chat Assistant</h1>
|
| 231 |
+
<p style="font-size: 1.1em; color: #718096;">Powered by Devstral with Web Search</p>
|
| 232 |
</div>
|
| 233 |
""",
|
| 234 |
elem_id="header"
|
| 235 |
)
|
| 236 |
|
| 237 |
+
chatbot = gr.Chatbot(
|
| 238 |
+
label="Chat History",
|
| 239 |
+
height=500,
|
| 240 |
+
elem_classes=["chatbot"],
|
| 241 |
+
bubble_full_width=False
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
with gr.Row():
|
| 245 |
+
msg_in = gr.Textbox(
|
| 246 |
+
placeholder="Type your message here...",
|
| 247 |
+
label="Message",
|
| 248 |
+
scale=4,
|
| 249 |
+
lines=1
|
| 250 |
+
)
|
| 251 |
+
submit_btn = gr.Button("Send", scale=1, variant="primary")
|
| 252 |
+
|
| 253 |
+
with gr.Row():
|
| 254 |
+
use_web_search = gr.Checkbox(
|
| 255 |
+
label="🔍 Enable Web Search",
|
| 256 |
+
value=True,
|
| 257 |
+
scale=2
|
| 258 |
+
)
|
| 259 |
+
clear_btn = gr.Button("Clear Chat", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
# Event handlers
|
| 262 |
+
def submit_message(msg, history, search):
|
| 263 |
+
return openrouter_chat(msg, history, search)
|
| 264 |
+
|
| 265 |
msg_in.submit(
|
| 266 |
+
submit_message,
|
| 267 |
+
inputs=[msg_in, chatbot, use_web_search],
|
| 268 |
+
outputs=[chatbot, msg_in]
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
submit_btn.click(
|
| 272 |
+
submit_message,
|
| 273 |
inputs=[msg_in, chatbot, use_web_search],
|
| 274 |
outputs=[chatbot, msg_in]
|
| 275 |
)
|
|
|
|
| 286 |
["What are the current stock market trends?", True]
|
| 287 |
],
|
| 288 |
inputs=[msg_in, use_web_search],
|
| 289 |
+
label="Example Queries"
|
| 290 |
)
|
| 291 |
|
| 292 |
demo.launch()
|