vectorplasticity commited on
Commit
7fb9048
Β·
verified Β·
1 Parent(s): 4327377

Add application entry point

Browse files
Files changed (1) hide show
  1. run.py +102 -0
run.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Universal Model Trainer - Entry Point
4
+
5
+ Run the FastAPI application with Uvicorn server.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import uvicorn
11
+ import argparse
12
+ from pathlib import Path
13
+
14
+ # Add the project root to Python path
15
+ sys.path.insert(0, str(Path(__file__).parent))
16
+
17
+
18
+ def parse_args():
19
+ """Parse command line arguments."""
20
+ parser = argparse.ArgumentParser(
21
+ description="Universal Model Trainer - HuggingFace Spaces"
22
+ )
23
+ parser.add_argument(
24
+ "--host",
25
+ type=str,
26
+ default=os.getenv("HOST", "0.0.0.0"),
27
+ help="Host to bind the server to"
28
+ )
29
+ parser.add_argument(
30
+ "--port",
31
+ type=int,
32
+ default=int(os.getenv("PORT", 7860)),
33
+ help="Port to bind the server to"
34
+ )
35
+ parser.add_argument(
36
+ "--workers",
37
+ type=int,
38
+ default=int(os.getenv("WORKERS", 1)),
39
+ help="Number of worker processes"
40
+ )
41
+ parser.add_argument(
42
+ "--reload",
43
+ action="store_true",
44
+ default=os.getenv("RELOAD", "false").lower() == "true",
45
+ help="Enable auto-reload for development"
46
+ )
47
+ parser.add_argument(
48
+ "--log-level",
49
+ type=str,
50
+ default=os.getenv("LOG_LEVEL", "info"),
51
+ choices=["critical", "error", "warning", "info", "debug", "trace"],
52
+ help="Log level"
53
+ )
54
+ return parser.parse_args()
55
+
56
+
57
+ def main():
58
+ """Main entry point."""
59
+ args = parse_args()
60
+
61
+ print(f"""
62
+ ╔══════════════════════════════════════════════════════════════╗
63
+ β•‘ UNIVERSAL MODEL TRAINER - STARTING... β•‘
64
+ ╠══════════════════════════════════════════════════════════════╣
65
+ β•‘ Host: {args.host:<54} β•‘
66
+ β•‘ Port: {args.port:<54} β•‘
67
+ β•‘ Workers: {args.workers:<52} β•‘
68
+ β•‘ Log Level: {args.log_level:<49} β•‘
69
+ β•‘ Reload: {str(args.reload):<53} β•‘
70
+ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
71
+ """)
72
+
73
+ # Create necessary directories
74
+ directories = [
75
+ "uploads",
76
+ "models",
77
+ "logs",
78
+ "cache",
79
+ "checkpoints",
80
+ "app/static/css",
81
+ "app/static/js",
82
+ "app/templates"
83
+ ]
84
+
85
+ for directory in directories:
86
+ Path(directory).mkdir(parents=True, exist_ok=True)
87
+
88
+ # Run the server
89
+ uvicorn.run(
90
+ "app.main:app",
91
+ host=args.host,
92
+ port=args.port,
93
+ workers=args.workers,
94
+ reload=args.reload,
95
+ log_level=args.log_level,
96
+ access_log=True,
97
+ use_colors=True
98
+ )
99
+
100
+
101
+ if __name__ == "__main__":
102
+ main()