File size: 1,743 Bytes
de76d9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
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")