File size: 5,778 Bytes
da784c8
efe44f0
da784c8
 
efe44f0
18f610c
da784c8
 
 
efe44f0
46da343
 
 
 
 
efe44f0
c1e9709
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
efe44f0
c1e9709
 
 
 
 
 
 
 
 
 
efe44f0
 
a1130ae
c1e9709
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
efe44f0
 
c1e9709
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
import os
from threading import Thread
from typing import Iterator

import gradio as gr
import spaces
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
import subprocess

subprocess.run(
    "pip install flash-attn --no-build-isolation",
    env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
    shell=True,
)

CUSTOM_CSS = """
.container {
    max-width: 1000px !important;
    margin: auto !important;
    padding-top: 2rem !important;
}

.header-container {
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    padding: 2rem;
    border-radius: 1rem;
    margin-bottom: 2rem;
    color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.model-info {
    background: white;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-container {
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.message {
    padding: 1rem;
    margin: 0.5rem;
    border-radius: 0.5rem;
}

.user-message {
    background: #f3f4f6;
}

.assistant-message {
    background: #dbeafe;
}

.controls-container {
    background: #f8fafc;
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
}

.slider-label {
    font-weight: 600;
    color: #374151;
}

.duplicate-button {
    background: #2563eb !important;
    color: white !important;
    padding: 0.75rem 1.5rem !important;
    border-radius: 0.5rem !important;
    font-weight: 600 !important;
    transition: all 0.2s !important;
}

.duplicate-button:hover {
    background: #1d4ed8 !important;
    transform: translateY(-1px) !important;
}
"""

DESCRIPTION = '''
<div class="header-container">
    <h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; text-align: center;">Lexora-Lite-3B</h1>
    <div class="model-info">
        <h2 style="font-size: 1.5rem; font-weight: 600; color: #1e3a8a; margin-bottom: 1rem;">About the Model</h2>
        <p style="color: #374151; line-height: 1.6;">
            This Space demonstrates <a href="https://huggingface.co/DeepMount00/Lexora-Lite-3B" style="color: #2563eb; font-weight: 600;">Lexora-Lite-3B Chat ITA</a>, 
            currently the best open-source large language model for the Italian language. Compare its performance with other models on the 
            <a href="https://huggingface.co/spaces/FinancialSupport/open_ita_llm_leaderboard" style="color: #2563eb; font-weight: 600;">official leaderboard</a>.
        </p>
    </div>
</div>
'''

# Rest of your existing code remains the same until the Blocks creation

with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft(
    primary_hue="blue",
    secondary_hue="blue",
    neutral_hue="slate",
    font=gr.themes.GoogleFont("Inter"),
    radius_size=gr.themes.sizes.radius_sm,
)) as demo:
    with gr.Column(elem_classes="container"):
        gr.Markdown(DESCRIPTION)
        
        with gr.Column(elem_classes="chat-container"):
            chat_interface = gr.ChatInterface(
                fn=generate,
                additional_inputs=[
                    gr.Textbox(
                        value="",
                        label="System Message",
                        elem_classes="system-message",
                        render=False,
                    ),
                    gr.Column(elem_classes="controls-container") as controls:
                        with controls:
                            gr.Slider(
                                label="Maximum New Tokens",
                                minimum=1,
                                maximum=MAX_MAX_NEW_TOKENS,
                                step=1,
                                value=DEFAULT_MAX_NEW_TOKENS,
                                elem_classes="slider-label",
                            ),
                            gr.Slider(
                                label="Temperature",
                                minimum=0,
                                maximum=4.0,
                                step=0.1,
                                value=0.001,
                                elem_classes="slider-label",
                            ),
                            gr.Slider(
                                label="Top-p (Nucleus Sampling)",
                                minimum=0.05,
                                maximum=1.0,
                                step=0.05,
                                value=1.0,
                                elem_classes="slider-label",
                            ),
                            gr.Slider(
                                label="Top-k",
                                minimum=1,
                                maximum=1000,
                                step=1,
                                value=50,
                                elem_classes="slider-label",
                            ),
                            gr.Slider(
                                label="Repetition Penalty",
                                minimum=1.0,
                                maximum=2.0,
                                step=0.05,
                                value=1.0,
                                elem_classes="slider-label",
                            ),
                ],
                examples=[
                    ["Ciao! Come stai?"],
                ],
                cache_examples=False,
            )
        
        gr.DuplicateButton(
            value="Duplicate Space for Private Use",
            elem_classes="duplicate-button",
            elem_id="duplicate-button",
        )

if __name__ == "__main__":
    demo.queue(max_size=20).launch()