File size: 725 Bytes
0e7e965 1344296 0e7e965 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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()
|