Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Launch script for LLM Code Analyzer | |
| Checks system requirements and starts the Streamlit app | |
| """ | |
| import sys | |
| import os | |
| import subprocess | |
| from pathlib import Path | |
| def check_requirements(): | |
| """Check if all requirements are met.""" | |
| print("π Checking system requirements...") | |
| # Check Python version | |
| if sys.version_info < (3, 11): | |
| print(f"β Python 3.11+ required, found {sys.version}") | |
| return False | |
| print(f"β Python {sys.version.split()[0]}") | |
| # Check if we're in the right directory | |
| if not Path("app.py").exists(): | |
| print("β app.py not found. Please run from project root directory.") | |
| return False | |
| print("β Project structure verified") | |
| # Check if analyzer module can be imported | |
| try: | |
| from analyzer import CodeAnalyzer | |
| analyzer = CodeAnalyzer() | |
| models = analyzer.available_models | |
| print(f"β Analyzer module loaded successfully") | |
| print(f"π Available models: {len(models)}") | |
| if not models: | |
| print("β οΈ No API keys configured in .env file") | |
| print(" Add at least one API key to use the analyzer") | |
| else: | |
| for key, name in models.items(): | |
| print(f" β’ {name}") | |
| except Exception as e: | |
| print(f"β Failed to load analyzer: {e}") | |
| return False | |
| # Check Streamlit | |
| try: | |
| import streamlit | |
| print(f"β Streamlit {streamlit.__version__}") | |
| except ImportError: | |
| print("β Streamlit not installed") | |
| return False | |
| return True | |
| def launch_app(): | |
| """Launch the Streamlit application.""" | |
| print("\nπ Starting LLM Code Analyzer...") | |
| print("=" * 50) | |
| try: | |
| # Start Streamlit | |
| cmd = [ | |
| sys.executable, "-m", "streamlit", "run", "app.py", | |
| "--server.headless", "true", | |
| "--server.port", "8501", | |
| "--server.address", "0.0.0.0" | |
| ] | |
| print("π± Application will be available at:") | |
| print(" β’ Local: http://localhost:8501") | |
| print(" β’ Network: http://0.0.0.0:8501") | |
| print("\nπ‘ Press Ctrl+C to stop the application") | |
| print("=" * 50) | |
| subprocess.run(cmd, check=True) | |
| except KeyboardInterrupt: | |
| print("\nπ Application stopped by user") | |
| except subprocess.CalledProcessError as e: | |
| print(f"β Failed to start application: {e}") | |
| return False | |
| except Exception as e: | |
| print(f"β Unexpected error: {e}") | |
| return False | |
| return True | |
| def main(): | |
| """Main entry point.""" | |
| print("π LLM Code Analyzer - Launcher") | |
| print("=" * 40) | |
| # Check requirements first | |
| if not check_requirements(): | |
| print("\nβ Requirements check failed") | |
| print("\nTo fix issues:") | |
| print("1. Ensure Python 3.11+ is installed") | |
| print("2. Run: pip install -r requirements.txt") | |
| print("3. Configure API keys in .env file") | |
| sys.exit(1) | |
| print("\nβ All requirements satisfied!") | |
| # Launch the app | |
| if not launch_app(): | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() |