Spaces:
Sleeping
Sleeping
File size: 3,255 Bytes
646ba30 | 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 | #!/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() |