Molbap HF Staff commited on
Commit
4c965e0
·
2 Parent(s): 6641fa8 a12858e

Merge branch 'main' of https://huggingface.co/spaces/Molbap/transformers-modular-refactor

Browse files
Files changed (2) hide show
  1. app.py +11 -10
  2. modular_graph_and_candidates.py +2 -33
app.py CHANGED
@@ -13,6 +13,17 @@ import gradio as gr
13
 
14
  from modular_graph_and_candidates import build_graph_json, generate_html, build_timeline_json, generate_timeline_html
15
 
 
 
 
 
 
 
 
 
 
 
 
16
  HF_MAIN_REPO = "https://github.com/huggingface/transformers"
17
 
18
  CACHE_REPO = "Molbap/hf_cached_embeds_log"
@@ -33,16 +44,6 @@ def _fetch_from_cache_repo(kind: str, sim_method: str, threshold: float, multimo
33
  return iframe_html, str(tmp)
34
 
35
 
36
- def _escape_srcdoc(text: str) -> str:
37
- """Escape for inclusion inside an <iframe srcdoc="…"> attribute."""
38
- return (
39
- text.replace("&", "&amp;")
40
- .replace("\"", "&quot;")
41
- .replace("'", "&#x27;")
42
- .replace("<", "&lt;")
43
- .replace(">", "&gt;")
44
- )
45
-
46
 
47
  def run_graph(repo_url: str, threshold: float, multimodal: bool, sim_method: str):
48
  return _fetch_from_cache_repo("graph", sim_method, threshold, multimodal)
 
13
 
14
  from modular_graph_and_candidates import build_graph_json, generate_html, build_timeline_json, generate_timeline_html
15
 
16
+ def _escape_srcdoc(text: str) -> str:
17
+ """Escape for inclusion inside an <iframe srcdoc="…"> attribute."""
18
+ return (
19
+ text.replace("&", "&amp;")
20
+ .replace("\"", "&quot;")
21
+ .replace("'", "&#x27;")
22
+ .replace("<", "&lt;")
23
+ .replace(">", "&gt;")
24
+ )
25
+
26
+
27
  HF_MAIN_REPO = "https://github.com/huggingface/transformers"
28
 
29
  CACHE_REPO = "Molbap/hf_cached_embeds_log"
 
44
  return iframe_html, str(tmp)
45
 
46
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  def run_graph(repo_url: str, threshold: float, multimodal: bool, sim_method: str):
49
  return _fetch_from_cache_repo("graph", sim_method, threshold, multimodal)
modular_graph_and_candidates.py CHANGED
@@ -685,7 +685,6 @@ function updateVisibility() {
685
  }
686
  document.getElementById('toggleRed').addEventListener('change', updateVisibility);
687
 
688
- const HF_LOGO_URI = "./static/hf-logo.png";
689
  const graph = __GRAPH_DATA__;
690
  const W = innerWidth, H = innerHeight;
691
  const svg = d3.select('#dependency').call(d3.zoom().on('zoom', e => g.attr('transform', e.transform)));
@@ -709,23 +708,7 @@ const node = g.selectAll('g.node')
709
  .call(d3.drag().on('start', dragStart).on('drag', dragged).on('end', dragEnd));
710
 
711
  const baseSel = node.filter(d => d.cls === 'base');
712
- if (HF_LOGO_URI){
713
- baseSel.append('image')
714
- .attr('href', HF_LOGO_URI)
715
- .attr('width', 40)
716
- .attr('height', 40)
717
- .attr('x', -20)
718
- .attr('y', -20)
719
- .on('error', function() {
720
- console.log('Image failed to load:', HF_LOGO_URI);
721
- // Fallback to circle
722
- d3.select(this.parentNode).append('circle')
723
- .attr('r', 22).attr('fill', '#ffbe0b');
724
- });
725
- console.log('Loading logo from:', HF_LOGO_URI);
726
- }else{
727
- baseSel.append('circle').attr('r', d => 22*d.sz).attr('fill', '#ffbe0b');
728
- }
729
  node.filter(d => d.cls !== 'base').append('circle').attr('r', d => 20*d.sz);
730
 
731
  node.append('text')
@@ -922,7 +905,6 @@ function updateVisibility() {
922
  }
923
  document.getElementById('toggleRed').addEventListener('change', updateVisibility);
924
 
925
- const HF_LOGO_URI = "./static/hf-logo.png";
926
  const timeline = __TIMELINE_DATA__;
927
  const W = innerWidth, H = innerHeight;
928
 
@@ -1003,20 +985,7 @@ const node = g.selectAll('g.node')
1003
  .call(d3.drag().on('start', dragStart).on('drag', dragged).on('end', dragEnd));
1004
 
1005
  const baseSel = node.filter(d => d.cls === 'base');
1006
- if (HF_LOGO_URI) {
1007
- baseSel.append('image')
1008
- .attr('href', HF_LOGO_URI)
1009
- .attr('width', 35)
1010
- .attr('height', 35)
1011
- .attr('x', -17.5)
1012
- .attr('y', -17.5)
1013
- .on('error', function() {
1014
- d3.select(this.parentNode).append('circle')
1015
- .attr('r', 20).attr('fill', '#ffbe0b');
1016
- });
1017
- } else {
1018
- baseSel.append('circle').attr('r', 20).attr('fill', '#ffbe0b');
1019
- }
1020
  node.filter(d => d.cls !== 'base').append('circle').attr('r', 18);
1021
 
1022
  node.append('text')
 
685
  }
686
  document.getElementById('toggleRed').addEventListener('change', updateVisibility);
687
 
 
688
  const graph = __GRAPH_DATA__;
689
  const W = innerWidth, H = innerHeight;
690
  const svg = d3.select('#dependency').call(d3.zoom().on('zoom', e => g.attr('transform', e.transform)));
 
708
  .call(d3.drag().on('start', dragStart).on('drag', dragged).on('end', dragEnd));
709
 
710
  const baseSel = node.filter(d => d.cls === 'base');
711
+ baseSel.append('circle').attr('r', d => 22*d.sz).attr('fill', '#ffbe0b');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  node.filter(d => d.cls !== 'base').append('circle').attr('r', d => 20*d.sz);
713
 
714
  node.append('text')
 
905
  }
906
  document.getElementById('toggleRed').addEventListener('change', updateVisibility);
907
 
 
908
  const timeline = __TIMELINE_DATA__;
909
  const W = innerWidth, H = innerHeight;
910
 
 
985
  .call(d3.drag().on('start', dragStart).on('drag', dragged).on('end', dragEnd));
986
 
987
  const baseSel = node.filter(d => d.cls === 'base');
988
+ baseSel.append('circle').attr('r', 20).attr('fill', '#ffbe0b');
 
 
 
 
 
 
 
 
 
 
 
 
 
989
  node.filter(d => d.cls !== 'base').append('circle').attr('r', 18);
990
 
991
  node.append('text')