Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -129,7 +129,7 @@ def retry_last_response(history, temperature, max_length):
|
|
| 129 |
|
| 130 |
return new_history
|
| 131 |
|
| 132 |
-
# Custom CSS for
|
| 133 |
custom_css = """
|
| 134 |
.gradio-container {
|
| 135 |
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
@@ -139,7 +139,7 @@ custom_css = """
|
|
| 139 |
}
|
| 140 |
|
| 141 |
.main-container {
|
| 142 |
-
max-width:
|
| 143 |
margin: 0 auto;
|
| 144 |
background: white;
|
| 145 |
border-radius: 20px;
|
|
@@ -168,60 +168,72 @@ custom_css = """
|
|
| 168 |
|
| 169 |
.content {
|
| 170 |
display: flex;
|
| 171 |
-
min-height:
|
|
|
|
| 172 |
}
|
| 173 |
|
|
|
|
| 174 |
.chat-column {
|
| 175 |
-
flex: 3
|
| 176 |
display: flex;
|
| 177 |
flex-direction: column;
|
|
|
|
| 178 |
}
|
| 179 |
|
|
|
|
| 180 |
.control-column {
|
| 181 |
-
flex: 1;
|
| 182 |
background: #f8f9fa;
|
| 183 |
-
padding:
|
| 184 |
border-left: 1px solid #e1e5e9;
|
|
|
|
|
|
|
| 185 |
}
|
| 186 |
|
| 187 |
.chatbot-container {
|
| 188 |
flex: 1;
|
| 189 |
display: flex;
|
| 190 |
flex-direction: column;
|
| 191 |
-
min-height:
|
| 192 |
}
|
| 193 |
|
| 194 |
#chatbot {
|
| 195 |
flex: 1;
|
| 196 |
-
min-height:
|
|
|
|
| 197 |
border: none !important;
|
| 198 |
background: white !important;
|
| 199 |
-
padding:
|
| 200 |
margin: 0 !important;
|
|
|
|
| 201 |
}
|
| 202 |
|
| 203 |
#chatbot .message {
|
| 204 |
-
padding:
|
| 205 |
-
margin:
|
| 206 |
-
border-radius:
|
| 207 |
-
max-width:
|
|
|
|
|
|
|
| 208 |
}
|
| 209 |
|
| 210 |
#chatbot .user-message {
|
| 211 |
-
background: #667eea !important;
|
| 212 |
color: white !important;
|
| 213 |
margin-left: auto !important;
|
|
|
|
| 214 |
}
|
| 215 |
|
| 216 |
#chatbot .bot-message {
|
| 217 |
-
background: #
|
| 218 |
-
color: #
|
| 219 |
margin-right: auto !important;
|
|
|
|
| 220 |
}
|
| 221 |
|
| 222 |
.input-container {
|
| 223 |
background: #f8f9fa;
|
| 224 |
-
padding:
|
| 225 |
border-top: 1px solid #e1e5e9;
|
| 226 |
}
|
| 227 |
|
|
@@ -231,6 +243,7 @@ custom_css = """
|
|
| 231 |
border-radius: 15px;
|
| 232 |
margin-bottom: 20px;
|
| 233 |
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
|
|
|
| 234 |
}
|
| 235 |
|
| 236 |
.model-info {
|
|
@@ -238,43 +251,118 @@ custom_css = """
|
|
| 238 |
color: white;
|
| 239 |
padding: 20px;
|
| 240 |
border-radius: 15px;
|
|
|
|
| 241 |
}
|
| 242 |
|
| 243 |
.gr-button {
|
| 244 |
-
background: linear-gradient(
|
| 245 |
border: none !important;
|
| 246 |
color: white !important;
|
| 247 |
-
border-radius:
|
| 248 |
-
padding:
|
| 249 |
font-weight: 600 !important;
|
| 250 |
margin: 5px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
|
| 253 |
.clear-btn {
|
| 254 |
-
background: linear-gradient(
|
|
|
|
| 255 |
}
|
| 256 |
|
| 257 |
.retry-btn {
|
| 258 |
-
background: linear-gradient(
|
|
|
|
| 259 |
}
|
| 260 |
|
| 261 |
.textbox {
|
| 262 |
-
border-radius:
|
| 263 |
-
border: 2px solid #
|
| 264 |
-
padding:
|
| 265 |
font-size: 16px !important;
|
|
|
|
|
|
|
|
|
|
| 266 |
}
|
| 267 |
|
| 268 |
.textbox:focus {
|
| 269 |
border-color: #667eea !important;
|
| 270 |
-
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 271 |
}
|
| 272 |
|
| 273 |
.examples-panel {
|
| 274 |
background: white;
|
| 275 |
-
padding:
|
| 276 |
border-top: 1px solid #e1e5e9;
|
| 277 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
"""
|
| 279 |
|
| 280 |
# Create the Gradio interface
|
|
@@ -287,7 +375,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 287 |
gr.Markdown("Chat with Alibaba's advanced Qwen3-0.6B model - Think tags automatically removed!")
|
| 288 |
|
| 289 |
with gr.Row(elem_classes="content"):
|
| 290 |
-
# Left Column - Chat (
|
| 291 |
with gr.Column(elem_classes="chat-column"):
|
| 292 |
with gr.Column(elem_classes="chatbot-container"):
|
| 293 |
chatbot = gr.Chatbot(
|
|
@@ -296,7 +384,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 296 |
elem_id="chatbot",
|
| 297 |
show_copy_button=True,
|
| 298 |
avatar_images=("π€", "π€"),
|
| 299 |
-
height=
|
| 300 |
container=True,
|
| 301 |
show_label=False
|
| 302 |
)
|
|
@@ -305,61 +393,72 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
| 305 |
with gr.Row():
|
| 306 |
msg = gr.Textbox(
|
| 307 |
label="",
|
| 308 |
-
placeholder="Type your message here...",
|
| 309 |
-
lines=
|
| 310 |
scale=4,
|
| 311 |
container=False,
|
| 312 |
show_label=False
|
| 313 |
)
|
| 314 |
-
|
|
|
|
| 315 |
|
| 316 |
with gr.Row():
|
| 317 |
-
clear_btn = gr.Button("ποΈ Clear Chat", elem_classes="clear-btn")
|
| 318 |
-
retry_btn = gr.Button("π Retry Last", elem_classes="retry-btn")
|
| 319 |
gr.HTML("""<div style="flex: 1; text-align: center; color: #666; font-size: 12px; padding: 10px;">
|
| 320 |
Press Enter to send β’ Shift+Enter for new line
|
| 321 |
</div>""")
|
| 322 |
|
| 323 |
-
# Right Column - Controls (
|
| 324 |
with gr.Column(elem_classes="control-column"):
|
| 325 |
with gr.Column(elem_classes="control-panel"):
|
| 326 |
-
gr.Markdown("### βοΈ
|
| 327 |
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
with gr.Column(elem_classes="model-info"):
|
| 347 |
gr.Markdown("### βΉοΈ Model Info")
|
| 348 |
if tokenizer and model:
|
| 349 |
gr.Markdown("""
|
| 350 |
-
**
|
| 351 |
-
|
|
|
|
| 352 |
**Think Tags:** Auto-removed β
|
| 353 |
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
|
|
|
| 358 |
""")
|
| 359 |
else:
|
| 360 |
gr.Markdown("""
|
| 361 |
-
**Status:**
|
| 362 |
-
|
|
|
|
| 363 |
""")
|
| 364 |
|
| 365 |
# Examples Section
|
|
|
|
| 129 |
|
| 130 |
return new_history
|
| 131 |
|
| 132 |
+
# Custom CSS with more space for chat and settings moved to right
|
| 133 |
custom_css = """
|
| 134 |
.gradio-container {
|
| 135 |
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
|
|
| 139 |
}
|
| 140 |
|
| 141 |
.main-container {
|
| 142 |
+
max-width: 1400px;
|
| 143 |
margin: 0 auto;
|
| 144 |
background: white;
|
| 145 |
border-radius: 20px;
|
|
|
|
| 168 |
|
| 169 |
.content {
|
| 170 |
display: flex;
|
| 171 |
+
min-height: 700px;
|
| 172 |
+
gap: 0;
|
| 173 |
}
|
| 174 |
|
| 175 |
+
/* Chat column - 80% width */
|
| 176 |
.chat-column {
|
| 177 |
+
flex: 4; /* Increased from 3 to 4 for more space */
|
| 178 |
display: flex;
|
| 179 |
flex-direction: column;
|
| 180 |
+
min-width: 0; /* Allow shrinking */
|
| 181 |
}
|
| 182 |
|
| 183 |
+
/* Control column - 20% width */
|
| 184 |
.control-column {
|
| 185 |
+
flex: 1; /* Reduced to take less space */
|
| 186 |
background: #f8f9fa;
|
| 187 |
+
padding: 20px;
|
| 188 |
border-left: 1px solid #e1e5e9;
|
| 189 |
+
min-width: 280px; /* Minimum width for controls */
|
| 190 |
+
max-width: 320px; /* Maximum width for controls */
|
| 191 |
}
|
| 192 |
|
| 193 |
.chatbot-container {
|
| 194 |
flex: 1;
|
| 195 |
display: flex;
|
| 196 |
flex-direction: column;
|
| 197 |
+
min-height: 600px;
|
| 198 |
}
|
| 199 |
|
| 200 |
#chatbot {
|
| 201 |
flex: 1;
|
| 202 |
+
min-height: 550px !important;
|
| 203 |
+
max-height: 550px !important;
|
| 204 |
border: none !important;
|
| 205 |
background: white !important;
|
| 206 |
+
padding: 25px !important;
|
| 207 |
margin: 0 !important;
|
| 208 |
+
overflow-y: auto !important;
|
| 209 |
}
|
| 210 |
|
| 211 |
#chatbot .message {
|
| 212 |
+
padding: 18px 22px !important;
|
| 213 |
+
margin: 12px 0 !important;
|
| 214 |
+
border-radius: 18px !important;
|
| 215 |
+
max-width: 85% !important;
|
| 216 |
+
line-height: 1.5 !important;
|
| 217 |
+
font-size: 15px !important;
|
| 218 |
}
|
| 219 |
|
| 220 |
#chatbot .user-message {
|
| 221 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 222 |
color: white !important;
|
| 223 |
margin-left: auto !important;
|
| 224 |
+
border: none !important;
|
| 225 |
}
|
| 226 |
|
| 227 |
#chatbot .bot-message {
|
| 228 |
+
background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
|
| 229 |
+
color: #2d3748 !important;
|
| 230 |
margin-right: auto !important;
|
| 231 |
+
border: 1px solid #e2e8f0 !important;
|
| 232 |
}
|
| 233 |
|
| 234 |
.input-container {
|
| 235 |
background: #f8f9fa;
|
| 236 |
+
padding: 25px;
|
| 237 |
border-top: 1px solid #e1e5e9;
|
| 238 |
}
|
| 239 |
|
|
|
|
| 243 |
border-radius: 15px;
|
| 244 |
margin-bottom: 20px;
|
| 245 |
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 246 |
+
border: 1px solid #eef2f7;
|
| 247 |
}
|
| 248 |
|
| 249 |
.model-info {
|
|
|
|
| 251 |
color: white;
|
| 252 |
padding: 20px;
|
| 253 |
border-radius: 15px;
|
| 254 |
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
| 255 |
}
|
| 256 |
|
| 257 |
.gr-button {
|
| 258 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 259 |
border: none !important;
|
| 260 |
color: white !important;
|
| 261 |
+
border-radius: 12px !important;
|
| 262 |
+
padding: 14px 28px !important;
|
| 263 |
font-weight: 600 !important;
|
| 264 |
margin: 5px !important;
|
| 265 |
+
transition: all 0.3s ease !important;
|
| 266 |
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
.gr-button:hover {
|
| 270 |
+
transform: translateY(-2px) !important;
|
| 271 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important;
|
| 272 |
}
|
| 273 |
|
| 274 |
.clear-btn {
|
| 275 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%) !important;
|
| 276 |
+
box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3) !important;
|
| 277 |
}
|
| 278 |
|
| 279 |
.retry-btn {
|
| 280 |
+
background: linear-gradient(135deg, #00b894 0%, #00a085 100%) !important;
|
| 281 |
+
box-shadow: 0 4px 12px rgba(0, 184, 148, 0.3) !important;
|
| 282 |
}
|
| 283 |
|
| 284 |
.textbox {
|
| 285 |
+
border-radius: 15px !important;
|
| 286 |
+
border: 2px solid #e2e8f0 !important;
|
| 287 |
+
padding: 18px !important;
|
| 288 |
font-size: 16px !important;
|
| 289 |
+
background: white !important;
|
| 290 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
|
| 291 |
+
min-height: 80px !important;
|
| 292 |
}
|
| 293 |
|
| 294 |
.textbox:focus {
|
| 295 |
border-color: #667eea !important;
|
| 296 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), 0 2px 8px rgba(0,0,0,0.05) !important;
|
| 297 |
}
|
| 298 |
|
| 299 |
.examples-panel {
|
| 300 |
background: white;
|
| 301 |
+
padding: 25px;
|
| 302 |
border-top: 1px solid #e1e5e9;
|
| 303 |
}
|
| 304 |
+
|
| 305 |
+
.control-section {
|
| 306 |
+
margin-bottom: 20px;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
.control-section:last-child {
|
| 310 |
+
margin-bottom: 0;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
.slider-container {
|
| 314 |
+
margin: 15px 0;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
.feature-list {
|
| 318 |
+
list-style: none;
|
| 319 |
+
padding: 0;
|
| 320 |
+
margin: 10px 0 0 0;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.feature-list li {
|
| 324 |
+
padding: 6px 0;
|
| 325 |
+
position: relative;
|
| 326 |
+
padding-left: 20px;
|
| 327 |
+
font-size: 14px;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
.feature-list li::before {
|
| 331 |
+
content: 'β';
|
| 332 |
+
position: absolute;
|
| 333 |
+
left: 0;
|
| 334 |
+
color: #48bb78;
|
| 335 |
+
font-weight: bold;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
.status-indicator {
|
| 339 |
+
display: inline-block;
|
| 340 |
+
width: 10px;
|
| 341 |
+
height: 10px;
|
| 342 |
+
border-radius: 50%;
|
| 343 |
+
margin-right: 8px;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
.status-online {
|
| 347 |
+
background: #48bb78;
|
| 348 |
+
box-shadow: 0 0 8px #48bb78;
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
@media (max-width: 1024px) {
|
| 352 |
+
.content {
|
| 353 |
+
flex-direction: column;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
.control-column {
|
| 357 |
+
max-width: none;
|
| 358 |
+
border-left: none;
|
| 359 |
+
border-top: 1px solid #e1e5e9;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
.chat-column {
|
| 363 |
+
min-height: 500px;
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
"""
|
| 367 |
|
| 368 |
# Create the Gradio interface
|
|
|
|
| 375 |
gr.Markdown("Chat with Alibaba's advanced Qwen3-0.6B model - Think tags automatically removed!")
|
| 376 |
|
| 377 |
with gr.Row(elem_classes="content"):
|
| 378 |
+
# Left Column - Chat (80% width)
|
| 379 |
with gr.Column(elem_classes="chat-column"):
|
| 380 |
with gr.Column(elem_classes="chatbot-container"):
|
| 381 |
chatbot = gr.Chatbot(
|
|
|
|
| 384 |
elem_id="chatbot",
|
| 385 |
show_copy_button=True,
|
| 386 |
avatar_images=("π€", "π€"),
|
| 387 |
+
height=550,
|
| 388 |
container=True,
|
| 389 |
show_label=False
|
| 390 |
)
|
|
|
|
| 393 |
with gr.Row():
|
| 394 |
msg = gr.Textbox(
|
| 395 |
label="",
|
| 396 |
+
placeholder="π Type your message here... (Press Enter to send, Shift+Enter for new line)",
|
| 397 |
+
lines=3,
|
| 398 |
scale=4,
|
| 399 |
container=False,
|
| 400 |
show_label=False
|
| 401 |
)
|
| 402 |
+
with gr.Column(scale=1):
|
| 403 |
+
submit_btn = gr.Button("Send π", size="lg")
|
| 404 |
|
| 405 |
with gr.Row():
|
| 406 |
+
clear_btn = gr.Button("ποΈ Clear Chat", elem_classes="clear-btn", size="sm")
|
| 407 |
+
retry_btn = gr.Button("π Retry Last", elem_classes="retry-btn", size="sm")
|
| 408 |
gr.HTML("""<div style="flex: 1; text-align: center; color: #666; font-size: 12px; padding: 10px;">
|
| 409 |
Press Enter to send β’ Shift+Enter for new line
|
| 410 |
</div>""")
|
| 411 |
|
| 412 |
+
# Right Column - Controls (20% width)
|
| 413 |
with gr.Column(elem_classes="control-column"):
|
| 414 |
with gr.Column(elem_classes="control-panel"):
|
| 415 |
+
gr.Markdown("### βοΈ Settings")
|
| 416 |
|
| 417 |
+
with gr.Column(elem_classes="control-section"):
|
| 418 |
+
gr.Markdown("**ποΈ Temperature**")
|
| 419 |
+
temperature = gr.Slider(
|
| 420 |
+
minimum=0.1,
|
| 421 |
+
maximum=1.5,
|
| 422 |
+
value=0.7,
|
| 423 |
+
step=0.1,
|
| 424 |
+
label="",
|
| 425 |
+
show_label=False
|
| 426 |
+
)
|
| 427 |
+
gr.Markdown("<div style='font-size: 12px; color: #666; margin-top: 8px;'>Lower = more predictable<br>Higher = more creative</div>")
|
| 428 |
|
| 429 |
+
with gr.Column(elem_classes="control-section"):
|
| 430 |
+
gr.Markdown("**π Max Length**")
|
| 431 |
+
max_length = gr.Slider(
|
| 432 |
+
minimum=50,
|
| 433 |
+
maximum=1000,
|
| 434 |
+
value=256,
|
| 435 |
+
step=50,
|
| 436 |
+
label="",
|
| 437 |
+
show_label=False
|
| 438 |
+
)
|
| 439 |
+
gr.Markdown("<div style='font-size: 12px; color: #666; margin-top: 8px;'>Response length in tokens</div>")
|
| 440 |
|
| 441 |
with gr.Column(elem_classes="model-info"):
|
| 442 |
gr.Markdown("### βΉοΈ Model Info")
|
| 443 |
if tokenizer and model:
|
| 444 |
gr.Markdown("""
|
| 445 |
+
<span class="status-indicator status-online"></span> **Status:** Online
|
| 446 |
+
|
| 447 |
+
**Model:** Qwen3-0.6B β
|
| 448 |
**Think Tags:** Auto-removed β
|
| 449 |
|
| 450 |
+
<ul class="feature-list">
|
| 451 |
+
<li>0.6B parameters</li>
|
| 452 |
+
<li>128K context</li>
|
| 453 |
+
<li>Multilingual</li>
|
| 454 |
+
<li>Advanced AI</li>
|
| 455 |
+
</ul>
|
| 456 |
""")
|
| 457 |
else:
|
| 458 |
gr.Markdown("""
|
| 459 |
+
<span class="status-indicator status-online" style="background: #ed8936;"></span> **Status:** Loading
|
| 460 |
+
|
| 461 |
+
Check console for details
|
| 462 |
""")
|
| 463 |
|
| 464 |
# Examples Section
|