Tymec commited on
Commit
7ce074d
1 Parent(s): 308dcf9

Handle missing spacy model

Browse files
Files changed (1) hide show
  1. app/model.py +10 -2
app/model.py CHANGED
@@ -2,8 +2,8 @@ from __future__ import annotations
2
 
3
  import warnings
4
 
5
- import en_core_web_sm
6
  import numpy as np
 
7
  from joblib import Memory
8
  from sklearn.base import BaseEstimator, TransformerMixin
9
  from sklearn.feature_extraction.text import TfidfVectorizer
@@ -16,7 +16,15 @@ from app.constants import CACHE_DIR
16
 
17
  __all__ = ["create_model", "train_model", "evaluate_model"]
18
 
19
- nlp = en_core_web_sm.load(disable=["tok2vec", "parser", "ner"])
 
 
 
 
 
 
 
 
20
 
21
 
22
  class TextTokenizer(BaseEstimator, TransformerMixin):
 
2
 
3
  import warnings
4
 
 
5
  import numpy as np
6
+ import spacy
7
  from joblib import Memory
8
  from sklearn.base import BaseEstimator, TransformerMixin
9
  from sklearn.feature_extraction.text import TfidfVectorizer
 
16
 
17
  __all__ = ["create_model", "train_model", "evaluate_model"]
18
 
19
+ try:
20
+ nlp = spacy.load("en_core_web_sm", disable=["tok2vec", "parser", "ner"])
21
+ except OSError:
22
+ print("Downloading spaCy model...")
23
+
24
+ from spacy.cli import download as spacy_download
25
+
26
+ spacy_download("en_core_web_sm")
27
+ nlp = spacy.load("en_core_web_sm", disable=["tok2vec", "parser", "ner"])
28
 
29
 
30
  class TextTokenizer(BaseEstimator, TransformerMixin):