-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_main.py
More file actions
72 lines (61 loc) · 1.87 KB
/
Copy pathserver_main.py
File metadata and controls
72 lines (61 loc) · 1.87 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
"""
Server main entry point - Run this on the inference server computer
"""
import argparse
import sys
import torch
from pathlib import Path
from config.configure import VALID_MODEL_NAMES
# Add the project root to Python path
sys.path.append(str(Path(__file__).parent))
from api.server import run_server
def main():
parser = argparse.ArgumentParser(description="ML Inference Server")
parser.add_argument(
"--host", type=str, default="0.0.0.0", help="Server host (default: 0.0.0.0)"
)
parser.add_argument(
"--port", type=int, default=8000, help="Server port (default: 8000)"
)
parser.add_argument(
"--workers", type=int, default=1, help="Number of worker processes (default: 1)"
)
parser.add_argument(
"--model",
type=str,
default="google/deeplabv3_mobilenet_v2_1.0_513",
choices=VALID_MODEL_NAMES,
help="model name for segmentation",
)
parser.add_argument(
"--device", type=str, default=None, help="Device for inference (cuda or cpu)"
)
args = parser.parse_args()
if not args.device:
device = "cuda" if torch.cuda.is_available() else "cpu"
else:
device = args.device
print("=" * 50)
print("ML INFERENCE SERVER")
print("=" * 50)
print(f"Host: {args.host}")
print(f"Port: {args.port}")
print(f"Workers: {args.workers}")
print(f"Model: {args.model}")
print(f"Device: {device}")
print(f"API Documentation: http://{args.host}:{args.port}/docs")
print("=" * 50)
try:
run_server(
host=args.host,
port=args.port,
workers=args.workers,
model_name=args.model,
device=device,
)
except KeyboardInterrupt:
print("\nServer stopped by user")
except Exception as e:
print(f"Server error: {e}")
if __name__ == "__main__":
main()