Ryadg commited on
Commit
f72a551
Β·
1 Parent(s): d9f3227

fix: hero visible, polling replaces MutationObserver for Svelte compat

Browse files
Files changed (1) hide show
  1. app.py +52 -55
app.py CHANGED
@@ -24,7 +24,9 @@ except Exception as e:
24
  CSS = """
25
  /* ── Base ──────────────────────────────────────────────────────────────────── */
26
  footer { display: none !important; }
27
- header { display: none !important; }
 
 
28
  * { box-sizing: border-box; }
29
  body { background: #0A0F1E !important; margin: 0 !important; }
30
 
@@ -41,14 +43,19 @@ body { background: #0A0F1E !important; margin: 0 !important; }
41
  .contain { padding: 0 !important; }
42
  #component-0 { padding: 0 !important; }
43
 
44
- /* ── Centre upload row, stack components vertically ────────────────────────── */
45
  #upload-row {
46
  max-width: 760px !important;
47
- margin-left: auto !important;
48
- margin-right: auto !important;
49
- padding: 0 20px !important;
50
  flex-direction: column !important;
51
  gap: 12px !important;
 
 
 
 
 
 
52
  }
53
 
54
  /* ── Completely hide the thin-line rows (DOM still present for JS) ───────────── */
@@ -141,8 +148,11 @@ body { background: #0A0F1E !important; margin: 0 !important; }
141
  pointer-events: none !important;
142
  }
143
 
144
- /* ── feedback_box is standalone (not in a row) β€” hide it off-screen ────────── */
145
- #hidden-feedback-output {
 
 
 
146
  position: fixed !important;
147
  top: -9999px !important;
148
  left: -9999px !important;
@@ -298,35 +308,23 @@ with gr.Blocks(title="PaperProf", css=CSS) as demo:
298
 
299
  gr.HTML("""
300
  <script>
301
- document.addEventListener('DOMContentLoaded', function() {
302
-
303
  let lastStatus = '';
 
304
 
305
- // Inject status bar before quiz-card
306
  function ensureStatusBar() {
307
  if (document.getElementById('gradio-status-bar')) return;
308
- const quizCard = document.getElementById('quiz-card');
309
- if (!quizCard) return;
310
  const bar = document.createElement('div');
311
  bar.id = 'gradio-status-bar';
312
- bar.style.cssText = [
313
- 'display:none',
314
- 'max-width:760px',
315
- 'margin:0 auto',
316
- 'padding:12px 20px',
317
- 'border-radius:10px',
318
- 'font-size:.9rem',
319
- 'font-weight:500',
320
- 'font-family:Inter,system-ui,sans-serif',
321
- 'transition:all .3s ease',
322
- ].join(';');
323
- quizCard.parentNode.insertBefore(bar, quizCard);
324
  }
325
 
326
  function applyStatus(text) {
327
  if (text === lastStatus) return;
328
  lastStatus = text;
329
-
330
  ensureStatusBar();
331
  const bar = document.getElementById('gradio-status-bar');
332
  if (!bar) return;
@@ -339,44 +337,43 @@ document.addEventListener('DOMContentLoaded', function() {
339
 
340
  if (isError) {
341
  bar.style.background = 'rgba(239,68,68,0.12)';
342
- bar.style.border = '1px solid rgba(239,68,68,0.3)';
343
- bar.style.color = '#FCA5A5';
344
  } else if (isSuccess) {
345
  bar.style.background = 'rgba(16,185,129,0.12)';
346
- bar.style.border = '1px solid rgba(16,185,129,0.3)';
347
- bar.style.color = '#6EE7B7';
348
-
349
- // Reveal quiz card
350
- const quizCard = document.getElementById('quiz-card');
351
- if (quizCard) {
352
- quizCard.classList.remove('hidden');
353
- setTimeout(() => quizCard.scrollIntoView({ behavior: 'smooth', block: 'start' }), 300);
354
- }
355
-
356
- // Recede upload area β€” find the Gradio row that holds pdf_input + load_btn
357
- const gradioMain = document.querySelector('.gradio-container .main');
358
- if (gradioMain) {
359
- const rows = gradioMain.querySelectorAll(':scope > .flex > *, :scope > .gap > *');
360
- rows.forEach(row => {
361
- if (row.querySelector('[data-testid="upload-zone"], .file-drop-zone, #hidden-load-btn')) {
362
- row.classList.add('upload-receded');
363
- }
364
- });
365
  }
366
  } else {
367
  bar.style.background = 'rgba(6,182,212,0.12)';
368
- bar.style.border = '1px solid rgba(6,182,212,0.3)';
369
- bar.style.color = '#67E8F9';
370
  }
371
  }
372
 
373
- const observer = new MutationObserver(() => {
374
- const statusEl = document.querySelector('#hidden-status-output textarea');
375
- if (statusEl && statusEl.value) applyStatus(statusEl.value);
376
- });
377
-
378
- observer.observe(document.body, { childList: true, subtree: true, characterData: true });
379
- });
380
  </script>
381
  """)
382
 
 
24
  CSS = """
25
  /* ── Base ──────────────────────────────────────────────────────────────────── */
26
  footer { display: none !important; }
27
+ /* Only hide Gradio's own header chrome β€” NOT our custom <header class="hero"> */
28
+ .gradio-container > header,
29
+ .app > header { display: none !important; }
30
  * { box-sizing: border-box; }
31
  body { background: #0A0F1E !important; margin: 0 !important; }
32
 
 
43
  .contain { padding: 0 !important; }
44
  #component-0 { padding: 0 !important; }
45
 
46
+ /* ── Upload row: centred column, card look ──────────────────────────────────── */
47
  #upload-row {
48
  max-width: 760px !important;
49
+ margin: 0 auto !important;
50
+ padding: 20px !important;
 
51
  flex-direction: column !important;
52
  gap: 12px !important;
53
+ background: rgba(10,15,30,0.65) !important;
54
+ border: 1px solid rgba(255,255,255,0.08) !important;
55
+ border-radius: 18px !important;
56
+ backdrop-filter: blur(24px) !important;
57
+ -webkit-backdrop-filter: blur(24px) !important;
58
+ box-shadow: 0 8px 32px rgba(0,0,0,0.45) !important;
59
  }
60
 
61
  /* ── Completely hide the thin-line rows (DOM still present for JS) ───────────── */
 
148
  pointer-events: none !important;
149
  }
150
 
151
+ /* ── Standalone hidden components (no row wrapper) ──────────────────────────── */
152
+ #hidden-feedback-output,
153
+ #hidden-answer-input,
154
+ #hidden-submit-btn,
155
+ #hidden-question-btn {
156
  position: fixed !important;
157
  top: -9999px !important;
158
  left: -9999px !important;
 
308
 
309
  gr.HTML("""
310
  <script>
311
+ (function() {
 
312
  let lastStatus = '';
313
+ let quizRevealed = false;
314
 
 
315
  function ensureStatusBar() {
316
  if (document.getElementById('gradio-status-bar')) return;
317
+ const anchor = document.getElementById('quiz-card') || document.getElementById('app');
318
+ if (!anchor) return;
319
  const bar = document.createElement('div');
320
  bar.id = 'gradio-status-bar';
321
+ bar.style.cssText = 'display:none;max-width:760px;margin:8px auto 0;padding:12px 20px;border-radius:10px;font-size:.9rem;font-weight:500;font-family:Inter,system-ui,sans-serif;transition:all .3s ease;';
322
+ anchor.parentNode.insertBefore(bar, anchor);
 
 
 
 
 
 
 
 
 
 
323
  }
324
 
325
  function applyStatus(text) {
326
  if (text === lastStatus) return;
327
  lastStatus = text;
 
328
  ensureStatusBar();
329
  const bar = document.getElementById('gradio-status-bar');
330
  if (!bar) return;
 
337
 
338
  if (isError) {
339
  bar.style.background = 'rgba(239,68,68,0.12)';
340
+ bar.style.border = '1px solid rgba(239,68,68,0.3)';
341
+ bar.style.color = '#FCA5A5';
342
  } else if (isSuccess) {
343
  bar.style.background = 'rgba(16,185,129,0.12)';
344
+ bar.style.border = '1px solid rgba(16,185,129,0.3)';
345
+ bar.style.color = '#6EE7B7';
346
+
347
+ if (!quizRevealed) {
348
+ quizRevealed = true;
349
+ const quizCard = document.getElementById('quiz-card');
350
+ if (quizCard) {
351
+ quizCard.classList.remove('hidden');
352
+ setTimeout(() => quizCard.scrollIntoView({ behavior: 'smooth', block: 'start' }), 400);
353
+ }
354
+ // Recede upload row
355
+ const uploadRow = document.getElementById('upload-row');
356
+ if (uploadRow) {
357
+ uploadRow.style.opacity = '0.5';
358
+ uploadRow.style.transform = 'scale(0.97)';
359
+ uploadRow.style.transition = 'all .4s ease';
360
+ uploadRow.style.pointerEvents = 'none';
361
+ }
 
362
  }
363
  } else {
364
  bar.style.background = 'rgba(6,182,212,0.12)';
365
+ bar.style.border = '1px solid rgba(6,182,212,0.3)';
366
+ bar.style.color = '#67E8F9';
367
  }
368
  }
369
 
370
+ // Poll every 300ms β€” Svelte updates textarea.value as a property,
371
+ // which MutationObserver characterData does NOT catch.
372
+ setInterval(function() {
373
+ const el = document.querySelector('#hidden-status-output textarea');
374
+ if (el && el.value) applyStatus(el.value);
375
+ }, 300);
376
+ })();
377
  </script>
378
  """)
379