Molbap HF Staff commited on
Commit
3cd87e0
·
1 Parent(s): 202b109

try to fix embedded graph

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -419,22 +419,29 @@ def build_d3_graph():
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;
@@ -445,10 +452,14 @@ def build_d3_graph():
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
 
 
419
  # Check if the HTML file exists
420
  html_file = Path("static/d3_dependency_graph.html")
421
  if html_file.exists():
422
+ # Read the HTML content
423
  html_content = html_file.read_text(encoding="utf-8")
424
 
425
+ # Extract only the body content (remove head tags that might cause issues)
426
+ body_match = re.search(r'<body.*?>(.*?)</body>', html_content, re.DOTALL)
427
+ if body_match:
428
+ body_content = body_match.group(1)
429
+ else:
430
+ body_content = html_content
431
+
432
+ # Get the script content
433
+ script_match = re.search(r'<script.*?>(.*?)</script>', html_content, re.DOTALL)
434
+ script_content = script_match.group(1) if script_match else ""
435
+
436
+ # Create a clean embedded version
437
  wrapped_html = f'''
438
+ <div id="d3-graph-container" style="width: 100%; height: 600px; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; background: white; position: relative;">
439
+ {body_content}
 
 
 
 
 
 
 
 
440
  </div>
441
+ <script src="https://d3js.org/d3.v7.min.js"></script>
442
+ <script>
443
+ {script_content}
444
+ </script>
445
  <style>
446
  #d3-graph-container svg {{
447
  width: 100% !important;
 
452
  top: 10px !important;
453
  left: 10px !important;
454
  z-index: 1000 !important;
455
+ background: rgba(255,255,255,0.9) !important;
456
+ padding: 12px !important;
457
+ border-radius: 6px !important;
458
+ font-size: 14px !important;
459
  }}
460
  </style>
461
  '''
462
+ gr.HTML(wrapped_html)
463
  else:
464
  gr.Markdown("⚠️ **D3 dependency graph not found.** The file `static/d3_dependency_graph.html` is missing.")
465