File size: 2,256 Bytes
53766b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""

Launcher script for the Image Tagger application.

"""
import os
import sys
import subprocess
import webbrowser
import time
from pathlib import Path

def run_app():
    """Run the Streamlit app"""
    # Check if app.py exists
    app_path = "app.py"
    if not os.path.exists(app_path):
        print(f"Error: {app_path} not found")
        return False
    
    # Get parent directory path (where venv is located)
    parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    
    # Get the path to streamlit in the virtual environment (in parent directory)
    if sys.platform == "win32":
        streamlit_path = os.path.join(parent_dir, "venv", "Scripts", "streamlit.exe")
    else:
        streamlit_path = os.path.join(parent_dir, "venv", "bin", "streamlit")
    
    if not os.path.exists(streamlit_path):
        print(f"Error: Streamlit not found at {streamlit_path}")
        print("Make sure you've run setup.py first to create the virtual environment")
        return False
    
    print("=" * 60)
    print("      Starting Image Tagger Application")
    print("=" * 60)
    
    print("\nLaunching the web interface...")
    
    # Create a directory for example images if it doesn't exist
    examples_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "examples")
    os.makedirs(examples_dir, exist_ok=True)
    
    # Check if there are example images
    example_files = [f for f in os.listdir(examples_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
    if not example_files:
        print("\nTip: Add some example images to the 'examples' directory for testing")
    
    # Run Streamlit app - using streamlit's built-in browser opening
    # This avoids the double browser opening issue
    try:
        command = [streamlit_path, "run", app_path]
        subprocess.run(command, check=True)
        return True
    except subprocess.CalledProcessError as e:
        print(f"Error running the app: {e}")
        return False
    except KeyboardInterrupt:
        print("\nApplication stopped by user")
        return True

if __name__ == "__main__":
    success = run_app()
    sys.exit(0 if success else 1)