#!/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()