Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import tabulate
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import networkx as nx
|
| 5 |
|
|
@@ -13,7 +12,6 @@ def parse(text):
|
|
| 13 |
|
| 14 |
dependency_tree = render_dependency_tree(output["forms"], output["heads"], output["deprel"])
|
| 15 |
table = render_table(output["forms"], output["lemmas"], output["upos"], output["xpos"], output["feats"], output["ne"])
|
| 16 |
-
table = gr.DataFrame(**table, interactive=False, datatype="markdown")
|
| 17 |
|
| 18 |
return dependency_tree, table
|
| 19 |
|
|
@@ -57,78 +55,6 @@ description = """
|
|
| 57 |
</div>
|
| 58 |
"""
|
| 59 |
|
| 60 |
-
text = """1 Forretten forrett NOUN _ Definite=Def|Gender=Masc|Number=Sing 2 nsubj _ name=O
|
| 61 |
-
2 lyder lyde VERB _ Mood=Ind|Tense=Pres|VerbForm=Fin 0 root _ name=O
|
| 62 |
-
3 navnet navn NOUN _ Definite=Def|Gender=Neut|Number=Sing 5 nmod _ name=O
|
| 63 |
-
4 " $" PUNCT _ _ 5 punct _ SpaceAfter=No|name=O
|
| 64 |
-
5 Coquilles Coquilles PROPN _ _ 2 obj _ name=B-PROD
|
| 65 |
-
6 St. St. PROPN _ _ 5 flat:name _ name=I-PROD
|
| 66 |
-
7 Jacques Jacques PROPN _ _ 5 flat:name _ name=I-PROD
|
| 67 |
-
8 Prince Prince PROPN _ _ 5 flat:name _ name=I-PROD
|
| 68 |
-
9 de de X _ _ 5 flat:name _ name=I-PROD
|
| 69 |
-
10 Norvege Norvege PROPN _ _ 5 flat:name _ SpaceAfter=No|name=I-PROD
|
| 70 |
-
11 " $" PUNCT _ _ 5 punct _ SpaceAfter=No|name=O
|
| 71 |
-
12 , $, PUNCT _ _ 5 punct _ name=O
|
| 72 |
-
13 som som PRON _ PronType=Rel 16 nsubj _ name=O
|
| 73 |
-
14 er være AUX _ Mood=Ind|Tense=Pres|VerbForm=Fin 16 cop _ name=O
|
| 74 |
-
15 grillet grille ADJ _ Definite=Ind|Gender=Neut|Number=Sing|VerbForm=Part 16 amod _ name=O
|
| 75 |
-
16 kamskjell kamskjell NOUN _ Definite=Ind|Gender=Neut|Number=Sing 5 acl:relcl _ name=O
|
| 76 |
-
17 på på ADP _ _ 19 case _ name=O
|
| 77 |
-
18 norsk norsk ADJ _ Definite=Ind|Degree=Pos|Number=Sing 19 amod _ name=O
|
| 78 |
-
19 spekeskinke spekeskinke NOUN _ Definite=Ind|Gender=Fem|Number=Sing 16 nmod _ name=O
|
| 79 |
-
20 - $- PUNCT _ _ 16 punct _ name=O
|
| 80 |
-
21 med med ADP _ _ 22 case _ name=O
|
| 81 |
-
22 trøffelhonningvinaigrette trøffelhonningvinaigrette NOUN _ Definite=Ind|Gender=Masc|Number=Sing 16 nmod _ SpaceAfter=No|name=O
|
| 82 |
-
23 , $, PUNCT _ _ 22 punct _ name=O
|
| 83 |
-
24 ruccolasalat ruccolasalat NOUN _ Definite=Ind|Gender=Masc|Number=Sing 22 conj _ name=O
|
| 84 |
-
25 og og CCONJ _ _ 27 cc _ name=O
|
| 85 |
-
26 ristede riste ADJ _ Number=Plur|VerbForm=Part 27 amod _ name=O
|
| 86 |
-
27 gresskarkjerner gresskarkjerne NOUN _ Definite=Ind|Gender=Fem|Number=Plur 22 conj _ SpaceAfter=No|name=O
|
| 87 |
-
28 . $. PUNCT _ _ 2 punct _ name=O"""
|
| 88 |
-
|
| 89 |
-
forms = [
|
| 90 |
-
line.split("\t")[1]
|
| 91 |
-
for line in text.split("\n")
|
| 92 |
-
if line and not line.startswith("#")
|
| 93 |
-
]
|
| 94 |
-
lemmas = [
|
| 95 |
-
line.split("\t")[2]
|
| 96 |
-
for line in text.split("\n")
|
| 97 |
-
if line and not line.startswith("#")
|
| 98 |
-
]
|
| 99 |
-
upos = [
|
| 100 |
-
line.split("\t")[3]
|
| 101 |
-
for line in text.split("\n")
|
| 102 |
-
if line and not line.startswith("#")
|
| 103 |
-
]
|
| 104 |
-
xpos = [
|
| 105 |
-
line.split("\t")[4]
|
| 106 |
-
for line in text.split("\n")
|
| 107 |
-
if line and not line.startswith("#")
|
| 108 |
-
]
|
| 109 |
-
feats = [
|
| 110 |
-
line.split("\t")[5]
|
| 111 |
-
for line in text.split("\n")
|
| 112 |
-
if line and not line.startswith("#")
|
| 113 |
-
]
|
| 114 |
-
ne = [
|
| 115 |
-
line.split("\t")[9].split('name=')[-1]
|
| 116 |
-
for line in text.split("\n")
|
| 117 |
-
if line and not line.startswith("#")
|
| 118 |
-
]
|
| 119 |
-
edges = [
|
| 120 |
-
int(line.split("\t")[6])
|
| 121 |
-
for line in text.split("\n")
|
| 122 |
-
if line and not line.startswith("#")
|
| 123 |
-
]
|
| 124 |
-
|
| 125 |
-
edge_labels = [
|
| 126 |
-
line.split("\t")[7]
|
| 127 |
-
for line in text.split("\n")
|
| 128 |
-
if line and not line.startswith("#")
|
| 129 |
-
]
|
| 130 |
-
|
| 131 |
-
print(ne, flush=True)
|
| 132 |
|
| 133 |
def render_table(forms, lemmas, upos, xpos, feats, named_entities):
|
| 134 |
feats = [[f"*{f.split('=')[0]}:* {f.split('=')[1]}" for f in (feat.split("|")) if '=' in f] for feat in feats]
|
|
@@ -159,8 +85,7 @@ def render_table(forms, lemmas, upos, xpos, feats, named_entities):
|
|
| 159 |
["*NE:*"] + named_entities_converted,
|
| 160 |
]
|
| 161 |
|
| 162 |
-
|
| 163 |
-
return {"value": array[1:], "headers": array[0]}
|
| 164 |
|
| 165 |
|
| 166 |
custom_css = \
|
|
@@ -193,8 +118,8 @@ with gr.Blocks(theme='sudeepshouche/minimalist', css=custom_css) as demo:
|
|
| 193 |
|
| 194 |
with gr.Column(scale=1, variant="panel"):
|
| 195 |
gr.Label("", show_label=False, container=False)
|
| 196 |
-
table = gr.DataFrame(
|
| 197 |
-
dependency_plot = gr.Plot(
|
| 198 |
|
| 199 |
source.submit(
|
| 200 |
fn=parse, inputs=[source], outputs=[dependency_plot, table], queue=True
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import networkx as nx
|
| 4 |
|
|
|
|
| 12 |
|
| 13 |
dependency_tree = render_dependency_tree(output["forms"], output["heads"], output["deprel"])
|
| 14 |
table = render_table(output["forms"], output["lemmas"], output["upos"], output["xpos"], output["feats"], output["ne"])
|
|
|
|
| 15 |
|
| 16 |
return dependency_tree, table
|
| 17 |
|
|
|
|
| 55 |
</div>
|
| 56 |
"""
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def render_table(forms, lemmas, upos, xpos, feats, named_entities):
|
| 60 |
feats = [[f"*{f.split('=')[0]}:* {f.split('=')[1]}" for f in (feat.split("|")) if '=' in f] for feat in feats]
|
|
|
|
| 85 |
["*NE:*"] + named_entities_converted,
|
| 86 |
]
|
| 87 |
|
| 88 |
+
return {"data": array[1:], "headers": array[0]}
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
custom_css = \
|
|
|
|
| 118 |
|
| 119 |
with gr.Column(scale=1, variant="panel"):
|
| 120 |
gr.Label("", show_label=False, container=False)
|
| 121 |
+
table = gr.DataFrame([["", "", "", ""] for _ in range(3)], headers=["", "", "", ""], interactive=False, datatype="markdown")
|
| 122 |
+
dependency_plot = gr.Plot(plt.subplots(figsize=(40, 16))[0], container=False)
|
| 123 |
|
| 124 |
source.submit(
|
| 125 |
fn=parse, inputs=[source], outputs=[dependency_plot, table], queue=True
|