crabz commited on
Commit
1a33777
1 Parent(s): e21886d
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -10,17 +10,17 @@ from transformers import pipeline
10
  import spacy
11
  from spacy import displacy
12
 
13
- POS_TAG_MAP = {0: "PODMET", 16: "PRÍSUDOK", 6: "PRÍDAVNÉ MENO", 2: "ADPOZÍCIA",
14
- 14: "PRÍSLOVKA", 17: "POMOCNÉ", 9: "KORDINAČNÁ SPOJKA", 8: "DETERMINANT",
15
- 15: "CYTOSLOVCIA", 3: "NUMERICKÉ", 7: "ČASTICA", 11: "ZÁMMENO",
16
- 10: "VLASTNÉ MENO", 1: "INTERPUNKCIA", 5: "PODRAĎOVACIA SPOJKA", 4: "SYMBÓL",
17
- 12: "INÉ", 13: "_"}
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-ner")
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 as e:
61
- print(e)
62
  return doc
63
 
64
 
65
  def apply_pos(Sentence: str):
66
- classifications = pipe(Sentence.replace(",", " ,")
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()