File size: 3,638 Bytes
4862c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/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()