File size: 2,733 Bytes
12f0afd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d03070
12f0afd
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
DD-POC Launch Script - Python Version
Simple script to start the Streamlit application with uv
"""

import os
import sys
import subprocess
from pathlib import Path


def check_uv_installation():
    """Check if uv is installed"""
    try:
        result = subprocess.run(['uv', '--version'],
                              capture_output=True,
                              text=True,
                              check=True)
        return True
    except (subprocess.CalledProcessError, FileNotFoundError):
        return False


def run_uv_command(command, cwd=None):
    """Run a uv command and return success status"""
    try:
        result = subprocess.run(['uv'] + command,
                              cwd=cwd,
                              check=True)
        return True
    except subprocess.CalledProcessError as e:
        print(f"❌ uv command failed: {' '.join(command)}")
        return False


def main():
    """Main launch function"""
    print("πŸš€ Starting DD-POC Application...")
    print("")

    # Check if uv is installed
    if not check_uv_installation():
        print("❌ Error: uv is not installed")
        print("   Please install uv: curl -LsSf https://astral.sh/uv/install.sh | sh")
        sys.exit(1)

    # Install dependencies if needed
    print("πŸ“¦ Ensuring dependencies are installed...")
    if not run_uv_command(['sync']):
        sys.exit(1)

    print("")
    print("🌐 Starting Streamlit server...")
    print("   App will open in your browser automatically")
    print("   Press Ctrl+C to stop the server")
    print("")

    # Enable tokenizers parallelism for better performance
    os.environ.setdefault("TOKENIZERS_PARALLELISM", "true")

    # Ensure we're in the project root directory
    script_dir = Path(__file__).parent
    project_root = script_dir.parent

    # Add current directory to Python path so app module can be found
    python_path = os.environ.get('PYTHONPATH', '')
    if python_path:
        python_path = f"{python_path}:{project_root}"
    else:
        python_path = str(project_root)

    # Set PYTHONPATH for the subprocess
    env = os.environ.copy()
    env['PYTHONPATH'] = python_path

    # Start the application with proper PYTHONPATH
    try:
        subprocess.run(['uv', 'run', 'python', '-m', 'streamlit', 'run', 'app/main.py'],
                      cwd=project_root,
                      env=env,
                      check=True)
    except KeyboardInterrupt:
        print("\nπŸ‘‹ Application stopped by user")
        sys.exit(0)
    except subprocess.CalledProcessError as e:
        print(f"❌ Failed to start Streamlit application: {e}")
        sys.exit(1)


if __name__ == "__main__":
    main()