-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
72 lines (59 loc) · 2.28 KB
/
Copy pathrun.py
File metadata and controls
72 lines (59 loc) · 2.28 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
"""
Main entry point for running the InsightForge-NLP API.
This script starts the FastAPI server with the InsightForge-NLP API.
"""
import os
import sys
import argparse
import logging
import uvicorn
from pathlib import Path
# Add project root to Python path
project_root = Path(__file__).parent.absolute()
sys.path.insert(0, str(project_root))
from app.common.config import Config
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def main():
"""Main function to run the InsightForge-NLP API."""
parser = argparse.ArgumentParser(description='InsightForge-NLP API')
parser.add_argument('--host', type=str, default='0.0.0.0',
help='Host to run the API server on')
parser.add_argument('--port', type=int, default=8000,
help='Port to run the API server on')
parser.add_argument('--reload', action='store_true',
help='Enable auto-reload for development')
parser.add_argument('--config', type=str, default=None,
help='Path to configuration file')
parser.add_argument('--log-level', type=str, default='INFO',
choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
help='Logging level')
args = parser.parse_args()
# Set logging level
logging.getLogger().setLevel(getattr(logging, args.log_level))
# Load configuration if provided
if args.config:
config = Config(args.config)
# Override with command line arguments
if args.host:
config.set('api.host', args.host)
if args.port:
config.set('api.port', args.port)
else:
# Use command line arguments directly
host = args.host
port = args.port
# Log startup information
logger.info(f"Starting InsightForge-NLP API on {args.host}:{args.port}")
logger.info(f"API documentation will be available at http://{args.host}:{args.port}/docs")
# Run the API server
uvicorn.run(
"app.api.main:app",
host=args.host,
port=args.port,
reload=args.reload,
log_level=args.log_level.lower()
)
if __name__ == "__main__":
main()