Skip to content

Commit

Permalink
feat: added en-core-web-sm as en explicit dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik committed Nov 22, 2024
1 parent f69ae49 commit 6a994c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from collections import defaultdict
from functools import cache
Expand All @@ -22,11 +23,19 @@
"PRODUCT",
]

_log = logging.getLogger(__name__)


@cache
def _get_pipeline(model: str) -> Language:
download_model(model)
return load_model(model)
try:
return load_model(model)
except Exception as e:
_log.warning(
f"Failed to load spaCy model {model!r}: {str(e)}\nDownloading the model..."
)
download_model(model)
return load_model(model)


# Preemptively load the default model on the server start-up
Expand Down
21 changes: 19 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ aidial-sdk = { version = "^0.15.0", extras = ["telemetry"] }
aiostream = { version = "^0.6.2", optional = true }
pillow = { version = "^10.4.0", optional = true }
numpy = { version = "^1.26.1", optional = true }
spacy = { version = "^3.7.5", optional = true }
spacy = { version = "3.7.5", optional = true }

[tool.poetry.dependencies.en_core_web_sm]
# Pinning particular combination of Spacy and en_core_web_sm versions:
# https://github.com/explosion/spaCy/issues/13690#issuecomment-2487873386
# otherwise, have a change of running into 403 error in runtime.
url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl"
optional = true

[tool.poetry.extras]
examples = ["aiostream", "pillow", "numpy", "spacy"]
examples = ["aiostream", "pillow", "numpy", "spacy", "en_core_web_sm"]

[tool.poetry.group.test.dependencies]
pytest = "7.4.0"
Expand Down

0 comments on commit 6a994c6

Please sign in to comment.