File size: 19,941 Bytes
a5cd7c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
#!pip install diffusers transformers accelerate safetensors torch torchvision pillow --quiet gradio

# πŸš€ Gradio Chatbot Space for DarkNeuron Chat v1.1
# Author: @Madara369Uchiha | Works perfectly on Hugging Face Spaces

import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

# πŸ”§ Model Setup
model_name = "DarkNeuron-AI/darkneuron-chat-v1.1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
device = 0 if torch.cuda.is_available() else -1

# βš™οΈ Create Chat Pipeline
chatbot = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    device=device,
    return_full_text=False
)

# 🧠 Chat Function
def chat_fn(message, history):
    history_text = ""
    for user, bot in history:
        history_text += f"User: {user}\nBot: {bot}\n"
    prompt = f"{history_text}User: {message}\nBot:"

    response = chatbot(
        prompt,
        max_length=200,
        do_sample=True,
        temperature=0.7,
        top_p=0.9,
        num_return_sequences=1
    )[0]["generated_text"]

    return response.strip()

# 🎨 Ultra Premium DarkNeuron Chat v1.1
# Perfect Dark Theme - No Tint - Premium Look

# ... (Your chat_fn code stays here) ...

# 🎨 Perfect Dark Premium CSS - NO TINT
custom_css = """

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css');



* {

    margin: 0;

    padding: 0;

    box-sizing: border-box;

}



/* Ultra Dark Background */

.gradio-container {

    background: #0d1117 !important;

    min-height: 100vh;

}



/* Hide ALL Scrollbars */

::-webkit-scrollbar { display: none !important; }

* {

    scrollbar-width: none !important;

    -ms-overflow-style: none !important;

}



/* Premium Glass Header */

.glass-header {

    background: rgba(13, 17, 23, 0.8);

    backdrop-filter: blur(30px);

    border: 1px solid rgba(139, 122, 255, 0.3);

    border-radius: 24px;

    padding: 1.5rem 2rem;

    margin-bottom: 2rem;

    box-shadow: 0 8px 40px rgba(139, 122, 255, 0.2);

}



.logo-container {

    display: flex;

    align-items: center;

    justify-content: center;

    gap: 1rem;

    margin-bottom: 0.5rem;

}



.logo-icon {

    font-size: 3rem;

    color: #8b7aff;

    filter: drop-shadow(0 0 25px rgba(139, 122, 255, 0.7));

    animation: pulse 2s ease-in-out infinite;

}



@keyframes pulse {

    0%, 100% { 

        transform: scale(1); 

        filter: drop-shadow(0 0 25px rgba(139, 122, 255, 0.7)); 

    }

    50% { 

        transform: scale(1.15); 

        filter: drop-shadow(0 0 40px rgba(139, 122, 255, 1)); 

    }

}



.logo-text {

    font-size: 2.3rem;

    font-weight: 900;

    background: linear-gradient(135deg, #8b7aff 0%, #b794f6 50%, #da92ff 100%);

    -webkit-background-clip: text;

    -webkit-text-fill-color: transparent;

}



.version-tag {

    display: inline-flex;

    align-items: center;

    gap: 0.5rem;

    padding: 0.5rem 1.3rem;

    background: rgba(139, 122, 255, 0.2);

    border: 1px solid rgba(139, 122, 255, 0.4);

    border-radius: 30px;

    font-size: 0.9rem;

    color: #c4b5ff;

    box-shadow: 0 4px 20px rgba(139, 122, 255, 0.25);

}



/* Hero Section */

.hero-section {

    text-align: center;

    padding: 3rem 0 4rem;

}



.hero-title {

    font-size: 4.5rem;

    font-weight: 900;

    color: #ffffff;

    margin-bottom: 1.5rem;

    text-shadow: 0 0 80px rgba(139, 122, 255, 0.8);

    letter-spacing: -0.02em;

}



.hero-subtitle {

    font-size: 1.4rem;

    color: rgba(255, 255, 255, 0.75);

    max-width: 800px;

    margin: 0 auto 2rem;

    line-height: 1.8;

}



/* Feature Cards - PURE DARK, NO TINT */

.feature-glass-card {

    background: rgba(139, 122, 255, 0.25) !important;

    border: 1px solid rgba(139, 122, 255, 0.25) !important;

    border-radius: 24px !important;

    padding: 3rem 2.5rem !important;

    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1) !important;

    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6) !important;

    position: relative;

    overflow: hidden;

}



.feature-glass-card::after {

    content: '';

    position: absolute;

    top: 0;

    left: 0;

    right: 0;

    bottom: 0;

    background: transparent !important;

    pointer-events: none;

}



.feature-glass-card::before {

    content: '';

    position: absolute;

    top: 0;

    left: -100%;

    width: 100%;

    height: 100%;

    background: linear-gradient(90deg, transparent, rgba(139, 122, 255, 0.08), transparent);

    transition: left 0.8s ease;

}



.feature-glass-card:hover::before {

    left: 100%;

}



.feature-glass-card:hover {

    transform: translateY(-12px) scale(1.03);

    background: #1c2128 !important;

    border-color: rgba(139, 122, 255, 0.5) !important;

    box-shadow: 0 20px 60px rgba(139, 122, 255, 0.4) !important;

}



.icon-box {

    background: transparent !important;

    border: none !important;

    padding: 1.5rem !important;

    border-radius: 16px !important;

    margin-bottom: 2rem !important;

    display: inline-block;

}



.icon-wrapper {

    font-size: 4.5rem;

    display: inline-block;

    transition: all 0.6s ease;

    filter: drop-shadow(0 8px 20px rgba(139, 122, 255, 0.4));

}



.feature-glass-card:hover .icon-wrapper {

    transform: rotateY(360deg) scale(1.2);

    filter: drop-shadow(0 12px 30px rgba(139, 122, 255, 0.7));

}



.feature-title-glass {

    font-size: 1.6rem;

    font-weight: 800;

    color: #ffffff;

    margin-bottom: 1rem;

    letter-spacing: -0.01em;

}



.feature-desc-glass {

    color: rgba(255, 255, 255, 0.7);

    line-height: 1.8;

    font-size: 1rem;

}



/* Chat Container */

.chat-container-glass {

    background: #161b22;

    border: 2px solid #4ade80;

    border-radius: 24px;

    padding: 2rem;

    box-shadow: 0 0 50px rgba(74, 222, 128, 0.25);

}



/* Settings Sidebar */

.settings-sidebar {

    background: #161b22;

    border: 1px solid rgba(139, 122, 255, 0.25);

    border-radius: 20px;

    padding: 2rem;

    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);

}



.settings-header {

    font-size: 1.2rem;

    font-weight: 700;

    color: #b794f6;

    margin-bottom: 1.5rem;

    display: flex;

    align-items: center;

    gap: 0.5rem;

    padding-bottom: 1rem;

    border-bottom: 1px solid rgba(139, 122, 255, 0.2);

}



/* Sliders & Inputs */

label {

    color: rgba(255, 255, 255, 0.8) !important;

    font-weight: 600 !important;

    font-size: 0.9rem !important;

}



input[type="range"] {

    -webkit-appearance: none;

    width: 100%;

    height: 6px;

    border-radius: 5px;

    background: rgba(255, 255, 255, 0.2) !important;

    outline: none;

}



input[type="range"]::-webkit-slider-thumb {

    -webkit-appearance: none;

    appearance: none;

    width: 18px;

    height: 18px;

    border-radius: 50%;

    background: linear-gradient(135deg, #8b7aff, #b794f6);

    cursor: pointer;

    box-shadow: 0 0 15px rgba(255, 255, 255, 0.6);

}



input[type="number"],

textarea {

    background: #0d1117 !important;

    border: 1px solid rgba(255, 255, 255, 0.3) !important;

    border-radius: 10px !important;

    color: white !important;

    padding: 0.7rem !important;

}



/* Chatbot */

.chatbot {

    border: none !important;

    background: transparent !important;

}



/* Input Box */

.input-glass-box input,

.input-glass-box textarea {

    background: #0d1117 !important;

    border: 1px solid rgba(139, 122, 255, 0.3) !important;

    border-radius: 14px !important;

    padding: 1rem 1.3rem !important;

    color: rgba(255, 255, 255, 0.95) !important;

    font-size: 1rem !important;

}



.input-glass-box input::placeholder,

.input-glass-box textarea::placeholder {

    color: rgba(255, 255, 255, 0.5) !important;

}



.input-glass-box input:focus,

.input-glass-box textarea:focus {

    background: #0d1117 !important;

    border-color: rgba(139, 122, 255, 0.6) !important;

    box-shadow: 0 0 25px rgba(139, 122, 255, 0.4) !important;

    outline: none !important;

}



/* Buttons */

button {

    border-radius: 14px !important;

    font-weight: 700 !important;

    padding: 0.9rem 2rem !important;

    transition: all 0.4s ease !important;

    font-size: 1rem !important;

}



.primary-btn {

    background: linear-gradient(135deg, #8b7aff 0%, #b794f6 100%) !important;

    border: none !important;

    color: white !important;

    box-shadow: 0 6px 25px rgba(139, 122, 255, 0.5);

}



.primary-btn:hover {

    transform: translateY(-4px) scale(1.05) !important;

    box-shadow: 0 15px 45px rgba(139, 122, 255, 0.7) !important;

}



.secondary-btn {

    background: #0d1117 !important;

    border: 1px solid rgba(139, 122, 255, 0.35) !important;

    color: rgba(255, 255, 255, 0.95) !important;

}



.secondary-btn:hover {

    background: #161b22 !important;

    transform: translateY(-4px) !important;

    box-shadow: 0 12px 35px rgba(139, 122, 255, 0.35) !important;

}



/* Section Headers */

.section-header-glass {

    text-align: center;

    font-size: 3rem;

    font-weight: 900;

    background: linear-gradient(135deg, #8b7aff, #b794f6, #da92ff);

    -webkit-background-clip: text;

    -webkit-text-fill-color: transparent;

    margin: 5rem 0 3.5rem;

    letter-spacing: -0.02em;

}



.section-header-glass::after {

    content: '';

    display: block;

    width: 120px;

    height: 5px;

    background: linear-gradient(90deg, #8b7aff, #b794f6);

    margin: 1.3rem auto 0;

    border-radius: 3px;

}



/* Footer */

.footer-glass {

    background: rgba(13, 17, 23, 0.8);

    backdrop-filter: blur(20px);

    border-top: 1px solid rgba(139, 122, 255, 0.25);

    padding: 3rem;

    margin-top: 6rem;

    text-align: center;

    color: rgba(255, 255, 255, 0.65);

}



/* Floating Animation */

@keyframes float {

    0%, 100% { transform: translateY(0px); }

    50% { transform: translateY(-20px); }

}



.floating {

    animation: float 3s ease-in-out infinite;

}



/* Responsive */

@media (max-width: 768px) {

    .hero-title { font-size: 2.5rem; }

    .hero-subtitle { font-size: 1.1rem; }

    .feature-glass-card { padding: 2rem !important; }

}

"""

# 🎯 Ultra Dark Theme
custom_theme = gr.themes.Soft(
    primary_hue="purple",
    secondary_hue="blue",
    neutral_hue="slate",
    font=gr.themes.GoogleFont("Inter"),
).set(
    body_background_fill="#0d1117",
    block_background_fill="#161b22",
    input_background_fill="#0d1117",
)

# πŸš€ Build Interface
with gr.Blocks(theme=custom_theme, css=custom_css, title="DarkNeuron Chat v1.1") as demo:
    
    # 🌟 Header
    with gr.Column(elem_classes=["glass-header"]):
        gr.HTML("""

            <div class="logo-container">

                <i class="fas fa-brain logo-icon floating"></i>

                <span class="logo-text">DarkNeuron</span>

            </div>

            <div style="text-align: center;">

                <span class="version-tag">

                    <i class="fas fa-sparkles"></i>

                    v1.1 Ultra Premium

                </span>

            </div>

        """)
    
    # 🎯 Hero
    with gr.Column(elem_classes=["hero-section"]):
        gr.HTML("""

            <h1 class="hero-title">Welcome to DarkNeuron</h1>

            <p class="hero-subtitle">Experience the pinnacle of AI conversation with advanced controls, stunning ultra-dark visuals, and blazing-fast performance.</p>

        """)
    
    # πŸ’¬ Chat Interface with Settings Sidebar
    with gr.Row():
        # βš™οΈ Settings Sidebar (Left)
        with gr.Column(scale=2, elem_classes=["settings-sidebar"]):
            gr.HTML('<div class="settings-header"><i class="fas fa-sliders"></i> Advanced Settings</div>')
            
            temperature = gr.Slider(
                minimum=0.1, maximum=2.0, value=0.7, step=0.1,
                label="🌑️ Temperature",
                info="Creativity level"
            )
            
            top_p = gr.Slider(
                minimum=0.1, maximum=1.0, value=0.9, step=0.05,
                label="🎯 Top P",
                info="Sampling threshold"
            )
            
            max_tokens = gr.Slider(
                minimum=50, maximum=2048, value=200, step=50,
                label="πŸ“ Max Tokens",
                info="Response length"
            )
            
            top_k = gr.Slider(
                minimum=1, maximum=100, value=50, step=1,
                label="πŸ”’ Top K",
                info="Vocabulary limit"
            )
            
            system_prompt = gr.Textbox(
                label="πŸ’¬ System Prompt",
                placeholder="You are a helpful AI assistant...",
                lines=4,
                value="You are DarkNeuron, a helpful and intelligent AI assistant."
            )
        
        # πŸ’¬ Chat Area (Center/Right)
        with gr.Column(scale=5, elem_classes=["chat-container-glass"]):
            chatbot_ui = gr.Chatbot(
                label="",
                height=600,
                show_copy_button=True,
                show_label=False,
                avatar_images=(
                    "https://api.dicebear.com/7.x/avataaars/svg?seed=User&backgroundColor=8b7aff",
                    "https://api.dicebear.com/7.x/bottts/svg?seed=DarkNeuron&backgroundColor=b794f6"
                ),
                bubble_full_width=False,
            )
            
            with gr.Row():
                with gr.Column(scale=6, elem_classes=["input-glass-box"]):
                    chat_input = gr.Textbox(
                        placeholder="Type your message here...",
                        show_label=False,
                        container=False,
                        max_lines=1,
                    )
                submit_btn = gr.Button("πŸš€ Send", scale=1, elem_classes=["primary-btn"])
            
            with gr.Row():
                clear_btn = gr.Button("πŸ—‘οΈ Clear", scale=1, elem_classes=["secondary-btn"])
                regenerate_btn = gr.Button("πŸ”„ Regenerate", scale=1, elem_classes=["secondary-btn"])
                export_btn = gr.Button("πŸ’Ύ Export", scale=1, elem_classes=["secondary-btn"])
    
    # ✨ Features - NO TINT
    gr.HTML('<h2 class="section-header-glass">Powerful Features</h2>')
    
    with gr.Row(equal_height=True):
        with gr.Column(scale=1):
            with gr.Group(elem_classes=["feature-glass-card"]):
                gr.HTML("""

                    <div class="icon-box">

                        <div class="icon-wrapper">

                            <i class="fas fa-bolt" style="color: #fbbf24;"></i>

                        </div>

                    </div>

                    <div class="feature-title-glass">Lightning Fast</div>

                    <div class="feature-desc-glass">Real-time streaming with token-by-token generation for instant, natural conversations.</div>

                """)
        
        with gr.Column(scale=1):
            with gr.Group(elem_classes=["feature-glass-card"]):
                gr.HTML("""

                    <div class="icon-box">

                        <div class="icon-wrapper">

                            <i class="fas fa-shield-halved" style="color: #4ade80;"></i>

                        </div>

                    </div>

                    <div class="feature-title-glass">Private & Secure</div>

                    <div class="feature-desc-glass">Enterprise-grade security with complete data isolation on Hugging Face Spaces.</div>

                """)
        
        with gr.Column(scale=1):
            with gr.Group(elem_classes=["feature-glass-card"]):
                gr.HTML("""

                    <div class="icon-box">

                        <div class="icon-wrapper">

                            <i class="fas fa-microchip" style="color: #f87171;"></i>

                        </div>

                    </div>

                    <div class="feature-title-glass">GPU Accelerated</div>

                    <div class="feature-desc-glass">Optimized PyTorch inference with blazing-fast GPU acceleration.</div>

                """)
    
    with gr.Row(equal_height=True):
        with gr.Column(scale=1):
            with gr.Group(elem_classes=["feature-glass-card"]):
                gr.HTML("""

                    <div class="icon-box">

                        <div class="icon-wrapper">

                            <i class="fas fa-comments" style="color: #b794f6;"></i>

                        </div>

                    </div>

                    <div class="feature-title-glass">Smart Context</div>

                    <div class="feature-desc-glass">Maintains conversation context for coherent, intelligent responses.</div>

                """)
        
        with gr.Column(scale=1):
            with gr.Group(elem_classes=["feature-glass-card"]):
                gr.HTML("""

                    <div class="icon-box">

                        <div class="icon-wrapper">

                            <i class="fas fa-wand-magic-sparkles" style="color: #fb923c;"></i>

                        </div>

                    </div>

                    <div class="feature-title-glass">Beautiful UI</div>

                    <div class="feature-desc-glass">Ultra-dark theme with advanced animations and stunning visual effects.</div>

                """)
        
        with gr.Column(scale=1):
            with gr.Group(elem_classes=["feature-glass-card"]):
                gr.HTML("""

                    <div class="icon-box">

                        <div class="icon-wrapper">

                            <i class="fas fa-code-branch" style="color: #60a5fa;"></i>

                        </div>

                    </div>

                    <div class="feature-title-glass">Open Source</div>

                    <div class="feature-desc-glass">Built with Transformers and Gradio - transparent and customizable.</div>

                """)
    
    # πŸ“Š Footer
    gr.HTML("""

        <div class="footer-glass">

            <p style="font-size: 1.1rem;"><i class="fas fa-flask"></i> Built with Gradio & Transformers | Powered by DarkNeuron-AI</p>

            <p style="margin-top: 0.7rem;"><i class="fas fa-heart" style="color: #f87171;"></i> Crafted with passion by @Madara369Uchiha</p>

        </div>

    """)
    
    # βš™οΈ Event Handlers
    def respond(message, chat_history, temp, top_p_val, max_tok):
        if not message.strip():
            return "", chat_history
        bot_response = chat_fn(message, chat_history)
        chat_history.append((message, bot_response))
        return "", chat_history
    
    def regenerate(chat_history):
        if not chat_history:
            return chat_history
        last_message = chat_history[-1][0]
        chat_history = chat_history[:-1]
        bot_response = chat_fn(last_message, chat_history)
        chat_history.append((last_message, bot_response))
        return chat_history
    
    # Connect events
    chat_input.submit(respond, [chat_input, chatbot_ui, temperature, top_p, max_tokens], [chat_input, chatbot_ui])
    submit_btn.click(respond, [chat_input, chatbot_ui, temperature, top_p, max_tokens], [chat_input, chatbot_ui])
    clear_btn.click(lambda: [], None, chatbot_ui)
    regenerate_btn.click(regenerate, chatbot_ui, chatbot_ui)

# πŸš€ Launch
if __name__ == "__main__":
    demo.launch(share=True)