davda54 commited on
Commit
87bbff8
·
1 Parent(s): 982fd1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -19,6 +19,10 @@ def parse(text):
19
  def render_dependency_tree(words, parents, labels):
20
  fig, ax = plt.subplots(figsize=(40, 16))
21
 
 
 
 
 
22
  # Create a directed graph
23
  G = nx.DiGraph()
24
 
@@ -36,12 +40,12 @@ def render_dependency_tree(words, parents, labels):
36
 
37
  # Draw the graph
38
  nx.draw(G, pos, ax=ax, with_labels=True, labels=nx.get_node_attributes(G, 'label'),
39
- arrows=True, node_color='#ffffff', node_size=0, node_shape='s', font_size=30, bbox = dict(facecolor="white", pad=14)
40
  )
41
 
42
  # Draw edge labels
43
  edge_labels = nx.get_edge_attributes(G, 'label')
44
- nx.draw_networkx_edge_labels(G, pos, ax=ax, edge_labels=edge_labels, rotate=False, alpha=0.9, font_size=22)
45
 
46
  return fig
47
 
 
19
  def render_dependency_tree(words, parents, labels):
20
  fig, ax = plt.subplots(figsize=(40, 16))
21
 
22
+ main_font_size = 40 if len(words) < 10 else 30 if len(words) < 20 else 24 if len(words) < 40 else 16
23
+ minor_font_size = 30 if len(words) < 10 else 22 if len(words) < 20 else 16 if len(words) < 40 else 12
24
+ pad = main_font_size // 2
25
+
26
  # Create a directed graph
27
  G = nx.DiGraph()
28
 
 
40
 
41
  # Draw the graph
42
  nx.draw(G, pos, ax=ax, with_labels=True, labels=nx.get_node_attributes(G, 'label'),
43
+ arrows=True, node_color='#ffffff', node_size=0, node_shape='s', font_size=main_font_size, bbox = dict(facecolor="white", pad=pad)
44
  )
45
 
46
  # Draw edge labels
47
  edge_labels = nx.get_edge_attributes(G, 'label')
48
+ nx.draw_networkx_edge_labels(G, pos, ax=ax, edge_labels=edge_labels, rotate=False, alpha=1.0, font_size=minor_font_size)
49
 
50
  return fig
51