File size: 1,607 Bytes
5d99375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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()