DeepMount00 commited on
Commit
9a64687
·
verified ·
1 Parent(s): f24ac48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -221
app.py CHANGED
@@ -20,7 +20,7 @@ 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
 
25
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
26
  model = AutoModelForCausalLM.from_pretrained(
@@ -32,137 +32,13 @@ model = AutoModelForCausalLM.from_pretrained(
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,
162
  chat_history: list[tuple[str, str]],
163
  system_message: str = "",
164
- max_new_tokens: int = 2048,
165
- temperature: float = 0.0001,
166
  top_p: float = 1.0,
167
  top_k: int = 50,
168
  repetition_penalty: float = 1.0,
@@ -203,102 +79,62 @@ def generate(
203
  outputs.append(text)
204
  yield "".join(outputs)
205
 
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",
247
- minimum=1,
248
- maximum=1000,
249
- step=1,
250
- value=50,
251
- visible=False,
252
- ),
253
- gr.Slider(
254
- label="Repetition Penalty",
255
- minimum=1.0,
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."],
265
- ["Qual è il tuo piatto italiano preferito?"],
266
- ],
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()
304
  demo.queue(max_size=20).launch()
 
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-Medium-7B"
24
 
25
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
26
  model = AutoModelForCausalLM.from_pretrained(
 
32
  )
33
  model.eval()
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  @spaces.GPU(duration=90)
36
  def generate(
37
  message: str,
38
  chat_history: list[tuple[str, str]],
39
  system_message: str = "",
40
+ max_new_tokens: int = 1024,
41
+ temperature: float = 0.001,
42
  top_p: float = 1.0,
43
  top_k: int = 50,
44
  repetition_penalty: float = 1.0,
 
79
  outputs.append(text)
80
  yield "".join(outputs)
81
 
 
 
 
 
 
 
 
 
82
 
83
+ chat_interface = gr.ChatInterface(
84
+ fn=generate,
85
+ additional_inputs=[
86
+ gr.Textbox(
87
+ value="",
88
+ label="System message",
89
+ render=False,
90
+ ),
91
+ gr.Slider(
92
+ label="Max new tokens",
93
+ minimum=1,
94
+ maximum=MAX_MAX_NEW_TOKENS,
95
+ step=1,
96
+ value=DEFAULT_MAX_NEW_TOKENS,
97
+ ),
98
+ gr.Slider(
99
+ label="Temperature",
100
+ minimum=0,
101
+ maximum=4.0,
102
+ step=0.1,
103
+ value=0.001,
104
+ ),
105
+ gr.Slider(
106
+ label="Top-p (nucleus sampling)",
107
+ minimum=0.05,
108
+ maximum=1.0,
109
+ step=0.05,
110
+ value=1.0,
111
+ ),
112
+ gr.Slider(
113
+ label="Top-k",
114
+ minimum=1,
115
+ maximum=1000,
116
+ step=1,
117
+ value=50,
118
+ ),
119
+ gr.Slider(
120
+ label="Repetition penalty",
121
+ minimum=1.0,
122
+ maximum=2.0,
123
+ step=0.05,
124
+ value=1.0,
125
+ ),
126
+ ],
127
+ stop_btn=None,
128
+ examples=[
129
+ ["Ciao! Come stai?"],
130
+ ],
131
+ cache_examples=False,
132
+ )
133
 
134
+ with gr.Blocks(css="style.css", fill_height=True, theme="soft") as demo:
135
+ gr.Markdown(DESCRIPTION)
136
+ gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
137
+ chat_interface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  if __name__ == "__main__":
 
140
  demo.queue(max_size=20).launch()