Spaces:
Running
Running
File size: 1,392 Bytes
cbb53b6 | 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 | """CLI script to start the FastAPI server."""
import sys
from pathlib import Path
import argparse
import uvicorn
# Add project root to path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from mlpipeline.logging.logger import get_logger
logger = get_logger(__name__)
def main():
"""Start the FastAPI server."""
parser = argparse.ArgumentParser(description="Start AutoML API server")
parser.add_argument(
"--host",
type=str,
default="0.0.0.0",
help="Host to bind (default: 0.0.0.0)"
)
parser.add_argument(
"--port",
type=int,
default=8000,
help="Port to bind (default: 8000)"
)
parser.add_argument(
"--reload",
action="store_true",
help="Enable auto-reload for development"
)
args = parser.parse_args()
try:
logger.info(f"🚀 Starting FastAPI server at {args.host}:{args.port}")
logger.info(f"📚 API docs: http://{args.host if args.host != '0.0.0.0' else 'localhost'}:{args.port}/docs")
uvicorn.run(
"app.main:app",
host=args.host,
port=args.port,
reload=args.reload
)
return 0
except Exception as e:
logger.error(f"❌ Server failed to start: {e}")
return 1
if __name__ == "__main__":
exit(main())
|