DeepMount00 commited on
Commit
f24ac48
1 Parent(s): a71fb86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -184
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
- /* Header styles */
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
- .model-info p {
93
- color: #374151;
94
- line-height: 1.6;
95
- font-size: 1.1rem;
96
- }
97
-
98
- .model-info a {
99
- color: #2563eb;
100
  font-weight: 600;
101
- text-decoration: none;
102
- transition: color 0.2s;
103
  }
104
 
105
- .model-info a:hover {
106
- color: #1d4ed8;
107
- text-decoration: underline;
108
  }
109
 
110
- /* Chat container styles */
111
  .chat-container {
112
- border: 1px solid #e5e7eb;
113
- border-radius: 1rem;
114
  background: white;
115
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
116
- margin-bottom: 2rem;
 
 
117
  }
118
 
119
- /* Message styles */
120
- .message {
121
- padding: 1.25rem;
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: #f3f4f6;
130
- border-left: 4px solid #3b82f6;
 
 
 
131
  }
132
 
133
  .assistant-message {
134
- background: #dbeafe;
135
- border-left: 4px solid #1d4ed8;
136
- }
137
-
138
- /* Controls container styles */
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
- /* Slider styles */
148
- .slider-label {
149
- font-weight: 600;
150
- color: #374151;
151
- margin-bottom: 0.5rem;
152
- font-size: 1.05rem;
 
 
 
 
 
153
  }
154
 
155
- /* Button styles */
156
- .duplicate-button {
 
 
 
157
  background: #2563eb !important;
158
  color: white !important;
159
- padding: 0.875rem 1.75rem !important;
160
  border-radius: 0.5rem !important;
161
- font-weight: 600 !important;
162
- font-size: 1.05rem !important;
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
- .duplicate-button:hover {
174
- background: #1d4ed8 !important;
175
- transform: translateY(-1px) !important;
176
- box-shadow: 0 4px 6px rgba(37, 99, 235, 0.3) !important;
 
177
  }
178
 
179
- /* Input field styles */
180
- .input-textarea {
181
- border: 2px solid #e5e7eb !important;
182
  border-radius: 0.5rem !important;
183
- padding: 1rem !important;
184
- font-size: 1.05rem !important;
185
- transition: border-color 0.2s !important;
186
  }
187
 
188
- .input-textarea:focus {
189
- border-color: #3b82f6 !important;
190
  outline: none !important;
191
- box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
192
  }
193
 
194
- /* System message styles */
195
- .system-message {
196
- background: #f8fafc;
197
- border: 1px solid #e5e7eb;
198
- border-radius: 0.5rem;
199
- padding: 1rem;
200
- margin-bottom: 1rem;
 
 
 
 
 
201
  }
202
  """
203
 
204
- # HTML Description
205
  DESCRIPTION = '''
206
- <div class="header-container">
207
- <h1 class="header-title">Lexora-Lite-3B</h1>
208
- <div class="model-info">
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="blue",
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
- with gr.Column(elem_classes="container"):
281
- gr.Markdown(DESCRIPTION)
282
-
283
- with gr.Column(elem_classes="chat-container"):
284
- additional_inputs = [
285
- gr.Textbox(
286
- value="",
287
- label="System Message",
288
- elem_classes="system-message",
289
- render=False,
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=4.0,
309
  step=0.1,
310
- value=0.001,
311
- elem_classes="slider-label",
312
  ),
313
  gr.Slider(
314
- label="Top-p (Nucleus Sampling)",
315
  minimum=0.05,
316
  maximum=1.0,
317
  step=0.05,
318
  value=1.0,
319
- elem_classes="slider-label",
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
- elem_classes="slider-label",
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
- elem_classes="slider-label",
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
- gr.DuplicateButton(
351
- value="Duplicate Space for Private Use",
352
- elem_classes="duplicate-button",
353
- elem_id="duplicate-button",
354
- )
355
-
356
- return demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()