-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
121 lines (93 loc) · 3.2 KB
/
main.py
File metadata and controls
121 lines (93 loc) · 3.2 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
Main entry point for LLM optimization platform.
Initializes the application and starts the appropriate service.
"""
import argparse
import sys
from typing import Optional
from config.settings import get_settings, create_directories
from utils.logging import setup_logging, get_logger
def setup_application():
"""Initialize the application with proper configuration."""
# Create necessary directories
create_directories()
# Setup logging
setup_logging()
logger = get_logger(__name__)
logger.info("LLM Optimization Platform starting up...")
# Validate configuration
settings = get_settings()
logger.info(f"Configuration loaded - Environment: {settings.flask_env}")
return settings
def run_api_server():
"""Run the Flask API server."""
logger = get_logger(__name__)
logger.info("Starting API server...")
try:
# Import here to avoid circular imports
from api.app import create_app
settings = get_settings()
app = create_app()
app.run(
host=settings.api_host,
port=settings.api_port,
debug=settings.flask_debug,
)
except ImportError:
logger.error("API module not yet implemented")
sys.exit(1)
def run_web_interface():
"""Run the Streamlit web interface."""
logger = get_logger(__name__)
logger.info("Starting web interface...")
try:
import subprocess
import os
settings = get_settings()
# Set Streamlit configuration
env = os.environ.copy()
env['STREAMLIT_SERVER_PORT'] = str(settings.streamlit_port)
env['STREAMLIT_SERVER_ADDRESS'] = '0.0.0.0'
# Run Streamlit app
subprocess.run([
'streamlit', 'run', 'web_interface/app.py',
'--server.port', str(settings.streamlit_port),
'--server.address', '0.0.0.0'
], env=env)
except FileNotFoundError:
logger.error("Streamlit not installed or web interface not implemented")
sys.exit(1)
def main():
"""Main application entry point."""
parser = argparse.ArgumentParser(description="LLM Optimization Platform")
parser.add_argument(
'service',
choices=['api', 'web', 'all'],
help='Service to run (api, web, or all)'
)
parser.add_argument(
'--config',
help='Path to configuration file',
default=None
)
args = parser.parse_args()
# Setup application
settings = setup_application()
logger = get_logger(__name__)
try:
if args.service == 'api':
run_api_server()
elif args.service == 'web':
run_web_interface()
elif args.service == 'all':
logger.info("Starting all services...")
# In a production environment, you'd use a process manager
# For now, we'll just start the API server
run_api_server()
except KeyboardInterrupt:
logger.info("Application shutdown requested")
except Exception as e:
logger.error(f"Application error: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()