davda54
commited on
Commit
·
4a39fff
1
Parent(s):
144e6f4
add dependency tree plot
Browse files- app.py +32 -0
- requirements.txt +4 -1
app.py
CHANGED
@@ -1,5 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
import tabulate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
|
5 |
description = """
|
@@ -108,5 +139,6 @@ custom_css = \
|
|
108 |
with gr.Blocks(theme='sudeepshouche/minimalist', css=custom_css) as demo:
|
109 |
gr.HTML(description)
|
110 |
gr.DataFrame(**render_table(forms, lemmas, upos, xpos, feats, metadata, edges, edge_labels), interactive=False, datatype="markdown")
|
|
|
111 |
|
112 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import tabulate
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import networkx as nx
|
5 |
+
|
6 |
+
|
7 |
+
def render_dependency_tree(words, parents, labels):
|
8 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
9 |
+
|
10 |
+
# Create a directed graph
|
11 |
+
G = nx.DiGraph()
|
12 |
+
|
13 |
+
# Adding nodes to the graph
|
14 |
+
for i, word in enumerate(words):
|
15 |
+
G.add_node(i, label=word)
|
16 |
+
|
17 |
+
# Adding edges with labels
|
18 |
+
for i, (parent, label) in enumerate(zip(parents, labels)):
|
19 |
+
if parent != -1:
|
20 |
+
G.add_edge(parent, i, label=label)
|
21 |
+
|
22 |
+
# Position nodes using Graphviz
|
23 |
+
pos = nx.nx_agraph.graphviz_layout(G, prog='dot')
|
24 |
+
|
25 |
+
# Draw the graph
|
26 |
+
nx.draw(G, pos, ax=ax, with_labels=True, labels=nx.get_node_attributes(G, 'label'),
|
27 |
+
arrows=True, node_color='white', node_size=3000)
|
28 |
+
|
29 |
+
# Draw edge labels
|
30 |
+
edge_labels = nx.get_edge_attributes(G, 'label')
|
31 |
+
nx.draw_networkx_edge_labels(G, pos, ax=ax, edge_labels=edge_labels, rotate=False)
|
32 |
+
|
33 |
+
return fig
|
34 |
|
35 |
|
36 |
description = """
|
|
|
139 |
with gr.Blocks(theme='sudeepshouche/minimalist', css=custom_css) as demo:
|
140 |
gr.HTML(description)
|
141 |
gr.DataFrame(**render_table(forms, lemmas, upos, xpos, feats, metadata, edges, edge_labels), interactive=False, datatype="markdown")
|
142 |
+
gr.Plot(render_dependency_tree(forms, edges, edge_labels), interactive=False)
|
143 |
|
144 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
tabulate
|
|
|
|
|
|
|
|
1 |
+
tabulate
|
2 |
+
matplotlib
|
3 |
+
networkx
|
4 |
+
pygraphviz
|