""" Setup script for spaCy model download and TextBlob corpus. Run once after installing requirements.txt """ import subprocess import sys def run(cmd): print(f"Running: {' '.join(cmd)}") result = subprocess.run(cmd, capture_output=False) if result.returncode != 0: print(f"Warning: command returned non-zero exit code {result.returncode}") if __name__ == "__main__": print("=" * 50) print("Setting up Intelligent Document Processing API") print("=" * 50) # Download the best available spaCy model print("\n[1/3] Downloading spaCy NER model (en_core_web_lg)...") run([sys.executable, "-m", "spacy", "download", "en_core_web_lg"]) # Also grab transformer model as optional upgrade print("\n[2/3] Downloading TextBlob corpora...") run([sys.executable, "-c", "import textblob; textblob.download_corpora()"]) print("\n[3/3] Verifying installations...") try: import spacy nlp = spacy.load("en_core_web_lg") print(f" ✓ spaCy model loaded: {nlp.meta['name']}") except Exception as e: print(f" ✗ spaCy model issue: {e}") try: from transformers import pipeline print(" ✓ Transformers available") except Exception as e: print(f" ✗ Transformers issue: {e}") try: import pytesseract version = pytesseract.get_tesseract_version() print(f" ✓ Tesseract available: version {version}") except Exception as e: print(f" ✗ Tesseract not found: {e}") print(" → Install Tesseract: https://github.com/UB-Mannheim/tesseract/wiki") print("\nSetup complete! Start the API with:") print(" uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload")