mac commited on
Commit
fb348b2
Β·
1 Parent(s): d6922a6

ui update

Browse files
Files changed (1) hide show
  1. app.py +265 -40
app.py CHANGED
@@ -103,35 +103,59 @@ def create_app():
103
  gr.set_static_paths(paths=[assets_path])
104
 
105
  with gr.Blocks() as demo:
106
- with gr.Row():
107
- with gr.Column(scale=1):
108
- gr.HTML(
109
- '<div class="logo-container">'
110
- '<img src="/gradio_api/file=assets/OpenBMB-MiniCPM.png" alt="MiniCPM Logo">'
111
- "</div>"
112
- )
113
- gr.HTML("<div style='height:1px;'></div>")
114
- temperature = gr.Slider(
115
- minimum=0, maximum=1, value=0.9, step=0.05, label="Temperature"
116
- )
117
- top_p = gr.Slider(
118
- minimum=0, maximum=1, value=0.95, step=0.01, label="Top-p"
119
- )
120
- enable_think = gr.Checkbox(label="Enable Thinking", value=True)
121
- gr.HTML("<div style='height:128px;'></div>")
122
- clear = gr.Button("Clear History")
123
 
124
- with gr.Column(scale=4):
 
125
  chatbot = gr.Chatbot(
126
- label="Chat History",
127
- placeholder="Input to start a new chat",
128
  height="70vh",
 
129
  )
130
  prompt = gr.Textbox(
131
- label="Input Text",
132
- placeholder="Type your message here...",
133
  lines=1,
134
- elem_classes=["input-box"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  )
136
 
137
  prompt.submit(
@@ -144,27 +168,228 @@ def create_app():
144
  return demo
145
 
146
 
147
- THEME = gr.themes.Soft(
148
- primary_hue="blue",
149
- secondary_hue="gray",
 
 
 
 
150
  neutral_hue="slate",
151
- font=[gr.themes.GoogleFont("Inter"), "Arial", "sans-serif"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  )
153
 
154
  CSS = """
155
- .logo-container {
156
- text-align: center;
157
- margin: 0.5rem 0 1rem 0;
158
- }
159
- .logo-container img {
160
- height: 96px;
161
- width: auto;
162
- max-width: 200px;
163
- display: inline-block;
164
- }
165
- .input-box {
166
- border: 1px solid #2f63b8;
167
- border-radius: 8px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
  """
170
 
 
103
  gr.set_static_paths(paths=[assets_path])
104
 
105
  with gr.Blocks() as demo:
106
+ # Header
107
+ gr.HTML(
108
+ '<div class="app-header">'
109
+ ' <div class="header-left">'
110
+ ' <img src="/gradio_api/file=assets/OpenBMB-MiniCPM.png" alt="Logo" class="header-logo">'
111
+ ' <div class="header-title">'
112
+ ' <span class="title-main">MiniCPM5-1B</span>'
113
+ ' <span class="title-sub">By OpenBMB</span>'
114
+ ' </div>'
115
+ ' </div>'
116
+ ' <div class="header-badge">'
117
+ ' <span class="status-dot"></span>'
118
+ ' MiniCPM5-1B'
119
+ ' </div>'
120
+ '</div>'
121
+ )
 
122
 
123
+ with gr.Row(elem_classes=["main-row"]):
124
+ with gr.Column(scale=4, elem_classes=["chat-col"]):
125
  chatbot = gr.Chatbot(
126
+ show_label=False,
127
+ placeholder="Send a message to start chatting...",
128
  height="70vh",
129
+ elem_classes=["dark-chatbot"],
130
  )
131
  prompt = gr.Textbox(
132
+ show_label=False,
133
+ placeholder="Ask MiniCPM5...",
134
  lines=1,
135
+ elem_classes=["input-pill"],
136
+ )
137
+
138
+ with gr.Column(scale=1, min_width=220, elem_classes=["settings-col"]):
139
+ gr.HTML('<div class="settings-title">Settings</div>')
140
+ temperature = gr.Slider(
141
+ minimum=0, maximum=1, value=0.9, step=0.05,
142
+ label="Temperature",
143
+ elem_classes=["dark-slider"],
144
+ )
145
+ top_p = gr.Slider(
146
+ minimum=0, maximum=1, value=0.95, step=0.01,
147
+ label="Top-p",
148
+ elem_classes=["dark-slider"],
149
+ )
150
+ enable_think = gr.Checkbox(
151
+ label="Enable Thinking",
152
+ value=True,
153
+ elem_classes=["dark-checkbox"],
154
+ )
155
+ clear = gr.Button(
156
+ "Clear History",
157
+ variant="secondary",
158
+ elem_classes=["clear-btn"],
159
  )
160
 
161
  prompt.submit(
 
168
  return demo
169
 
170
 
171
+ THEME = gr.themes.Base(
172
+ primary_hue=gr.themes.Color(
173
+ c50="#eef2ff", c100="#e0e7ff", c200="#c7d2fe", c300="#a5b4fc",
174
+ c400="#818cf8", c500="#6366f1", c600="#4f46e5", c700="#4338ca",
175
+ c800="#3730a3", c900="#312e81", c950="#1e1b4b",
176
+ ),
177
+ secondary_hue="slate",
178
  neutral_hue="slate",
179
+ font=[gr.themes.GoogleFont("Inter"), "system-ui", "sans-serif"],
180
+ ).set(
181
+ body_background_fill="#05070A",
182
+ body_background_fill_dark="#05070A",
183
+ body_text_color="#e2e8f0",
184
+ body_text_color_dark="#e2e8f0",
185
+ block_background_fill="rgba(255,255,255,0.03)",
186
+ block_background_fill_dark="rgba(255,255,255,0.03)",
187
+ block_border_color="rgba(255,255,255,0.08)",
188
+ block_border_color_dark="rgba(255,255,255,0.08)",
189
+ block_label_text_color="#94a3b8",
190
+ block_label_text_color_dark="#94a3b8",
191
+ block_title_text_color="#e2e8f0",
192
+ block_title_text_color_dark="#e2e8f0",
193
+ input_background_fill="rgba(255,255,255,0.04)",
194
+ input_background_fill_dark="rgba(255,255,255,0.04)",
195
+ input_border_color="rgba(255,255,255,0.08)",
196
+ input_border_color_dark="rgba(255,255,255,0.08)",
197
+ input_placeholder_color="#64748b",
198
+ input_placeholder_color_dark="#64748b",
199
+ button_primary_background_fill="linear-gradient(135deg, #3B5BFF, #27D4EA)",
200
+ button_primary_background_fill_dark="linear-gradient(135deg, #3B5BFF, #27D4EA)",
201
+ button_primary_text_color="#ffffff",
202
+ button_secondary_background_fill="rgba(255,255,255,0.06)",
203
+ button_secondary_background_fill_dark="rgba(255,255,255,0.06)",
204
+ button_secondary_text_color="#94a3b8",
205
+ button_secondary_border_color="rgba(255,255,255,0.1)",
206
+ button_secondary_border_color_dark="rgba(255,255,255,0.1)",
207
+ slider_color="#6366f1",
208
+ slider_color_dark="#6366f1",
209
+ checkbox_background_color="rgba(255,255,255,0.06)",
210
+ checkbox_background_color_dark="rgba(255,255,255,0.06)",
211
+ checkbox_border_color="rgba(255,255,255,0.15)",
212
+ checkbox_border_color_dark="rgba(255,255,255,0.15)",
213
+ checkbox_label_text_color="#cbd5e1",
214
+ checkbox_label_text_color_dark="#cbd5e1",
215
+ shadow_drop="none",
216
+ shadow_drop_lg="none",
217
  )
218
 
219
  CSS = """
220
+ /* Force dark background everywhere */
221
+ html, body, .gradio-container, .main, footer { background: #05070A !important; }
222
+ footer { display: none !important; }
223
+
224
+ /* Header */
225
+ .app-header {
226
+ display: flex;
227
+ align-items: center;
228
+ justify-content: space-between;
229
+ padding: 16px 24px;
230
+ border-bottom: 1px solid rgba(255,255,255,0.05);
231
+ }
232
+ .header-left {
233
+ display: flex;
234
+ align-items: center;
235
+ gap: 12px;
236
+ }
237
+ .header-logo {
238
+ width: 40px;
239
+ height: 40px;
240
+ border-radius: 10px;
241
+ filter: drop-shadow(0 0 12px rgba(39,212,234,0.35));
242
+ }
243
+ .header-title {
244
+ display: flex;
245
+ flex-direction: column;
246
+ }
247
+ .title-main {
248
+ font-size: 18px;
249
+ font-weight: 700;
250
+ letter-spacing: -0.02em;
251
+ background: linear-gradient(to right, #fff, rgba(255,255,255,0.6));
252
+ -webkit-background-clip: text;
253
+ -webkit-text-fill-color: transparent;
254
+ }
255
+ .title-sub {
256
+ font-size: 10px;
257
+ text-transform: uppercase;
258
+ letter-spacing: 0.2em;
259
+ color: rgba(255,255,255,0.35);
260
+ font-weight: 600;
261
+ }
262
+ .header-badge {
263
+ display: flex;
264
+ align-items: center;
265
+ gap: 6px;
266
+ font-size: 10px;
267
+ font-weight: 700;
268
+ letter-spacing: 0.12em;
269
+ text-transform: uppercase;
270
+ color: rgba(255,255,255,0.5);
271
+ background: rgba(255,255,255,0.04);
272
+ padding: 6px 14px;
273
+ border-radius: 100px;
274
+ border: 1px solid rgba(255,255,255,0.06);
275
+ }
276
+ .status-dot {
277
+ width: 6px;
278
+ height: 6px;
279
+ border-radius: 50%;
280
+ background: #27D4EA;
281
+ animation: pulse-dot 2s infinite;
282
+ }
283
+ @keyframes pulse-dot {
284
+ 0%, 100% { opacity: 1; }
285
+ 50% { opacity: 0.4; }
286
+ }
287
+
288
+ /* Layout */
289
+ .main-row { gap: 0 !important; }
290
+ .chat-col { padding-right: 8px !important; }
291
+ .settings-col {
292
+ border-left: 1px solid rgba(255,255,255,0.06) !important;
293
+ padding: 20px !important;
294
+ }
295
+ .settings-title {
296
+ font-size: 14px;
297
+ font-weight: 700;
298
+ color: rgba(255,255,255,0.7);
299
+ margin-bottom: 12px;
300
+ letter-spacing: 0.05em;
301
+ text-transform: uppercase;
302
+ }
303
+
304
+ /* Chatbot dark styling */
305
+ .dark-chatbot {
306
+ border: none !important;
307
+ background: transparent !important;
308
+ }
309
+ .dark-chatbot .wrapper { background: transparent !important; }
310
+ .dark-chatbot .bubble-wrap { background: transparent !important; }
311
+ .dark-chatbot .message-row {
312
+ animation: msg-fade-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
313
+ }
314
+ @keyframes msg-fade-in {
315
+ from { opacity: 0; transform: translateY(12px); }
316
+ to { opacity: 1; transform: translateY(0); }
317
+ }
318
+
319
+ /* User message bubble */
320
+ .dark-chatbot .role-user .message-bubble-border {
321
+ background: linear-gradient(135deg, #3B5BFF, #27D4EA) !important;
322
+ border: none !important;
323
+ border-radius: 20px 20px 4px 20px !important;
324
+ box-shadow: 0 6px 20px rgba(59,91,255,0.15);
325
+ }
326
+ .dark-chatbot .role-user .message-bubble-border .message-content {
327
+ color: #ffffff !important;
328
+ }
329
+
330
+ /* Bot message bubble */
331
+ .dark-chatbot .role-assistant .message-bubble-border {
332
+ background: rgba(255,255,255,0.03) !important;
333
+ border: 1px solid rgba(255,255,255,0.08) !important;
334
+ border-radius: 20px 20px 20px 4px !important;
335
+ backdrop-filter: blur(8px);
336
+ }
337
+ .dark-chatbot .role-assistant .message-bubble-border .message-content {
338
+ color: #e2e8f0 !important;
339
+ }
340
+
341
+ /* Thinking block (blockquote in bot messages) */
342
+ .dark-chatbot .role-assistant blockquote {
343
+ background: rgba(59,91,255,0.06) !important;
344
+ border-left: 3px solid #3B5BFF !important;
345
+ border-radius: 4px 10px 10px 4px;
346
+ padding: 10px 14px !important;
347
+ color: #8B949E !important;
348
+ font-style: italic;
349
+ margin-bottom: 10px !important;
350
+ }
351
+
352
+ /* Input pill */
353
+ .input-pill {
354
+ border: 1px solid rgba(255,255,255,0.08) !important;
355
+ border-radius: 24px !important;
356
+ background: rgba(255,255,255,0.04) !important;
357
+ backdrop-filter: blur(20px);
358
+ transition: all 0.3s ease;
359
+ }
360
+ .input-pill:focus-within {
361
+ border-color: rgba(99,102,241,0.4) !important;
362
+ background: rgba(255,255,255,0.06) !important;
363
+ box-shadow: 0 0 30px rgba(99,102,241,0.06);
364
+ }
365
+ .input-pill textarea, .input-pill input {
366
+ background: transparent !important;
367
+ border: none !important;
368
+ color: #e2e8f0 !important;
369
+ }
370
+
371
+ /* Settings controls */
372
+ .dark-slider input[type="range"] {
373
+ accent-color: #6366f1;
374
+ }
375
+ .clear-btn button {
376
+ border-radius: 12px !important;
377
+ transition: all 0.2s ease;
378
+ }
379
+ .clear-btn button:hover {
380
+ background: rgba(255,255,255,0.1) !important;
381
+ color: #fff !important;
382
+ }
383
+
384
+ /* Code blocks in chat */
385
+ .dark-chatbot pre {
386
+ background: rgba(0,0,0,0.4) !important;
387
+ border: 1px solid rgba(255,255,255,0.06) !important;
388
+ border-radius: 10px !important;
389
+ color: #e2e8f0 !important;
390
+ }
391
+ .dark-chatbot code {
392
+ color: #a5b4fc !important;
393
  }
394
  """
395