|
|
|
"""
|
|
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"""
|
|
|
|
app_path = "app.py"
|
|
if not os.path.exists(app_path):
|
|
print(f"Error: {app_path} not found")
|
|
return False
|
|
|
|
|
|
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
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...")
|
|
|
|
|
|
examples_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "examples")
|
|
os.makedirs(examples_dir, exist_ok=True)
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
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) |