Spaces:
Runtime error
Runtime error
Added init_pln method
Browse files
utils.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import spacy
|
|
|
2 |
from typing import Tuple
|
3 |
from spacy import displacy
|
4 |
from anytree import Node, RenderTree
|
@@ -8,10 +9,30 @@ class Pipeline:
|
|
8 |
self
|
9 |
) -> None:
|
10 |
|
11 |
-
self.nlp =
|
12 |
self.__ch_html_tree = None
|
13 |
self.__ch_str_tree = None
|
14 |
self.__ch_sentence = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def __postag(
|
17 |
self,
|
|
|
1 |
import spacy
|
2 |
+
import subprocess
|
3 |
from typing import Tuple
|
4 |
from spacy import displacy
|
5 |
from anytree import Node, RenderTree
|
|
|
9 |
self
|
10 |
) -> None:
|
11 |
|
12 |
+
self.nlp = None
|
13 |
self.__ch_html_tree = None
|
14 |
self.__ch_str_tree = None
|
15 |
self.__ch_sentence = None
|
16 |
+
self.__init_nlp(model="en_core_web_md")
|
17 |
+
|
18 |
+
def __init_nlp(
|
19 |
+
self,
|
20 |
+
model: str
|
21 |
+
) -> None:
|
22 |
+
|
23 |
+
self.nlp = None
|
24 |
+
try:
|
25 |
+
self.nlp = spacy.load(model)
|
26 |
+
|
27 |
+
except:
|
28 |
+
print(f"* Downloading {model} model...")
|
29 |
+
_ = subprocess.Popen(
|
30 |
+
f"python -m spacy download {model}",
|
31 |
+
stdout=subprocess.PIPE,
|
32 |
+
shell=True
|
33 |
+
).communicate()
|
34 |
+
|
35 |
+
self.npl = spacy.load(model)
|
36 |
|
37 |
def __postag(
|
38 |
self,
|