KingNish commited on
Commit
8cd17a1
·
1 Parent(s): ab7e40e

Better Hoem Page

Browse files
Files changed (2) hide show
  1. app.css +148 -12
  2. app.py +99 -2
app.css CHANGED
@@ -3,6 +3,8 @@
3
  --layout-gap: 0 !important;
4
  }
5
 
 
 
6
  html {
7
  scroll-behavior: smooth;
8
  }
@@ -18,6 +20,7 @@ html {
18
  flex-direction: column;
19
  padding: 0;
20
  overflow: hidden;
 
21
  }
22
 
23
  #chatbot {
@@ -135,18 +138,6 @@ label span {
135
  /* --- Input Area — Docked Bottom --- */
136
 
137
 
138
- /* Style the textbox wrapper to look like ChatGPT's input container */
139
- #input-row .form {
140
- box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
141
- transition: box-shadow 0.2s ease, border-color 0.2s ease !important;
142
- border: 1px solid var(--border-color-primary) !important;
143
- }
144
-
145
- #input-row .form:focus-within {
146
- box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
147
- border-color: var(--neutral-400) !important;
148
- }
149
-
150
  /* --- Send / Stop Button Micro-animations --- */
151
  #send-btn, #stop-btn {
152
  font-size: 0;
@@ -206,3 +197,148 @@ label span {
206
  background: var(--border-color-primary);
207
  border-radius: 2px;
208
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  --layout-gap: 0 !important;
4
  }
5
 
6
+ @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');
7
+
8
  html {
9
  scroll-behavior: smooth;
10
  }
 
20
  flex-direction: column;
21
  padding: 0;
22
  overflow: hidden;
23
+ position: relative;
24
  }
25
 
26
  #chatbot {
 
138
  /* --- Input Area — Docked Bottom --- */
139
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  /* --- Send / Stop Button Micro-animations --- */
142
  #send-btn, #stop-btn {
143
  font-size: 0;
 
197
  background: var(--border-color-primary);
198
  border-radius: 2px;
199
  }
200
+
201
+ .input-container textarea {
202
+ background: transparent !important;
203
+ }
204
+
205
+ /* ============================================
206
+ LANDING PAGE - Terminal-inspired Design
207
+ ============================================ */
208
+
209
+ #landing-page-container {
210
+ position: absolute;
211
+ top: 0;
212
+ left: 0;
213
+ right: 0;
214
+ bottom: 0;
215
+ display: flex;
216
+ align-items: center;
217
+ justify-content: center;
218
+ background: var(--background-fill-primary);
219
+ z-index: 10;
220
+ pointer-events: auto;
221
+ }
222
+
223
+ #landing-page {
224
+ width: 100%;
225
+ height: 100%;
226
+ display: flex;
227
+ align-items: center;
228
+ justify-content: center;
229
+ }
230
+
231
+ .landing-content {
232
+ display: flex;
233
+ flex-direction: column;
234
+ align-items: center;
235
+ gap: 32px;
236
+ padding: 40px;
237
+ max-width: 600px;
238
+ width: 100%;
239
+ }
240
+
241
+ /* Logo styling */
242
+ .landing-logo {
243
+ margin-bottom: 100px !important;
244
+ }
245
+
246
+ .landing-logo svg {
247
+ height: 60px;
248
+ width: auto;
249
+ filter: drop-shadow(0 0 20px rgba(241, 236, 236, 0.1));
250
+ }
251
+
252
+ /* Hide landing page when chat has messages */
253
+ #landing-page-container.hidden {
254
+ display: none !important;
255
+ }
256
+
257
+ /* ============================================
258
+ INPUT ROW - Terminal-style Global
259
+ ============================================ */
260
+
261
+ /* When landing page is visible, center the input row */
262
+ #chat-column.landing-active #input-row {
263
+ position: absolute;
264
+ top: 50%;
265
+ left: 50%;
266
+ transform: translateX(-50%);
267
+ width: 100%;
268
+ max-width: 600px;
269
+ z-index: 20;
270
+ }
271
+
272
+ /* When landing page is hidden (chat active), keep input at bottom */
273
+ #chat-column:not(.landing-active) #input-row {
274
+ position: relative;
275
+ bottom: auto;
276
+ left: auto;
277
+ transform: none;
278
+ max-width: none;
279
+ }
280
+
281
+ /* Terminal-style input row */
282
+ #input-row {
283
+ z-index: 15;
284
+ position: relative;
285
+ }
286
+
287
+ #input-row .form {
288
+ background: rgba(255, 255, 255, 0.03) !important;
289
+ border: 1px solid rgba(255, 255, 255, 0.1) !important;
290
+ border-radius: 8px !important;
291
+ font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace !important;
292
+ transition: all 0.2s ease !important;
293
+ }
294
+
295
+ #input-row .form:focus-within {
296
+ border-color: rgba(255, 255, 255, 0.3) !important;
297
+ background: rgba(255, 255, 255, 0.05) !important;
298
+ box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.05) !important;
299
+ }
300
+
301
+ /* Terminal cursor effect on input */
302
+ #input-row textarea,
303
+ #input-row input[type="text"] {
304
+ font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace !important;
305
+ caret-color: var(--body-text-color) !important;
306
+ caret-shape: block !important;
307
+ }
308
+
309
+ /* Blinking cursor animation for input */
310
+ @keyframes inputCursorBlink {
311
+ 0%, 50% { border-right-color: var(--body-text-color); }
312
+ 51%, 100% { border-right-color: transparent; }
313
+ }
314
+
315
+ /* Responsive adjustments */
316
+ @media (max-width: 768px) {
317
+ .landing-content {
318
+ padding: 20px;
319
+ gap: 24px;
320
+ }
321
+
322
+ .landing-logo svg {
323
+ height: 40px;
324
+ }
325
+ }
326
+
327
+ /* Apply monospace font to body for terminal feel */
328
+ body, .gradio-container {
329
+ font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace !important;
330
+ }
331
+
332
+ /* Chatbot styling when empty */
333
+ #chatbot:empty,
334
+ #chatbot .empty-state {
335
+ display: flex;
336
+ align-items: center;
337
+ justify-content: center;
338
+ height: 100%;
339
+ }
340
+
341
+ /* Ensure proper z-index stacking */
342
+ #chatbot {
343
+ z-index: 5;
344
+ }
app.py CHANGED
@@ -185,7 +185,6 @@ class GradioEvents:
185
  send_btn: gr.update(visible=True),
186
  stop_btn: gr.update(visible=False),
187
  }
188
- raise
189
 
190
  @staticmethod
191
  def new_chat(state_value):
@@ -302,6 +301,23 @@ with gr.Blocks(fill_width=True, title="Demo Chat") as demo:
302
 
303
  with gr.Column(elem_id="chat-column"):
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  chatbot = gr.Chatbot(
306
  elem_id="chatbot",
307
  show_label=False,
@@ -310,10 +326,11 @@ with gr.Blocks(fill_width=True, title="Demo Chat") as demo:
310
  )
311
  with gr.Row(elem_id="input-row"):
312
  msg = gr.Textbox(
313
- placeholder="Type a message and press Enter...",
314
  show_label=False,
315
  scale=4,
316
  container=False,
 
317
  )
318
  send_btn = gr.Button(
319
  "Send",
@@ -387,6 +404,86 @@ with gr.Blocks(fill_width=True, title="Demo Chat") as demo:
387
  fn=GradioEvents.load_from_js,
388
  inputs=[js_load_output, state],
389
  outputs=[conv_choice, state],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  )
391
 
392
  theme = gr.themes.Base(radius_size="none")
 
185
  send_btn: gr.update(visible=True),
186
  stop_btn: gr.update(visible=False),
187
  }
 
188
 
189
  @staticmethod
190
  def new_chat(state_value):
 
301
 
302
  with gr.Column(elem_id="chat-column"):
303
 
304
+ # Landing page shown when chat is empty
305
+ landing_page = gr.HTML(
306
+ value="""
307
+ <div id="landing-page">
308
+ <div class="landing-content">
309
+ <div class="landing-logo">
310
+ <svg width="300" height="42" viewBox="0 0 300 42" fill="none" xmlns="http://www.w3.org/2000/svg">
311
+ <path d="M0 6H24V12H0V6ZM0 12H6V18H0V12ZM18 12H24V18H18V12ZM30 6H54V12H30V6ZM30 12H36V18H30V12ZM30 36H36V42H30V36ZM48 12H54V18H48V12ZM60 6H84V12H60V6ZM60 12H66V18H60V12ZM78 12H84V18H78V12ZM90 6H114V12H90V6ZM90 12H96V18H90V12ZM108 12H114V18H108V12ZM120 6H150V12H120V6ZM120 12H126V18H120V12ZM132 12H138V18H132V12ZM144 12H150V18H144V12ZM156 6H162V18H156V6ZM174 6H180V18H174V6ZM174 36H180V42H174V36ZM186 6H210V12H186V6ZM192 0H198V6H192V0ZM192 12H198V18H192V12ZM216 0H222V12H216V0ZM216 12H240V18H216V12ZM246 6H270V12H246V6ZM246 12H252V18H246V12ZM264 12H270V18H264V12ZM276 6H300V12H276V6ZM276 12H282V18H276V12Z" fill="#F1ECEC"/>
312
+ <path d="M0 18H6V30H0V18ZM0 30H24V36H0V30ZM18 18H24V30H18V18ZM30 18H36V30H30V18ZM30 30H54V36H30V30ZM48 18H54V30H48V18ZM60 18H84V24H60V18ZM60 24H66V30H60V24ZM60 30H84V36H60V30ZM90 18H96V36H90V18ZM108 18H114V36H108V18ZM120 18H126V36H120V18ZM132 18H138V24H132V18ZM144 18H150V36H144V18ZM156 18H162V24H156V18ZM156 24H180V30H156V24ZM174 18H180V24H174V18ZM174 30H180V36H174V30ZM192 18H198V30H192V18ZM192 30H204V36H192V30ZM216 18H222V36H216V18ZM234 18H240V36H234V18ZM246 18H252V30H246V18ZM246 30H270V36H246V30ZM264 18H270V30H264V18ZM276 18H300V24H276V18ZM276 30H300V36H276V30ZM294 24H300V30H294V24Z" fill="#B7B1B1"/>
313
+ </svg>
314
+ </div>
315
+ </div>
316
+ </div>
317
+ """,
318
+ elem_id="landing-page-container",
319
+ )
320
+
321
  chatbot = gr.Chatbot(
322
  elem_id="chatbot",
323
  show_label=False,
 
326
  )
327
  with gr.Row(elem_id="input-row"):
328
  msg = gr.Textbox(
329
+ placeholder="Enter your message here...",
330
  show_label=False,
331
  scale=4,
332
  container=False,
333
+ max_lines=10,
334
  )
335
  send_btn = gr.Button(
336
  "Send",
 
404
  fn=GradioEvents.load_from_js,
405
  inputs=[js_load_output, state],
406
  outputs=[conv_choice, state],
407
+ ).then(
408
+ fn=None,
409
+ inputs=None,
410
+ outputs=None,
411
+ js="""
412
+ () => {
413
+ // Landing page toggle logic
414
+ const landingPage = document.getElementById('landing-page-container');
415
+ const chatbot = document.getElementById('chatbot');
416
+ const msgInput = document.querySelector('#input-row textarea, #input-row input[type="text"]');
417
+
418
+ if (!landingPage || !chatbot) return;
419
+
420
+ function toggleLanding() {
421
+ // Check if chatbot has any messages
422
+ const messages = chatbot.querySelectorAll('[data-testid="bot"], [data-testid="user"], [class*="message"]');
423
+ const hasMessages = messages.length > 0;
424
+
425
+ // Also check for empty state indicators
426
+ const emptyState = chatbot.querySelector('.empty-state, .placeholder, [class*="empty"]');
427
+ const chatColumn = document.getElementById('chat-column');
428
+
429
+ if (hasMessages && !emptyState) {
430
+ landingPage.classList.add('hidden');
431
+ if (chatColumn) chatColumn.classList.remove('landing-active');
432
+ } else {
433
+ landingPage.classList.remove('hidden');
434
+ if (chatColumn) chatColumn.classList.add('landing-active');
435
+ }
436
+ }
437
+
438
+ // Initial check
439
+ toggleLanding();
440
+
441
+ // Set up mutation observer to watch for chat changes
442
+ const observer = new MutationObserver((mutations) => {
443
+ let shouldToggle = false;
444
+ for (const mutation of mutations) {
445
+ if (mutation.type === 'childList' || mutation.type === 'subtree') {
446
+ shouldToggle = true;
447
+ break;
448
+ }
449
+ }
450
+ if (shouldToggle) {
451
+ // Debounce the toggle check
452
+ clearTimeout(window._landingToggleTimeout);
453
+ window._landingToggleTimeout = setTimeout(toggleLanding, 100);
454
+ }
455
+ });
456
+
457
+ observer.observe(chatbot, {
458
+ childList: true,
459
+ subtree: true,
460
+ attributes: true,
461
+ attributeFilter: ['class']
462
+ });
463
+
464
+ // Also watch for the input area to handle new chat creation
465
+ const inputRow = document.getElementById('input-row');
466
+ if (inputRow) {
467
+ observer.observe(inputRow, {
468
+ childList: true,
469
+ subtree: true
470
+ });
471
+ }
472
+
473
+ // Click on landing prompt to focus input
474
+ const landingPrompt = document.querySelector('.landing-prompt');
475
+ if (landingPrompt && msgInput) {
476
+ landingPrompt.addEventListener('click', () => {
477
+ msgInput.focus();
478
+ msgInput.click();
479
+ });
480
+ }
481
+
482
+ // Store reference for cleanup
483
+ window._landingPageObserver = observer;
484
+ window._landingPage = landingPage;
485
+ }
486
+ """,
487
  )
488
 
489
  theme = gr.themes.Base(radius_size="none")