Lisa Dunlap
restart
4862c84
#!/usr/bin/env python3
"""
CLI launcher for LMM-Vibes Gradio visualization app.
Usage:
python -m lmmvibes.vis_gradio.launcher --results_dir path/to/results
Or directly:
python lmmvibes/vis_gradio/launcher.py --results_dir path/to/results
"""
import argparse
import sys
from pathlib import Path
def main():
parser = argparse.ArgumentParser(
description="Launch LMM-Vibes Gradio visualization app",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Launch with auto-loaded data from a base results directory
python -m lmmvibes.vis_gradio.launcher --results_dir /path/to/results
# Launch with public sharing enabled
python -m lmmvibes.vis_gradio.launcher --results_dir /path/to/results --share
# Launch on specific port
python -m lmmvibes.vis_gradio.launcher --results_dir /path/to/results --port 8080
# Launch with automatic port selection
python -m lmmvibes.vis_gradio.launcher --results_dir /path/to/results --auto_port
# Launch without auto-loading (manual selection in app)
python -m lmmvibes.vis_gradio.launcher
"""
)
parser.add_argument(
"--results_dir",
type=str,
help="Path to base results directory containing experiment subfolders (optional - can be loaded in the app)"
)
parser.add_argument(
"--share",
action="store_true",
help="Create a public shareable link"
)
parser.add_argument(
"--server_name",
type=str,
default="127.0.0.1",
help="Server address (default: 127.0.0.1)"
)
parser.add_argument(
"--port",
type=int,
default=7860,
help="Server port (default: 7860). Use --auto_port to automatically find an available port."
)
parser.add_argument(
"--auto_port",
action="store_true",
help="Automatically find an available port by trying ports 8080-8089"
)
parser.add_argument(
"--debug",
action="store_true",
help="Enable debug mode"
)
args = parser.parse_args()
# Handle auto_port option
if args.auto_port:
# Use a high port range for auto-port mode
args.port = 8080
print("πŸ” Auto-port mode enabled - will try ports 8080-8089")
# Validate results directory if provided
if args.results_dir:
results_path = Path(args.results_dir)
if not results_path.exists():
print(f"❌ Error: Results directory does not exist: {args.results_dir}")
sys.exit(1)
if not results_path.is_dir():
print(f"❌ Error: Path is not a directory: {args.results_dir}")
sys.exit(1)
# Import and launch the app
try:
from .app import launch_app
print("πŸš€ Launching LMM-Vibes Gradio Visualization App...")
print(f"🌐 Server: http://{args.server_name}:{args.port}")
if args.share:
print("πŸ”— Public sharing enabled")
launch_app(
results_dir=args.results_dir,
share=args.share,
server_name=args.server_name,
server_port=args.port,
debug=args.debug
)
except ImportError as e:
print(f"❌ Error: Failed to import required modules: {e}")
print("πŸ’‘ Make sure you have gradio installed: pip install gradio")
sys.exit(1)
except Exception as e:
print(f"❌ Error launching app: {e}")
sys.exit(1)
if __name__ == "__main__":
main()