DevNumb commited on
Commit
bc92016
Β·
verified Β·
1 Parent(s): edc7f70

Update app.py

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