Molbap HF Staff commited on
Commit
202b109
·
1 Parent(s): 833113a

enance code blocks

Browse files
Files changed (1) hide show
  1. app.py +97 -9
app.py CHANGED
@@ -411,10 +411,46 @@ def build_image(filename):
411
  return _build
412
 
413
  def build_d3_graph():
 
414
  with gr.Group():
415
- with open("static/d3_dependency_graph.html", "r") as f:
416
- html_content = f.read()
417
- gr.HTML(html_content, elem_id="d3-dependency-graph")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
 
419
  # ---------------------------
420
  # Inserts registry
@@ -487,15 +523,67 @@ html, body, .gradio-container { background: #fff !important; }
487
  .article a { color: var(--link-text-color) !important; text-decoration: underline; }
488
  .article a:hover { text-decoration: none; }
489
 
490
- /* Code */
491
  .article pre {
492
- background: #f8fafc; border: 1px solid var(--border-color); border-radius: 8px;
493
- padding: 1rem; margin: 1.25rem 0; overflow-x: auto;
494
- font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
495
- font-size: .95rem; line-height: 1.6rem; color: #0b0f19 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  }
 
 
497
  .article code {
498
- background: #e2e8f0; color: #0b0f19 !important; padding: .15rem .35rem; border-radius: .25rem; font-weight: 600;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
  }
500
 
501
  /* Blockquotes, images, rules */
 
411
  return _build
412
 
413
  def build_d3_graph():
414
+ """Build interactive D3 dependency graph."""
415
  with gr.Group():
416
+ gr.Markdown("### 🔗 Interactive Model Dependency Graph")
417
+ gr.Markdown("Explore how transformers models inherit from each other using the modular system. Click and drag nodes to interact!")
418
+
419
+ # Check if the HTML file exists
420
+ html_file = Path("static/d3_dependency_graph.html")
421
+ if html_file.exists():
422
+ # Read and modify the HTML content for direct embedding
423
+ html_content = html_file.read_text(encoding="utf-8")
424
+
425
+ # Wrap in a container with proper styling
426
+ wrapped_html = f'''
427
+ <div id="d3-graph-container" style="
428
+ width: 100%;
429
+ height: 600px;
430
+ border: 1px solid #e2e8f0;
431
+ border-radius: 8px;
432
+ overflow: hidden;
433
+ background: white;
434
+ position: relative;
435
+ ">
436
+ {html_content}
437
+ </div>
438
+ <style>
439
+ #d3-graph-container svg {{
440
+ width: 100% !important;
441
+ height: 100% !important;
442
+ }}
443
+ #d3-graph-container #legend {{
444
+ position: absolute !important;
445
+ top: 10px !important;
446
+ left: 10px !important;
447
+ z-index: 1000 !important;
448
+ }}
449
+ </style>
450
+ '''
451
+ gr.HTML(wrapped_html, elem_id="d3-dependency-graph")
452
+ else:
453
+ gr.Markdown("⚠️ **D3 dependency graph not found.** The file `static/d3_dependency_graph.html` is missing.")
454
 
455
  # ---------------------------
456
  # Inserts registry
 
523
  .article a { color: var(--link-text-color) !important; text-decoration: underline; }
524
  .article a:hover { text-decoration: none; }
525
 
526
+ /* Code blocks - HF blog style */
527
  .article pre {
528
+ background: #f8fafc !important;
529
+ border: 1px solid #e2e8f0 !important;
530
+ border-radius: 8px !important;
531
+ padding: 1.5rem !important;
532
+ margin: 2rem 0 !important;
533
+ overflow-x: auto !important;
534
+ font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Courier New', monospace !important;
535
+ font-size: 0.875rem !important;
536
+ line-height: 1.7 !important;
537
+ color: #1e293b !important;
538
+ box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06) !important;
539
+ }
540
+
541
+ /* Code block syntax highlighting */
542
+ .article pre code {
543
+ background: transparent !important;
544
+ color: #1e293b !important;
545
+ padding: 0 !important;
546
+ border-radius: 0 !important;
547
+ font-weight: 400 !important;
548
+ font-size: inherit !important;
549
+ line-height: inherit !important;
550
  }
551
+
552
+ /* Inline code */
553
  .article code {
554
+ background: #f1f5f9 !important;
555
+ color: #dc2626 !important;
556
+ padding: 0.125rem 0.375rem !important;
557
+ border-radius: 4px !important;
558
+ font-weight: 500 !important;
559
+ font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace !important;
560
+ font-size: 0.875rem !important;
561
+ }
562
+
563
+ /* Python syntax highlighting approximation */
564
+ .article pre code .hljs-keyword,
565
+ .article pre code .hljs-built_in {
566
+ color: #7c3aed !important; /* Purple for keywords */
567
+ font-weight: 600 !important;
568
+ }
569
+
570
+ .article pre code .hljs-string {
571
+ color: #059669 !important; /* Green for strings */
572
+ }
573
+
574
+ .article pre code .hljs-comment {
575
+ color: #6b7280 !important; /* Gray for comments */
576
+ font-style: italic !important;
577
+ }
578
+
579
+ .article pre code .hljs-number {
580
+ color: #dc2626 !important; /* Red for numbers */
581
+ }
582
+
583
+ .article pre code .hljs-class .hljs-title,
584
+ .article pre code .hljs-function .hljs-title {
585
+ color: #2563eb !important; /* Blue for class/function names */
586
+ font-weight: 600 !important;
587
  }
588
 
589
  /* Blockquotes, images, rules */