-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_api.py
More file actions
100 lines (86 loc) · 3.06 KB
/
run_api.py
File metadata and controls
100 lines (86 loc) · 3.06 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
"""
FastAPI server launcher for Prediction Analyzer
Usage:
python run_api.py [--host HOST] [--port PORT] [--reload]
Examples:
python run_api.py # Start on http://127.0.0.1:8000
python run_api.py --port 3000 # Start on http://127.0.0.1:3000
python run_api.py --reload # Start with auto-reload for development
python run_api.py --host 0.0.0.0 # Allow external connections
"""
import argparse
import importlib.util
import sys
def check_dependencies():
"""Check if required dependencies are installed"""
required = {
"fastapi": "fastapi",
"uvicorn": "uvicorn",
"sqlalchemy": "sqlalchemy",
"jwt": "PyJWT",
"passlib": "passlib",
"argon2": "argon2-cffi",
"pydantic_settings": "pydantic-settings",
}
missing = [
pip_name
for module, pip_name in required.items()
if importlib.util.find_spec(module) is None
]
if missing:
print("Missing required dependencies:")
for dep in missing:
print(f" - {dep}")
print("\nInstall with:")
print(" pip install -r requirements.txt")
sys.exit(1)
def main():
"""Run the FastAPI server"""
check_dependencies()
parser = argparse.ArgumentParser(
description="Run the Prediction Analyzer API server"
)
parser.add_argument(
"--host",
type=str,
default="127.0.0.1",
help="Host to bind to (default: 127.0.0.1)"
)
parser.add_argument(
"--port",
type=int,
default=8000,
help="Port to bind to (default: 8000)"
)
parser.add_argument(
"--reload",
action="store_true",
help="Enable auto-reload for development"
)
parser.add_argument(
"--workers",
type=int,
default=1,
help="Number of worker processes (default: 1)"
)
args = parser.parse_args()
import uvicorn
print(f"""
╔═══════════════════════════════════════════════════════════════╗
║ Prediction Analyzer API Server ║
╠═══════════════════════════════════════════════════════════════╣
║ Server running at: http://{args.host}:{args.port:<24}║
║ API Documentation: http://{args.host}:{args.port}/docs{' ' * 18}║
║ ReDoc: http://{args.host}:{args.port}/redoc{' ' * 17}║
╚═══════════════════════════════════════════════════════════════╝
""")
uvicorn.run(
"prediction_analyzer.api.main:app",
host=args.host,
port=args.port,
reload=args.reload,
workers=args.workers if not args.reload else 1,
)
if __name__ == "__main__":
main()