redaction / api /setup_models.py
gni
feat: unified build for Hugging Face Spaces
1344296
raw
history blame contribute delete
725 Bytes
import spacy
import os
import subprocess
import sys
MODELS = ["en_core_web_lg", "fr_core_news_lg"]
def check_and_download():
for model in MODELS:
try:
print(f"🔍 Checking if {model} is installed...")
spacy.load(model)
print(f"✅ {model} is already present.")
except OSError:
print(f"📥 {model} not found. Downloading (this may take a few minutes)...")
# Using --user to ensure it goes into a writable directory for non-root users
subprocess.check_call([sys.executable, "-m", "spacy", "download", model, "--user"])
print(f"✨ {model} downloaded successfully.")
if __name__ == "__main__":
check_and_download()