#!/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)