Skip to content

Commit

Permalink
Added model download if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
fexfl committed Oct 24, 2024
1 parent b667a24 commit bf19133
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions mailcom/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,21 @@ def init_spacy(self, language: str, model="default"):
model, exclude=["morphologizer", "attribute_ruler", "lemmatizer", "ner"]
)
except OSError:
raise OSError("Could not find {} in standard directory.".format(model))

self.nlp_spacy = sp.load(model)
pass
try:
print(
"Could not find model in standard directory. Trying to download model from repo." # noqa
)
# try downloading model
sp.cli.download(model)
self.nlp_spacy = sp.load(
model,
exclude=["morphologizer", "attribute_ruler", "lemmatizer", "ner"],
)
except SystemExit:
raise SystemExit("Could not download {} from repo".format(model))
except OSError:
raise OSError("Could not find {} in standard directory".format(model))

def init_transformers(
self,
Expand Down
2 changes: 1 addition & 1 deletion mailcom/test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_default_fr():
def test_init_spacy(get_instant):
with pytest.raises(KeyError):
get_instant.init_spacy("not_a_language")
with pytest.raises(OSError):
with pytest.raises(SystemExit):
get_instant.init_spacy("fr", "not_an_existing_spacy_model")


Expand Down

0 comments on commit bf19133

Please sign in to comment.