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()