Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,18 +45,23 @@ def tokenize_sentence(text):
|
|
| 45 |
tokens = re.findall(r"[\w\u0370-\u03FF]+|[.,;:·!?]", text)
|
| 46 |
return [{"id": str(i+1), "form": t, "lemma": "", "postag": "Pontuação" if t in ".,;:·!?" else "Substantivo", "head": "0" if t in ".,;:·!?" else "", "relation": "AuxK" if (t in ".,;:·!?" and i==len(tokens)-1) else ("AuxX" if t in ".,;:·!?" else ""), "artificial": False} for i, t in enumerate(tokens)]
|
| 47 |
|
| 48 |
-
def render_tree(words
|
| 49 |
if not words: return None
|
| 50 |
-
|
|
|
|
| 51 |
dot.attr(rankdir='TB', nodesep='1.0', ranksep='0.8')
|
| 52 |
dot.attr('node', fontname="serif", shape='none')
|
| 53 |
dot.node("0", label="ROOT", fontcolor="red", fontsize="24")
|
|
|
|
| 54 |
for w in words:
|
| 55 |
txt_color = MORPHO_COLORS.get(w.get('postag', 'Substantivo'), "black")
|
| 56 |
label = f"<<table border='0' cellborder='0'><tr><td><font point-size='22' color='{txt_color}'><b>{w['form']}</b></font></td></tr><tr><td><font point-size='16' color='gray30'>{w['relation'] or '?'}</font></td></tr></table>>"
|
| 57 |
-
dot.node(w['id'], label)
|
| 58 |
-
dot.edge(w['head'] or "0", w['id'], color="#cccccc", penwidth='2.0')
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
def add_at(words):
|
|
@@ -89,7 +94,7 @@ with gr.Blocks(title="Arethusa Lite", css=custom_css) as demo:
|
|
| 89 |
btn_xml = gr.Button("📦 EXPORTAR XML")
|
| 90 |
out_file = gr.File(label="Download")
|
| 91 |
with gr.Column(scale=2):
|
| 92 |
-
svg_out = gr.
|
| 93 |
|
| 94 |
def process_start(text):
|
| 95 |
d = tokenize_sentence(text)
|
|
|
|
| 45 |
tokens = re.findall(r"[\w\u0370-\u03FF]+|[.,;:·!?]", text)
|
| 46 |
return [{"id": str(i+1), "form": t, "lemma": "", "postag": "Pontuação" if t in ".,;:·!?" else "Substantivo", "head": "0" if t in ".,;:·!?" else "", "relation": "AuxK" if (t in ".,;:·!?" and i==len(tokens)-1) else ("AuxX" if t in ".,;:·!?" else ""), "artificial": False} for i, t in enumerate(tokens)]
|
| 47 |
|
| 48 |
+
def render_tree(words):
|
| 49 |
if not words: return None
|
| 50 |
+
# Criamos o gráfico pedindo o formato SVG
|
| 51 |
+
dot = Digraph(format='svg')
|
| 52 |
dot.attr(rankdir='TB', nodesep='1.0', ranksep='0.8')
|
| 53 |
dot.attr('node', fontname="serif", shape='none')
|
| 54 |
dot.node("0", label="ROOT", fontcolor="red", fontsize="24")
|
| 55 |
+
|
| 56 |
for w in words:
|
| 57 |
txt_color = MORPHO_COLORS.get(w.get('postag', 'Substantivo'), "black")
|
| 58 |
label = f"<<table border='0' cellborder='0'><tr><td><font point-size='22' color='{txt_color}'><b>{w['form']}</b></font></td></tr><tr><td><font point-size='16' color='gray30'>{w['relation'] or '?'}</font></td></tr></table>>"
|
| 59 |
+
dot.node(str(w['id']), label)
|
| 60 |
+
dot.edge(str(w['head'] or "0"), str(w['id']), color="#cccccc", penwidth='2.0')
|
| 61 |
+
|
| 62 |
+
# O SEGREDO: Transformar o gráfico em uma string SVG que o HTML aceita
|
| 63 |
+
svg_data = dot.pipe(format='svg').decode('utf-8')
|
| 64 |
+
return svg_data
|
| 65 |
|
| 66 |
|
| 67 |
def add_at(words):
|
|
|
|
| 94 |
btn_xml = gr.Button("📦 EXPORTAR XML")
|
| 95 |
out_file = gr.File(label="Download")
|
| 96 |
with gr.Column(scale=2):
|
| 97 |
+
svg_out = gr.HTML()
|
| 98 |
|
| 99 |
def process_start(text):
|
| 100 |
d = tokenize_sentence(text)
|