Spaces:
Sleeping
Sleeping
Added spacy en_core_web_sm to build instead of lazy import
Browse files- frontend/text_analysis.py +11 -6
- requirements.txt +1 -0
frontend/text_analysis.py
CHANGED
|
@@ -59,12 +59,17 @@ def _load_models():
|
|
| 59 |
|
| 60 |
try:
|
| 61 |
nlp = spacy.load("en_core_web_sm")
|
| 62 |
-
except OSError:
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Sentence-Transformers and KeyBERT (which depends on it)
|
| 70 |
sent_trans = importlib.import_module("sentence_transformers")
|
|
|
|
| 59 |
|
| 60 |
try:
|
| 61 |
nlp = spacy.load("en_core_web_sm")
|
| 62 |
+
except OSError as exc:
|
| 63 |
+
# The model is missing. Do NOT attempt to install it at run-time
|
| 64 |
+
# because the app may run under a non-privileged user (e.g. Streamlit
|
| 65 |
+
# Cloud) and lack write permissions to the virtual-env. Instead we
|
| 66 |
+
# instruct the developer to add the model wheel to build-time
|
| 67 |
+
# dependencies so it gets installed by pip when the image is built.
|
| 68 |
+
raise RuntimeError(
|
| 69 |
+
"spaCy model 'en_core_web_sm' is not installed. "
|
| 70 |
+
"Add 'en-core-web-sm==3.8.0' (hyphen, not underscore) to "
|
| 71 |
+
"your requirements.txt so it is installed during deployment."
|
| 72 |
+
) from exc
|
| 73 |
|
| 74 |
# Sentence-Transformers and KeyBERT (which depends on it)
|
| 75 |
sent_trans = importlib.import_module("sentence_transformers")
|
requirements.txt
CHANGED
|
@@ -10,6 +10,7 @@ pyyaml
|
|
| 10 |
|
| 11 |
# Text analysis
|
| 12 |
spacy
|
|
|
|
| 13 |
scikit-learn
|
| 14 |
sentence-transformers
|
| 15 |
keybert
|
|
|
|
| 10 |
|
| 11 |
# Text analysis
|
| 12 |
spacy
|
| 13 |
+
en-core-web-sm==3.8.0
|
| 14 |
scikit-learn
|
| 15 |
sentence-transformers
|
| 16 |
keybert
|