Spaces:
Runtime error
Runtime error
fix bugs
Browse files
app.py
CHANGED
@@ -10,17 +10,17 @@ from transformers import pipeline
|
|
10 |
import spacy
|
11 |
from spacy import displacy
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
|
19 |
options = {"ents": list(POS_TAG_MAP.values()),
|
20 |
"colors": {"PODMET": "lightblue", "PRÍSUDOK": "lightcoral",
|
21 |
"PRÍDAVNÉ MENO": "lightgreen", "VLASTNÉ MENO": "papayawhip"}}
|
22 |
|
23 |
-
pipe = pipeline(task='token-classification', model="crabz/slovakbert-
|
24 |
nlp = spacy.blank("sk")
|
25 |
|
26 |
|
@@ -55,19 +55,14 @@ def set_entities(sentence, entities):
|
|
55 |
for label, start, end in entities:
|
56 |
ents.append(doc.char_span(start, end, label))
|
57 |
try:
|
58 |
-
print(ents)
|
59 |
doc.ents = ents
|
60 |
-
except TypeError
|
61 |
-
|
62 |
return doc
|
63 |
|
64 |
|
65 |
def apply_pos(Sentence: str):
|
66 |
-
classifications = pipe(Sentence
|
67 |
-
.replace(".", " .")
|
68 |
-
.replace("!", " !")
|
69 |
-
.replace("?", " ?")
|
70 |
-
.replace(":", " :"))
|
71 |
entities = postprocess(classifications)
|
72 |
print(entities)
|
73 |
doc = set_entities(Sentence, entities)
|
@@ -85,4 +80,4 @@ intf = gr.Interface(fn=apply_pos, inputs="text", outputs="html", title='Slovak P
|
|
85 |
description="",
|
86 |
article="",
|
87 |
analytics_enabled=False)
|
88 |
-
intf.launch()
|
|
|
10 |
import spacy
|
11 |
from spacy import displacy
|
12 |
|
13 |
+
|
14 |
+
POS_TAG_MAP = {"NOUN": "PODMET", "VERB": "PRÍSUDOK", "ADJ": "PRÍDAVNÉ MENO", "ADP": "ADPOZÍCIA",
|
15 |
+
"ADV": "PRÍSLOVKA", "AUX": "POMOCNÉ", "CCONJ": "KORDINAČNÁ KONJUKCIA", "DET": "DETERMINANT",
|
16 |
+
"INTJ": "CYTOSLOVCIA", "NUM": "NUMERICKÉ", "PART": "ČASTICA", "PRON": "ZÁMMENO",
|
17 |
+
"PROPN": "VLASTNÉ MENO", "PUNCT": "INTERPUNKCIA", "SCONJ": "", "SYM": "SYMBÓL", "X": "INÉ"}
|
18 |
|
19 |
options = {"ents": list(POS_TAG_MAP.values()),
|
20 |
"colors": {"PODMET": "lightblue", "PRÍSUDOK": "lightcoral",
|
21 |
"PRÍDAVNÉ MENO": "lightgreen", "VLASTNÉ MENO": "papayawhip"}}
|
22 |
|
23 |
+
pipe = pipeline(task='token-classification', model="crabz/slovakbert-upos")
|
24 |
nlp = spacy.blank("sk")
|
25 |
|
26 |
|
|
|
55 |
for label, start, end in entities:
|
56 |
ents.append(doc.char_span(start, end, label))
|
57 |
try:
|
|
|
58 |
doc.ents = ents
|
59 |
+
except TypeError:
|
60 |
+
pass
|
61 |
return doc
|
62 |
|
63 |
|
64 |
def apply_pos(Sentence: str):
|
65 |
+
classifications = pipe(Sentence)
|
|
|
|
|
|
|
|
|
66 |
entities = postprocess(classifications)
|
67 |
print(entities)
|
68 |
doc = set_entities(Sentence, entities)
|
|
|
80 |
description="",
|
81 |
article="",
|
82 |
analytics_enabled=False)
|
83 |
+
intf.launch()
|