Molbap HF Staff commited on
Commit
164a34e
·
verified ·
1 Parent(s): 3ff0c13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -157
app.py CHANGED
@@ -93,6 +93,18 @@ def md_to_html(text: str) -> str:
93
  return md.markdown(text, extensions=exts, extension_configs=cfg, output_format="html5")
94
 
95
  def render_article(md_path: str, inserts: dict[str, callable]):
 
 
 
 
 
 
 
 
 
 
 
 
96
  raw = ""
97
  path = Path(md_path)
98
  if path.exists():
@@ -315,178 +327,82 @@ INSERTS = {
315
  # ---------------------------
316
 
317
  CSS = """
318
- /* Import Inter font like HF blog */
319
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
320
-
321
- :root {
322
- --toc-w: 280px;
323
- --text-color: #374151;
324
- --heading-color: #111827;
325
- --link-color: #2563eb;
326
  --border-color: #e5e7eb;
327
  }
328
 
329
- /* Main layout */
330
- #layout { display: grid; grid-template-columns: var(--toc-w) 1fr; gap: 2rem; }
331
- #toc {
332
- position: sticky;
333
- top: 1rem;
334
- height: calc(100vh - 2rem);
335
- overflow: auto;
336
- padding-right: 1rem;
337
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
338
- }
339
- #toc a {
340
- text-decoration: none;
341
- display: block;
342
- padding: 0.5rem 0;
343
- color: var(--text-color);
344
- font-size: 0.875rem;
345
- line-height: 1.25rem;
346
- }
347
- #toc a:hover { color: var(--link-color); }
348
-
349
- /* Container styling */
350
- .gradio-container {
351
- max-width: 1200px !important;
352
- margin: 0 auto !important;
353
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
354
- }
355
-
356
- /* Typography - matching HF blog style */
357
- .gradio-container h1 {
358
- font-size: 2.25rem !important;
359
- line-height: 2.5rem !important;
360
- font-weight: 700 !important;
361
- color: var(--heading-color) !important;
362
- margin: 2rem 0 1.5rem 0 !important;
363
- font-family: 'Inter', sans-serif !important;
364
- }
365
-
366
- .gradio-container h2 {
367
- font-size: 1.875rem !important;
368
- line-height: 2.25rem !important;
369
- font-weight: 600 !important;
370
- color: var(--heading-color) !important;
371
- margin: 2.5rem 0 1rem 0 !important;
372
- font-family: 'Inter', sans-serif !important;
373
- }
374
-
375
- .gradio-container h3 {
376
- font-size: 1.5rem !important;
377
- line-height: 2rem !important;
378
- font-weight: 600 !important;
379
- color: var(--heading-color) !important;
380
- margin: 2rem 0 0.75rem 0 !important;
381
- font-family: 'Inter', sans-serif !important;
382
- }
383
-
384
- .gradio-container h4 {
385
- font-size: 1.25rem !important;
386
- line-height: 1.75rem !important;
387
- font-weight: 600 !important;
388
- color: var(--heading-color) !important;
389
- margin: 1.5rem 0 0.5rem 0 !important;
390
- font-family: 'Inter', sans-serif !important;
391
  }
392
 
393
- /* Body text */
394
- .gradio-container p {
395
- font-size: 1rem !important;
396
- line-height: 1.75rem !important;
397
- font-weight: 400 !important;
398
- color: var(--text-color) !important;
399
- margin: 1.25rem 0 !important;
400
- font-family: 'Inter', sans-serif !important;
 
 
 
 
 
 
 
 
401
  }
402
 
403
- /* Lists */
404
- .gradio-container ul, .gradio-container ol {
405
- font-size: 1rem !important;
406
- line-height: 1.75rem !important;
407
- color: var(--text-color) !important;
408
- margin: 1.25rem 0 !important;
409
- padding-left: 1.5rem !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  }
411
-
412
- .gradio-container li {
413
- margin: 0.5rem 0 !important;
414
- }
415
-
416
- /* Links */
417
- .gradio-container a {
418
- color: var(--link-color) !important;
419
- text-decoration: underline !important;
420
- }
421
-
422
- .gradio-container a:hover {
423
- text-decoration: none !important;
424
- }
425
-
426
- /* Code blocks */
427
- .gradio-container pre {
428
- background-color: #f8fafc !important;
429
- border: 1px solid var(--border-color) !important;
430
- border-radius: 0.5rem !important;
431
- padding: 1rem !important;
432
- margin: 1.5rem 0 !important;
433
- overflow-x: auto !important;
434
- font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace !important;
435
- font-size: 0.875rem !important;
436
- line-height: 1.5rem !important;
437
- }
438
-
439
- .gradio-container code {
440
- background-color: #f1f5f9 !important;
441
- color: #475569 !important;
442
- padding: 0.125rem 0.375rem !important;
443
- border-radius: 0.25rem !important;
444
- font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace !important;
445
- font-size: 0.875rem !important;
446
  }
447
 
448
  /* Blockquotes */
449
- .gradio-container blockquote {
450
- border-left: 4px solid var(--link-color) !important;
451
- padding-left: 1rem !important;
452
- margin: 1.5rem 0 !important;
453
- font-style: italic !important;
454
- color: #64748b !important;
455
- }
456
 
457
- /* Images - add some spacing */
458
- .gradio-container img {
459
- margin: 1.5rem 0 !important;
460
- border-radius: 0.5rem !important;
461
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
462
- }
463
 
464
- /* Horizontal rules */
465
- hr {
466
- border: none !important;
467
- border-top: 1px solid var(--border-color) !important;
468
- margin: 2rem 0 !important;
469
- }
470
 
471
- /* Scroll margins for anchor links */
472
- .section {
473
- scroll-margin-top: 80px;
474
- }
475
 
476
- /* Improve readability with better max-width for text */
477
- .gradio-container > div > div {
478
- max-width: 65ch;
479
- }
480
-
481
- /* Interactive components styling */
482
- .gradio-container .gr-form {
483
- margin: 2rem 0 !important;
484
- }
485
-
486
- .gradio-container button {
487
- font-family: 'Inter', sans-serif !important;
488
- font-weight: 500 !important;
489
- }
490
  """
491
 
492
  with gr.Blocks(css=CSS, fill_height=True, title="Interactive Blog — Transformers Feature Showcase") as demo:
 
93
  return md.markdown(text, extensions=exts, extension_configs=cfg, output_format="html5")
94
 
95
  def render_article(md_path: str, inserts: dict[str, callable]):
96
+ raw = Path(md_path).read_text(encoding="utf-8") if Path(md_path).exists() else f"**Missing article**: `{md_path}`."
97
+ parts = re.split(r"\{\{([A-Z_]+)\}\}", raw)
98
+ with gr.Column():
99
+ for i, part in enumerate(parts):
100
+ if i % 2 == 0:
101
+ # Wrap prose in an article container for scoped CSS
102
+ gr.HTML(f'<div class="article">{md_to_html(part)}</div>')
103
+ else:
104
+ (inserts.get(part) or (lambda: gr.HTML(f"<p><em>Unknown insert: {part}</em></p>")))()
105
+
106
+
107
+ def old_render_article(md_path: str, inserts: dict[str, callable]):
108
  raw = ""
109
  path = Path(md_path)
110
  if path.exists():
 
327
  # ---------------------------
328
 
329
  CSS = """
330
+ /* Force light theme and readable defaults */
331
+ :root {
332
+ color-scheme: light;
333
+ --body-background-fill: #ffffff;
334
+ --body-text-color: #111827; /* near-black */
335
+ --heading-text-color: #0b1021;
336
+ --link-text-color: #1d4ed8;
 
337
  --border-color: #e5e7eb;
338
  }
339
 
340
+ /* Load Inter; if Google Fonts is blocked, the @font-face fallback is used */
341
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
342
+ @font-face {
343
+ font-family: 'Inter var';
344
+ font-style: normal;
345
+ font-weight: 100 900;
346
+ font-display: swap;
347
+ src: url('https://rsms.me/inter/font-files/Inter.var.woff2?v=3.19') format('woff2');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  }
349
 
350
+ html, body, .gradio-container { background: #fff !important; }
351
+ .gradio-container { font-family: 'Inter', 'Inter var', system-ui, -apple-system, Segoe UI, Roboto, sans-serif !important; }
352
+
353
+ /* Layout (don’t clamp all nested divs) */
354
+ #layout { display: grid; grid-template-columns: 280px 1fr; gap: 2rem; }
355
+ #toc { position: sticky; top: 1rem; height: calc(100vh - 2rem); overflow: auto; padding-right: 1rem; }
356
+ #toc a { display: block; padding: .5rem 0; color: #374151; font-size: .875rem; text-decoration: none; }
357
+ #toc a:hover { color: var(--link-text-color); }
358
+
359
+ /* Scope ALL article typography to .article to beat Gradio’s prose opacity */
360
+ .article,
361
+ .article :where(p, li, code, pre, blockquote, h1, h2, h3, h4, h5, h6, a, strong, em) {
362
+ color: var(--body-text-color) !important;
363
+ opacity: 1 !important;
364
+ -webkit-font-smoothing: antialiased;
365
+ -moz-osx-font-smoothing: grayscale;
366
  }
367
 
368
+ /* Article width and centering */
369
+ .article { max-width: 72ch; margin: 0 auto; }
370
+
371
+ /* Headings */
372
+ .article h1 { font-weight: 700; font-size: 2.25rem; line-height: 2.6rem; color: var(--heading-text-color) !important; margin: 2rem 0 1.25rem; }
373
+ .article h2 { font-weight: 600; font-size: 1.875rem; line-height: 2.25rem; color: var(--heading-text-color) !important; margin: 2rem 0 1rem; }
374
+ .article h3 { font-weight: 600; font-size: 1.5rem; line-height: 2rem; color: var(--heading-text-color) !important; margin: 1.5rem 0 .75rem; }
375
+
376
+ /* Body text and lists */
377
+ .article p, .article li { font-size: 1.02rem; line-height: 1.8rem; }
378
+ .article ul, .article ol { padding-left: 1.5rem; margin: 1rem 0; }
379
+ .article a { color: var(--link-text-color) !important; text-decoration: underline; }
380
+ .article a:hover { text-decoration: none; }
381
+
382
+ /* Code blocks and inline code */
383
+ .article pre {
384
+ background: #f8fafc; border: 1px solid var(--border-color); border-radius: 8px;
385
+ padding: 1rem; margin: 1.25rem 0; overflow-x: auto;
386
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
387
+ font-size: .92rem; line-height: 1.6rem;
388
  }
389
+ .article code {
390
+ background: #f1f5f9; color: #111827; padding: .15rem .35rem; border-radius: .25rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  }
392
 
393
  /* Blockquotes */
394
+ .article blockquote { border-left: 4px solid var(--link-text-color); padding-left: 1rem; margin: 1.25rem 0; color: #334155; }
 
 
 
 
 
 
395
 
396
+ /* Images inside article */
397
+ .article img { display: block; max-width: 100%; height: auto; margin: 1.25rem auto; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
 
 
 
 
398
 
399
+ /* Horizontal rule and anchor offset */
400
+ hr { border: 0; border-top: 1px solid var(--border-color); margin: 2rem 0; }
401
+ .section { scroll-margin-top: 80px; }
 
 
 
402
 
403
+ /* Keep widgets full width; don’t inherit article max-width */
404
+ .gr-form, .gr-panel, .gr-block { max-width: none; }
 
 
405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  """
407
 
408
  with gr.Blocks(css=CSS, fill_height=True, title="Interactive Blog — Transformers Feature Showcase") as demo: