#!/usr/bin/env python3 """ Startup Script for Policy Analysis Application This script ensures all required models are downloaded before starting the application. """ import os import sys import subprocess from pathlib import Path def run_model_downloader(): """Run the model downloader script.""" script_dir = Path(__file__).parent downloader_script = script_dir / "download_models.py" if not downloader_script.exists(): print("❌ Model downloader script not found!") return False print("🚀 Ensuring all models are downloaded...") try: result = subprocess.run([sys.executable, str(downloader_script)], capture_output=True, text=True, check=True) print(result.stdout) return True except subprocess.CalledProcessError as e: print("❌ Error running model downloader:") print(e.stdout) print(e.stderr) return False def start_application(): """Start the main application.""" print("🌟 Starting Policy Analysis Application...") # Import and run the main app try: from app import demo demo.queue().launch(share=True, debug=True) except ImportError as e: print(f"❌ Failed to import app: {e}") sys.exit(1) if __name__ == "__main__": print("🤖 Policy Analysis Application Startup") print("=" * 50) # Download models first if not run_model_downloader(): print("⚠️ Model download failed, but continuing anyway...") # Start the application start_application()