DevNumb commited on
Commit
47b0d3a
Β·
verified Β·
1 Parent(s): 93c6ed7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +337 -144
app.py CHANGED
@@ -129,159 +129,323 @@ def retry_last_response(history, temperature, max_length):
129
 
130
  return new_history
131
 
132
- # Custom CSS for beautiful UI
133
  custom_css = """
134
  .gradio-container {
135
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
136
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
137
  min-height: 100vh;
138
- padding: 20px;
 
139
  }
140
 
141
  .main-container {
142
- max-width: 1200px;
143
  margin: 0 auto;
144
  background: white;
145
- border-radius: 20px;
146
- box-shadow: 0 20px 40px rgba(0,0,0,0.1);
147
- overflow: hidden;
 
 
148
  }
149
 
150
  .header {
151
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
152
  color: white;
153
- padding: 30px;
154
  text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  }
156
 
157
  .header h1 {
158
  margin: 0;
159
- font-size: 2.5em;
160
- font-weight: 700;
 
 
161
  }
162
 
163
  .header p {
164
- margin: 10px 0 0 0;
165
- opacity: 0.9;
166
- font-size: 1.2em;
 
 
 
 
 
167
  }
168
 
169
- .content {
170
- display: flex;
171
- min-height: 600px;
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: 25px;
184
- border-left: 1px solid #e1e5e9;
 
185
  }
186
 
187
- .chatbot-container {
188
  flex: 1;
189
- display: flex;
190
- flex-direction: column;
191
  min-height: 500px;
 
 
192
  }
193
 
194
  #chatbot {
195
- flex: 1;
196
  min-height: 500px !important;
 
197
  border: none !important;
198
  background: white !important;
199
- padding: 20px !important;
200
  margin: 0 !important;
 
201
  }
202
 
203
  #chatbot .message {
204
- padding: 15px 20px !important;
205
- margin: 10px 0 !important;
206
- border-radius: 15px !important;
207
- max-width: 80% !important;
 
 
 
 
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: #f1f3f4 !important;
218
- color: #333 !important;
 
219
  margin-right: auto !important;
 
 
 
 
 
 
 
220
  }
221
 
222
  .input-container {
223
- background: #f8f9fa;
224
- padding: 20px;
225
- border-top: 1px solid #e1e5e9;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  }
227
 
228
  .control-panel {
229
  background: white;
230
- padding: 20px;
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 {
237
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
238
  color: white;
239
- padding: 20px;
240
- border-radius: 15px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  }
242
 
243
  .gr-button {
244
- background: linear-gradient(45deg, #667eea, #764ba2) !important;
245
  border: none !important;
246
  color: white !important;
247
- border-radius: 10px !important;
248
- padding: 12px 24px !important;
249
  font-weight: 600 !important;
250
- margin: 5px !important;
 
 
 
 
 
 
 
251
  }
252
 
253
  .clear-btn {
254
- background: linear-gradient(45deg, #ff6b6b, #ee5a24) !important;
 
255
  }
256
 
257
  .retry-btn {
258
- background: linear-gradient(45deg, #00b894, #00a085) !important;
 
259
  }
260
 
261
  .textbox {
262
- border-radius: 12px !important;
263
- border: 2px solid #e1e5e9 !important;
264
- padding: 15px !important;
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: 20px;
276
- border-top: 1px solid #e1e5e9;
277
  }
278
 
279
- .loading {
280
- display: flex;
281
- justify-content: center;
282
- align-items: center;
283
- height: 200px;
284
- color: #666;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  }
286
  """
287
 
@@ -291,15 +455,16 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
291
  with gr.Column(elem_classes="main-container"):
292
  # Header
293
  with gr.Column(elem_classes="header"):
294
- gr.Markdown("# πŸ€– Qwen3-0.6B Chatbot")
295
- gr.Markdown("Chat with Alibaba's advanced Qwen3-0.6B model - Think tags automatically removed!")
296
 
297
- with gr.Row(elem_classes="content"):
298
- # Left Column - Chat (70%)
299
- with gr.Column(elem_classes="chat-column"):
300
- with gr.Column(elem_classes="chatbot-container"):
 
301
  chatbot = gr.Chatbot(
302
- value=[],
303
  label="",
304
  elem_id="chatbot",
305
  show_copy_button=True,
@@ -309,83 +474,111 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
309
  show_label=False
310
  )
311
 
312
- with gr.Column(elem_classes="input-container"):
313
- with gr.Row():
314
- msg = gr.Textbox(
315
- label="",
316
- placeholder="Type your message here...",
317
- lines=2,
318
- scale=4,
319
- container=False,
320
- show_label=False
321
- )
322
- submit_btn = gr.Button("Send πŸš€", size="lg", scale=1)
323
-
324
- with gr.Row():
325
- clear_btn = gr.Button("πŸ—‘οΈ Clear Chat", elem_classes="clear-btn")
326
- retry_btn = gr.Button("πŸ”„ Retry Last", elem_classes="retry-btn")
327
- gr.HTML("""<div style="flex: 1; text-align: center; color: #666; font-size: 12px; padding: 10px;">
328
- Press Enter to send β€’ Shift+Enter for new line
329
- </div>""")
330
-
331
- # Right Column - Controls (30%)
332
- with gr.Column(elem_classes="control-column"):
333
- with gr.Column(elem_classes="control-panel"):
334
- gr.Markdown("### βš™οΈ Generation Settings")
335
-
336
- temperature = gr.Slider(
337
- minimum=0.1,
338
- maximum=1.5,
339
- value=0.7,
340
- step=0.1,
341
- label="Temperature",
342
- info="Lower = more predictable, Higher = more creative"
343
- )
344
-
345
- max_length = gr.Slider(
346
- minimum=50,
347
- maximum=1000,
348
- value=256,
349
- step=50,
350
- label="Max Response Length",
351
- info="Tokens in generated response"
352
- )
353
-
354
- with gr.Column(elem_classes="model-info"):
355
- gr.Markdown("### ℹ️ Model Info")
356
- if tokenizer and model:
357
- gr.Markdown("""
358
- **Model:** Qwen3-0.6B βœ…
359
- **Status:** Ready to chat!
360
- **Think Tags:** Auto-removed βœ…
361
 
362
- **Features:**
363
- β€’ 0.6B parameters
364
- β€’ 128K context
365
- β€’ Multilingual
366
- """)
367
- else:
368
- gr.Markdown("""
369
- **Status:** ⚠️ Loading failed
370
- **Check console for errors**
371
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
 
373
  # Examples Section
374
  with gr.Column(elem_classes="examples-panel"):
375
- gr.Markdown("### πŸ’‘ Try These Examples")
376
- gr.Examples(
377
- examples=[
378
- "Explain quantum computing in simple terms",
379
- "Write a short poem about artificial intelligence",
380
- "What are the benefits of renewable energy?",
381
- "How do I learn programming effectively?",
382
- "Tell me an interesting fact about space exploration",
383
- "Help me plan a healthy weekly meal plan"
384
- ],
385
- inputs=msg,
386
- label="Click any example to start chatting!",
387
- examples_per_page=6
388
- )
 
 
 
 
389
 
390
  # Event handlers
391
  submit_event = msg.submit(
 
129
 
130
  return new_history
131
 
132
+ # Enhanced CSS for beautiful UI with settings below chat
133
  custom_css = """
134
  .gradio-container {
135
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
136
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
137
  min-height: 100vh;
138
+ padding: 0;
139
+ margin: 0;
140
  }
141
 
142
  .main-container {
143
+ max-width: 1400px;
144
  margin: 0 auto;
145
  background: white;
146
+ border-radius: 0;
147
+ box-shadow: 0 0 50px rgba(0,0,0,0.1);
148
+ min-height: 100vh;
149
+ display: flex;
150
+ flex-direction: column;
151
  }
152
 
153
  .header {
154
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
155
  color: white;
156
+ padding: 40px 30px 30px 30px;
157
  text-align: center;
158
+ position: relative;
159
+ overflow: hidden;
160
+ }
161
+
162
+ .header::before {
163
+ content: '';
164
+ position: absolute;
165
+ top: 0;
166
+ left: 0;
167
+ right: 0;
168
+ bottom: 0;
169
+ background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 100" opacity="0.1"><polygon points="0,0 1000,100 1000,0" fill="white"/></svg>');
170
+ background-size: cover;
171
  }
172
 
173
  .header h1 {
174
  margin: 0;
175
+ font-size: 3em;
176
+ font-weight: 800;
177
+ position: relative;
178
+ text-shadow: 0 2px 10px rgba(0,0,0,0.3);
179
  }
180
 
181
  .header p {
182
+ margin: 15px 0 0 0;
183
+ opacity: 0.95;
184
+ font-size: 1.3em;
185
+ font-weight: 300;
186
+ position: relative;
187
+ max-width: 600px;
188
+ margin-left: auto;
189
+ margin-right: auto;
190
  }
191
 
192
+ .chat-main-area {
193
+ flex: 1;
 
 
 
 
 
194
  display: flex;
195
  flex-direction: column;
196
+ min-height: 70vh;
197
  }
198
 
199
+ .chat-container {
200
  flex: 1;
201
+ display: flex;
202
+ flex-direction: column;
203
+ background: white;
204
+ position: relative;
205
  }
206
 
207
+ .chatbot-wrapper {
208
  flex: 1;
 
 
209
  min-height: 500px;
210
+ max-height: 65vh;
211
+ border-bottom: 1px solid #eef2f7;
212
  }
213
 
214
  #chatbot {
 
215
  min-height: 500px !important;
216
+ max-height: 65vh !important;
217
  border: none !important;
218
  background: white !important;
219
+ padding: 30px !important;
220
  margin: 0 !important;
221
+ border-radius: 0 !important;
222
  }
223
 
224
  #chatbot .message {
225
+ padding: 20px 25px !important;
226
+ margin: 15px 0 !important;
227
+ border-radius: 20px !important;
228
+ max-width: 85% !important;
229
+ line-height: 1.6 !important;
230
+ font-size: 16px !important;
231
+ box-shadow: 0 2px 10px rgba(0,0,0,0.08) !important;
232
+ border: 1px solid rgba(0,0,0,0.05) !important;
233
  }
234
 
235
  #chatbot .user-message {
236
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
237
  color: white !important;
238
  margin-left: auto !important;
239
+ margin-right: 0 !important;
240
  }
241
 
242
  #chatbot .bot-message {
243
+ background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
244
+ color: #2d3748 !important;
245
+ margin-left: 0 !important;
246
  margin-right: auto !important;
247
+ border: 1px solid #e2e8f0 !important;
248
+ }
249
+
250
+ .input-section {
251
+ background: #fafbfc;
252
+ padding: 30px;
253
+ border-top: 1px solid #eef2f7;
254
  }
255
 
256
  .input-container {
257
+ max-width: 1000px;
258
+ margin: 0 auto;
259
+ }
260
+
261
+ .controls-section {
262
+ background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
263
+ padding: 40px 30px;
264
+ border-top: 1px solid #e2e8f0;
265
+ }
266
+
267
+ .controls-container {
268
+ max-width: 1200px;
269
+ margin: 0 auto;
270
+ }
271
+
272
+ .controls-grid {
273
+ display: grid;
274
+ grid-template-columns: 1fr 1fr;
275
+ gap: 30px;
276
+ margin-bottom: 30px;
277
  }
278
 
279
  .control-panel {
280
  background: white;
281
+ padding: 30px;
282
+ border-radius: 20px;
283
+ box-shadow: 0 10px 30px rgba(0,0,0,0.08);
284
+ border: 1px solid #eef2f7;
285
  }
286
 
287
+ .model-info-panel {
288
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
289
  color: white;
290
+ padding: 30px;
291
+ border-radius: 20px;
292
+ box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
293
+ position: relative;
294
+ overflow: hidden;
295
+ }
296
+
297
+ .model-info-panel::before {
298
+ content: '';
299
+ position: absolute;
300
+ top: 0;
301
+ right: 0;
302
+ width: 100px;
303
+ height: 100px;
304
+ background: rgba(255,255,255,0.1);
305
+ border-radius: 50%;
306
+ transform: translate(30px, -30px);
307
+ }
308
+
309
+ .control-group {
310
+ margin-bottom: 25px;
311
+ }
312
+
313
+ .control-group:last-child {
314
+ margin-bottom: 0;
315
+ }
316
+
317
+ .control-label {
318
+ display: block;
319
+ font-weight: 600;
320
+ color: #2d3748;
321
+ margin-bottom: 12px;
322
+ font-size: 16px;
323
+ }
324
+
325
+ .control-info {
326
+ font-size: 14px;
327
+ color: #718096;
328
+ margin-top: 8px;
329
+ line-height: 1.5;
330
  }
331
 
332
  .gr-button {
333
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
334
  border: none !important;
335
  color: white !important;
336
+ border-radius: 15px !important;
337
+ padding: 16px 32px !important;
338
  font-weight: 600 !important;
339
+ font-size: 16px !important;
340
+ transition: all 0.3s ease !important;
341
+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
342
+ }
343
+
344
+ .gr-button:hover {
345
+ transform: translateY(-2px) !important;
346
+ box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4) !important;
347
  }
348
 
349
  .clear-btn {
350
+ background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%) !important;
351
+ box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3) !important;
352
  }
353
 
354
  .retry-btn {
355
+ background: linear-gradient(135deg, #00b894 0%, #00a085 100%) !important;
356
+ box-shadow: 0 4px 15px rgba(0, 184, 148, 0.3) !important;
357
  }
358
 
359
  .textbox {
360
+ border-radius: 15px !important;
361
+ border: 2px solid #e2e8f0 !important;
362
+ padding: 20px !important;
363
  font-size: 16px !important;
364
+ background: white !important;
365
+ box-shadow: 0 2px 10px rgba(0,0,0,0.05) !important;
366
  }
367
 
368
  .textbox:focus {
369
  border-color: #667eea !important;
370
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), 0 2px 10px rgba(0,0,0,0.05) !important;
371
+ }
372
+
373
+ .slider-container {
374
+ margin: 20px 0;
375
+ }
376
+
377
+ .model-features {
378
+ margin-top: 20px;
379
+ }
380
+
381
+ .feature-list {
382
+ list-style: none;
383
+ padding: 0;
384
+ margin: 15px 0 0 0;
385
+ }
386
+
387
+ .feature-list li {
388
+ padding: 8px 0;
389
+ position: relative;
390
+ padding-left: 25px;
391
+ }
392
+
393
+ .feature-list li::before {
394
+ content: 'βœ“';
395
+ position: absolute;
396
+ left: 0;
397
+ color: #48bb78;
398
+ font-weight: bold;
399
  }
400
 
401
  .examples-panel {
402
  background: white;
403
+ padding: 40px 30px;
404
+ border-top: 1px solid #eef2f7;
405
  }
406
 
407
+ .examples-container {
408
+ max-width: 1200px;
409
+ margin: 0 auto;
410
+ }
411
+
412
+ .examples-grid {
413
+ display: grid;
414
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
415
+ gap: 15px;
416
+ margin-top: 20px;
417
+ }
418
+
419
+ @media (max-width: 768px) {
420
+ .controls-grid {
421
+ grid-template-columns: 1fr;
422
+ }
423
+
424
+ .header h1 {
425
+ font-size: 2.2em;
426
+ }
427
+
428
+ .header p {
429
+ font-size: 1.1em;
430
+ }
431
+ }
432
+
433
+ .status-indicator {
434
+ display: inline-block;
435
+ width: 12px;
436
+ height: 12px;
437
+ border-radius: 50%;
438
+ margin-right: 8px;
439
+ }
440
+
441
+ .status-online {
442
+ background: #48bb78;
443
+ box-shadow: 0 0 10px #48bb78;
444
+ }
445
+
446
+ .status-offline {
447
+ background: #ed8936;
448
+ box-shadow: 0 0 10px #ed8936;
449
  }
450
  """
451
 
 
455
  with gr.Column(elem_classes="main-container"):
456
  # Header
457
  with gr.Column(elem_classes="header"):
458
+ gr.Markdown("# πŸš€ Qwen3-0.6B Chatbot")
459
+ gr.Markdown("Experience intelligent conversations with Alibaba's advanced AI - Think tags automatically removed! ✨")
460
 
461
+ # Main Chat Area
462
+ with gr.Column(elem_classes="chat-main-area"):
463
+ with gr.Column(elem_classes="chat-container"):
464
+ # Chatbot
465
+ with gr.Column(elem_classes="chatbot-wrapper"):
466
  chatbot = gr.Chatbot(
467
+ value=[["Hello! How can I assist you today? 😊", ""]],
468
  label="",
469
  elem_id="chatbot",
470
  show_copy_button=True,
 
474
  show_label=False
475
  )
476
 
477
+ # Input Section
478
+ with gr.Column(elem_classes="input-section"):
479
+ with gr.Column(elem_classes="input-container"):
480
+ with gr.Row():
481
+ msg = gr.Textbox(
482
+ label="",
483
+ placeholder="πŸ’­ Type your message here... (Press Enter to send, Shift+Enter for new line)",
484
+ lines=2,
485
+ scale=4,
486
+ container=False,
487
+ show_label=False
488
+ )
489
+ with gr.Column(scale=1):
490
+ submit_btn = gr.Button("Send Message πŸš€", size="lg")
491
+
492
+ with gr.Row():
493
+ clear_btn = gr.Button("πŸ—‘οΈ Clear Chat", elem_classes="clear-btn")
494
+ retry_btn = gr.Button("πŸ”„ Retry Last", elem_classes="retry-btn")
495
+ gr.HTML("""<div style="flex: 1; text-align: center; color: #666; font-size: 14px; padding: 12px;">
496
+ ✨ Powered by Qwen3-0.6B β€’ Think tags automatically removed
497
+ </div>""")
498
+
499
+ # Controls Section (Below Chat)
500
+ with gr.Column(elem_classes="controls-section"):
501
+ with gr.Column(elem_classes="controls-container"):
502
+ with gr.Row(elem_classes="controls-grid"):
503
+ # Settings Panel
504
+ with gr.Column(elem_classes="control-panel"):
505
+ gr.Markdown("### βš™οΈ Generation Settings")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
506
 
507
+ with gr.Column(elem_classes="control-group"):
508
+ gr.Markdown("**πŸŽ›οΈ Temperature**")
509
+ temperature = gr.Slider(
510
+ minimum=0.1,
511
+ maximum=1.5,
512
+ value=0.7,
513
+ step=0.1,
514
+ label="",
515
+ show_label=False,
516
+ info=""
517
+ )
518
+ gr.Markdown("<div class='control-info'>Lower values for more predictable responses, higher values for more creativity</div>")
519
+
520
+ with gr.Column(elem_classes="control-group"):
521
+ gr.Markdown("**πŸ“ Max Response Length**")
522
+ max_length = gr.Slider(
523
+ minimum=50,
524
+ maximum=1000,
525
+ value=256,
526
+ step=50,
527
+ label="",
528
+ show_label=False,
529
+ info=""
530
+ )
531
+ gr.Markdown("<div class='control-info'>Number of tokens in the generated response (50-1000)</div>")
532
+
533
+ # Model Info Panel
534
+ with gr.Column(elem_classes="model-info-panel"):
535
+ gr.Markdown("### ℹ️ Model Information")
536
+ if tokenizer and model:
537
+ gr.Markdown("""
538
+ <span class="status-indicator status-online"></span> **Status:** Online & Ready
539
+
540
+ **Model:** Qwen3-0.6B βœ…
541
+ **Think Tags:** Auto-Removed βœ…
542
+
543
+ <div class="model-features">
544
+ **Key Features:**
545
+ <ul class="feature-list">
546
+ <li>0.6 Billion Parameters</li>
547
+ <li>128K Context Window</li>
548
+ <li>Multilingual Support</li>
549
+ <li>Advanced Reasoning</li>
550
+ <li>Chat Optimized</li>
551
+ </ul>
552
+ </div>
553
+ """)
554
+ else:
555
+ gr.Markdown("""
556
+ <span class="status-indicator status-offline"></span> **Status:** Loading Issue
557
+
558
+ Please check the console for error details.
559
+ The interface will use fallback responses.
560
+ """)
561
 
562
  # Examples Section
563
  with gr.Column(elem_classes="examples-panel"):
564
+ with gr.Column(elem_classes="examples-container"):
565
+ gr.Markdown("### πŸ’‘ Quick Start Examples")
566
+ gr.Markdown("Click any example below to start chatting:")
567
+
568
+ with gr.Column(elem_classes="examples-grid"):
569
+ gr.Examples(
570
+ examples=[
571
+ "Explain quantum computing in simple terms",
572
+ "Write a short poem about artificial intelligence",
573
+ "What are the benefits of renewable energy?",
574
+ "How do I learn programming effectively?",
575
+ "Tell me an interesting fact about space exploration",
576
+ "Help me plan a healthy weekly meal plan"
577
+ ],
578
+ inputs=msg,
579
+ label="",
580
+ examples_per_page=6
581
+ )
582
 
583
  # Event handlers
584
  submit_event = msg.submit(