-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
81 lines (66 loc) · 2.35 KB
/
setup.py
File metadata and controls
81 lines (66 loc) · 2.35 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Quick-start setup script:
1. Creates virtual environment
2. Installs dependencies
3. Creates .env from template
4. Initialises the database
5. Optionally downloads spaCy model
"""
import subprocess
import sys
import os
import shutil
from pathlib import Path
BASE = Path(__file__).parent
def run(cmd, **kw):
print(f"\n▶ {' '.join(cmd) if isinstance(cmd, list) else cmd}")
subprocess.run(cmd, check=True, **kw)
def main():
# Virtual environment
venv = BASE / "venv"
py = sys.executable
if not venv.exists():
print("Creating virtual environment…")
run([py, "-m", "venv", str(venv)])
# Determine venv python/pip
if sys.platform == "win32":
venv_py = str(venv / "Scripts" / "python.exe")
venv_pip = str(venv / "Scripts" / "pip.exe")
else:
venv_py = str(venv / "bin" / "python")
venv_pip = str(venv / "bin" / "pip")
# Install dependencies
print("\nInstalling Python dependencies…")
run([venv_pip, "install", "--upgrade", "pip"])
run([venv_pip, "install", "-r", str(BASE / "requirements.txt")])
# .env
env_example = BASE / ".env.example"
env_file = BASE / ".env"
if not env_file.exists() and env_example.exists():
shutil.copy(env_example, env_file)
print(f"\n✅ Created .env – edit it to set your TESSERACT_CMD and other settings.")
else:
print(f"\nℹ️ .env already exists – skipping.")
# Create directories
for d in ["uploads", "logs"]:
(BASE / d).mkdir(exist_ok=True)
# DB init
print("\nInitialising database…")
env = os.environ.copy()
env["PYTHONPATH"] = str(BASE)
run([venv_py, "-c", "from app.database import init_db; init_db(); print('DB ready.')"],
cwd=str(BASE), env=env)
# spaCy model (optional)
try:
run([venv_py, "-m", "spacy", "download", "en_core_web_sm"], cwd=str(BASE))
except Exception:
print("⚠️ Could not download spaCy model – NER will be skipped. Run manually:")
print(f" {venv_py} -m spacy download en_core_web_sm")
print("\n" + "="*60)
print("✅ Setup complete!")
print(f" Start the server: {venv_py} run.py")
print(" Dashboard: http://127.0.0.1:8000")
print(" API Docs: http://127.0.0.1:8000/api/docs")
print("="*60)
if __name__ == "__main__":
main()