Spaces:
Sleeping
Sleeping
DeepMount00
commited on
Commit
•
f24ac48
1
Parent(s):
a71fb86
Update app.py
Browse files
app.py
CHANGED
@@ -14,12 +14,11 @@ subprocess.run(
|
|
14 |
shell=True,
|
15 |
)
|
16 |
|
17 |
-
# Constants
|
18 |
MAX_MAX_NEW_TOKENS = 2048
|
19 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
20 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
21 |
|
22 |
-
# Model initialization
|
23 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
24 |
model_id = "DeepMount00/Lexora-Lite-3B"
|
25 |
|
@@ -33,193 +32,130 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
33 |
)
|
34 |
model.eval()
|
35 |
|
36 |
-
# Custom CSS
|
37 |
CUSTOM_CSS = """
|
38 |
-
/* Base styles */
|
39 |
-
* {
|
40 |
-
margin: 0;
|
41 |
-
padding: 0;
|
42 |
-
box-sizing: border-box;
|
43 |
-
}
|
44 |
-
|
45 |
-
body {
|
46 |
-
font-family: 'Inter', sans-serif;
|
47 |
-
background-color: #f8fafc;
|
48 |
-
color: #1e293b;
|
49 |
-
}
|
50 |
-
|
51 |
-
/* Container styles */
|
52 |
.container {
|
53 |
max-width: 1000px !important;
|
54 |
margin: auto !important;
|
55 |
-
padding: 2rem !important;
|
56 |
}
|
57 |
|
58 |
-
|
59 |
-
.header-container {
|
60 |
-
background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
|
61 |
-
padding: 2.5rem;
|
62 |
-
border-radius: 1rem;
|
63 |
-
margin-bottom: 2rem;
|
64 |
-
color: white;
|
65 |
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
66 |
-
}
|
67 |
-
|
68 |
-
.header-title {
|
69 |
-
font-size: 2.5rem;
|
70 |
-
font-weight: 700;
|
71 |
-
margin-bottom: 1.5rem;
|
72 |
text-align: center;
|
73 |
-
letter-spacing: -0.025em;
|
74 |
-
}
|
75 |
-
|
76 |
-
/* Model info styles */
|
77 |
-
.model-info {
|
78 |
-
background: white;
|
79 |
-
padding: 1.75rem;
|
80 |
-
border-radius: 0.75rem;
|
81 |
-
margin-top: 1.5rem;
|
82 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
83 |
-
}
|
84 |
-
|
85 |
-
.model-info h2 {
|
86 |
-
font-size: 1.5rem;
|
87 |
-
font-weight: 600;
|
88 |
-
color: #1e3a8a;
|
89 |
margin-bottom: 1rem;
|
|
|
90 |
}
|
91 |
|
92 |
-
.
|
93 |
-
|
94 |
-
line-height: 1.6;
|
95 |
-
font-size: 1.1rem;
|
96 |
-
}
|
97 |
-
|
98 |
-
.model-info a {
|
99 |
-
color: #2563eb;
|
100 |
font-weight: 600;
|
101 |
-
|
102 |
-
|
103 |
}
|
104 |
|
105 |
-
.
|
106 |
-
color: #
|
107 |
-
|
108 |
}
|
109 |
|
110 |
-
/* Chat container styles */
|
111 |
.chat-container {
|
112 |
-
border:
|
113 |
-
border-radius: 1rem;
|
114 |
background: white;
|
115 |
-
box-shadow: 0
|
116 |
-
|
|
|
|
|
117 |
}
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
margin: 0.75rem;
|
123 |
-
border-radius: 0.5rem;
|
124 |
-
font-size: 1.05rem;
|
125 |
-
line-height: 1.6;
|
126 |
}
|
127 |
|
128 |
.user-message {
|
129 |
-
background: #
|
130 |
-
border-left:
|
|
|
|
|
|
|
131 |
}
|
132 |
|
133 |
.assistant-message {
|
134 |
-
background:
|
135 |
-
border-left:
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
.controls-container {
|
140 |
-
background: #f8fafc;
|
141 |
-
padding: 1.75rem;
|
142 |
-
border-radius: 0.75rem;
|
143 |
-
margin-top: 1.5rem;
|
144 |
-
border: 1px solid #e5e7eb;
|
145 |
}
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
}
|
154 |
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
157 |
background: #2563eb !important;
|
158 |
color: white !important;
|
159 |
-
padding: 0.
|
160 |
border-radius: 0.5rem !important;
|
161 |
-
font-
|
162 |
-
font-
|
163 |
-
transition: all 0.2s !important;
|
164 |
-
border: none !important;
|
165 |
-
cursor: pointer !important;
|
166 |
-
display: inline-flex !important;
|
167 |
-
align-items: center !important;
|
168 |
-
justify-content: center !important;
|
169 |
-
text-align: center !important;
|
170 |
-
box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2) !important;
|
171 |
}
|
172 |
|
173 |
-
.
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
177 |
}
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
border: 2px solid #e5e7eb !important;
|
182 |
border-radius: 0.5rem !important;
|
183 |
-
padding:
|
184 |
-
font-size:
|
185 |
-
|
186 |
}
|
187 |
|
188 |
-
.
|
189 |
-
border-color: #
|
190 |
outline: none !important;
|
191 |
-
box-shadow: 0 0 0
|
192 |
}
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
border-radius: 0.5rem;
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
201 |
}
|
202 |
"""
|
203 |
|
204 |
-
# HTML Description
|
205 |
DESCRIPTION = '''
|
206 |
-
<div class="header
|
207 |
-
<h1
|
208 |
-
<
|
209 |
-
<h2>About the Model</h2>
|
210 |
-
<p>
|
211 |
-
Welcome to the demonstration of <a href="https://huggingface.co/DeepMount00/Lexora-Lite-3B">Lexora-Lite-3B Chat ITA</a>,
|
212 |
-
currently the leading open-source large language model for the Italian language. This model represents the state-of-the-art
|
213 |
-
in Italian natural language processing, combining powerful language understanding with efficient performance.
|
214 |
-
</p>
|
215 |
-
<p style="margin-top: 1rem;">
|
216 |
-
View its performance metrics and compare it with other models on the
|
217 |
-
<a href="https://huggingface.co/spaces/FinancialSupport/open_ita_llm_leaderboard">official leaderboard</a>.
|
218 |
-
</p>
|
219 |
-
</div>
|
220 |
</div>
|
221 |
'''
|
222 |
|
|
|
223 |
@spaces.GPU(duration=90)
|
224 |
def generate(
|
225 |
message: str,
|
@@ -270,53 +206,41 @@ def generate(
|
|
270 |
def create_chat_interface():
|
271 |
theme = gr.themes.Soft(
|
272 |
primary_hue="blue",
|
273 |
-
secondary_hue="
|
274 |
neutral_hue="slate",
|
275 |
font=gr.themes.GoogleFont("Inter"),
|
276 |
radius_size=gr.themes.sizes.radius_sm,
|
277 |
)
|
278 |
|
279 |
with gr.Blocks(css=CUSTOM_CSS, theme=theme) as demo:
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
# Create controls without context manager
|
294 |
-
controls = gr.Column(elem_classes="controls-container")
|
295 |
-
with controls:
|
296 |
-
additional_inputs.extend([
|
297 |
-
gr.Slider(
|
298 |
-
label="Maximum New Tokens",
|
299 |
-
minimum=1,
|
300 |
-
maximum=MAX_MAX_NEW_TOKENS,
|
301 |
-
step=1,
|
302 |
-
value=DEFAULT_MAX_NEW_TOKENS,
|
303 |
-
elem_classes="slider-label",
|
304 |
),
|
305 |
gr.Slider(
|
306 |
label="Temperature",
|
307 |
minimum=0,
|
308 |
-
maximum=
|
309 |
step=0.1,
|
310 |
-
value=0.
|
311 |
-
|
312 |
),
|
313 |
gr.Slider(
|
314 |
-
label="Top-p
|
315 |
minimum=0.05,
|
316 |
maximum=1.0,
|
317 |
step=0.05,
|
318 |
value=1.0,
|
319 |
-
|
320 |
),
|
321 |
gr.Slider(
|
322 |
label="Top-k",
|
@@ -324,7 +248,7 @@ def create_chat_interface():
|
|
324 |
maximum=1000,
|
325 |
step=1,
|
326 |
value=50,
|
327 |
-
|
328 |
),
|
329 |
gr.Slider(
|
330 |
label="Repetition Penalty",
|
@@ -332,13 +256,9 @@ def create_chat_interface():
|
|
332 |
maximum=2.0,
|
333 |
step=0.05,
|
334 |
value=1.0,
|
335 |
-
|
336 |
),
|
337 |
-
]
|
338 |
-
|
339 |
-
chat_interface = gr.ChatInterface(
|
340 |
-
fn=generate,
|
341 |
-
additional_inputs=additional_inputs,
|
342 |
examples=[
|
343 |
["Ciao! Come stai?"],
|
344 |
["Raccontami una breve storia."],
|
@@ -347,13 +267,37 @@ def create_chat_interface():
|
|
347 |
cache_examples=False,
|
348 |
)
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
|
358 |
if __name__ == "__main__":
|
359 |
demo = create_chat_interface()
|
|
|
14 |
shell=True,
|
15 |
)
|
16 |
|
17 |
+
# Constants and model initialization code remains the same
|
18 |
MAX_MAX_NEW_TOKENS = 2048
|
19 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
20 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
21 |
|
|
|
22 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
23 |
model_id = "DeepMount00/Lexora-Lite-3B"
|
24 |
|
|
|
32 |
)
|
33 |
model.eval()
|
34 |
|
|
|
35 |
CUSTOM_CSS = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
.container {
|
37 |
max-width: 1000px !important;
|
38 |
margin: auto !important;
|
|
|
39 |
}
|
40 |
|
41 |
+
.header {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
margin-bottom: 1rem;
|
44 |
+
padding: 1rem;
|
45 |
}
|
46 |
|
47 |
+
.header h1 {
|
48 |
+
font-size: 2rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
font-weight: 600;
|
50 |
+
color: #1e293b;
|
51 |
+
margin-bottom: 0.5rem;
|
52 |
}
|
53 |
|
54 |
+
.header p {
|
55 |
+
color: #64748b;
|
56 |
+
font-size: 1rem;
|
57 |
}
|
58 |
|
|
|
59 |
.chat-container {
|
60 |
+
border-radius: 0.75rem;
|
|
|
61 |
background: white;
|
62 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
63 |
+
height: calc(100vh - 200px);
|
64 |
+
display: flex;
|
65 |
+
flex-direction: column;
|
66 |
}
|
67 |
|
68 |
+
.message-container {
|
69 |
+
padding: 1rem;
|
70 |
+
margin-bottom: 0.5rem;
|
|
|
|
|
|
|
|
|
71 |
}
|
72 |
|
73 |
.user-message {
|
74 |
+
background: #f8fafc;
|
75 |
+
border-left: 3px solid #2563eb;
|
76 |
+
padding: 1rem;
|
77 |
+
margin: 0.5rem 0;
|
78 |
+
border-radius: 0.5rem;
|
79 |
}
|
80 |
|
81 |
.assistant-message {
|
82 |
+
background: white;
|
83 |
+
border-left: 3px solid #64748b;
|
84 |
+
padding: 1rem;
|
85 |
+
margin: 0.5rem 0;
|
86 |
+
border-radius: 0.5rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
}
|
88 |
|
89 |
+
.controls-panel {
|
90 |
+
position: fixed;
|
91 |
+
right: 1rem;
|
92 |
+
top: 1rem;
|
93 |
+
width: 300px;
|
94 |
+
background: white;
|
95 |
+
padding: 1rem;
|
96 |
+
border-radius: 0.5rem;
|
97 |
+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
|
98 |
+
z-index: 1000;
|
99 |
+
display: none;
|
100 |
}
|
101 |
|
102 |
+
.controls-button {
|
103 |
+
position: fixed;
|
104 |
+
right: 1rem;
|
105 |
+
top: 1rem;
|
106 |
+
z-index: 1001;
|
107 |
background: #2563eb !important;
|
108 |
color: white !important;
|
109 |
+
padding: 0.5rem 1rem !important;
|
110 |
border-radius: 0.5rem !important;
|
111 |
+
font-size: 0.875rem !important;
|
112 |
+
font-weight: 500 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
}
|
114 |
|
115 |
+
.input-area {
|
116 |
+
border-top: 1px solid #e2e8f0;
|
117 |
+
padding: 1rem;
|
118 |
+
background: white;
|
119 |
+
border-radius: 0 0 0.75rem 0.75rem;
|
120 |
}
|
121 |
|
122 |
+
.textbox {
|
123 |
+
border: 1px solid #e2e8f0 !important;
|
|
|
124 |
border-radius: 0.5rem !important;
|
125 |
+
padding: 0.75rem !important;
|
126 |
+
font-size: 1rem !important;
|
127 |
+
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05) !important;
|
128 |
}
|
129 |
|
130 |
+
.textbox:focus {
|
131 |
+
border-color: #2563eb !important;
|
132 |
outline: none !important;
|
133 |
+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2) !important;
|
134 |
}
|
135 |
|
136 |
+
.submit-button {
|
137 |
+
background: #2563eb !important;
|
138 |
+
color: white !important;
|
139 |
+
padding: 0.5rem 1rem !important;
|
140 |
+
border-radius: 0.5rem !important;
|
141 |
+
font-size: 0.875rem !important;
|
142 |
+
font-weight: 500 !important;
|
143 |
+
transition: all 0.2s !important;
|
144 |
+
}
|
145 |
+
|
146 |
+
.submit-button:hover {
|
147 |
+
background: #1d4ed8 !important;
|
148 |
}
|
149 |
"""
|
150 |
|
|
|
151 |
DESCRIPTION = '''
|
152 |
+
<div class="header">
|
153 |
+
<h1>Lexora-Lite-3B Chat</h1>
|
154 |
+
<p>An advanced Italian language model ready to assist you</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
</div>
|
156 |
'''
|
157 |
|
158 |
+
# Generate function remains the same
|
159 |
@spaces.GPU(duration=90)
|
160 |
def generate(
|
161 |
message: str,
|
|
|
206 |
def create_chat_interface():
|
207 |
theme = gr.themes.Soft(
|
208 |
primary_hue="blue",
|
209 |
+
secondary_hue="slate",
|
210 |
neutral_hue="slate",
|
211 |
font=gr.themes.GoogleFont("Inter"),
|
212 |
radius_size=gr.themes.sizes.radius_sm,
|
213 |
)
|
214 |
|
215 |
with gr.Blocks(css=CUSTOM_CSS, theme=theme) as demo:
|
216 |
+
gr.Markdown(DESCRIPTION)
|
217 |
+
|
218 |
+
with gr.Row():
|
219 |
+
# Main chat column
|
220 |
+
with gr.Column(scale=3):
|
221 |
+
chat = gr.ChatInterface(
|
222 |
+
fn=generate,
|
223 |
+
additional_inputs=[
|
224 |
+
gr.Textbox(
|
225 |
+
value="",
|
226 |
+
label="System Message",
|
227 |
+
visible=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
),
|
229 |
gr.Slider(
|
230 |
label="Temperature",
|
231 |
minimum=0,
|
232 |
+
maximum=1.0,
|
233 |
step=0.1,
|
234 |
+
value=0.0001,
|
235 |
+
visible=False,
|
236 |
),
|
237 |
gr.Slider(
|
238 |
+
label="Top-p",
|
239 |
minimum=0.05,
|
240 |
maximum=1.0,
|
241 |
step=0.05,
|
242 |
value=1.0,
|
243 |
+
visible=False,
|
244 |
),
|
245 |
gr.Slider(
|
246 |
label="Top-k",
|
|
|
248 |
maximum=1000,
|
249 |
step=1,
|
250 |
value=50,
|
251 |
+
visible=False,
|
252 |
),
|
253 |
gr.Slider(
|
254 |
label="Repetition Penalty",
|
|
|
256 |
maximum=2.0,
|
257 |
step=0.05,
|
258 |
value=1.0,
|
259 |
+
visible=False,
|
260 |
),
|
261 |
+
],
|
|
|
|
|
|
|
|
|
262 |
examples=[
|
263 |
["Ciao! Come stai?"],
|
264 |
["Raccontami una breve storia."],
|
|
|
267 |
cache_examples=False,
|
268 |
)
|
269 |
|
270 |
+
# Advanced settings panel
|
271 |
+
with gr.Column(scale=1, visible=False) as settings_panel:
|
272 |
+
gr.Markdown("### Advanced Settings")
|
273 |
+
gr.Slider(
|
274 |
+
label="Temperature",
|
275 |
+
minimum=0,
|
276 |
+
maximum=1.0,
|
277 |
+
step=0.1,
|
278 |
+
value=0.0001,
|
279 |
+
)
|
280 |
+
gr.Slider(
|
281 |
+
label="Top-p",
|
282 |
+
minimum=0.05,
|
283 |
+
maximum=1.0,
|
284 |
+
step=0.05,
|
285 |
+
value=1.0,
|
286 |
+
)
|
287 |
+
gr.Slider(
|
288 |
+
label="Top-k",
|
289 |
+
minimum=1,
|
290 |
+
maximum=1000,
|
291 |
+
step=1,
|
292 |
+
value=50,
|
293 |
+
)
|
294 |
+
gr.Slider(
|
295 |
+
label="Repetition Penalty",
|
296 |
+
minimum=1.0,
|
297 |
+
maximum=2.0,
|
298 |
+
step=0.05,
|
299 |
+
value=1.0,
|
300 |
+
)
|
301 |
|
302 |
if __name__ == "__main__":
|
303 |
demo = create_chat_interface()
|