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

Simple launcher script for the ABSA Gradio application.

Provides different launch options for various use cases.

"""

import argparse
import sys
import os

def main():
    parser = argparse.ArgumentParser(description="Launch the ABSA Gradio Application")
    parser.add_argument(
        '--mode', 
        choices=['dev', 'prod', 'share'], 
        default='dev',
        help='Launch mode: dev (development), prod (production), share (public link)'
    )
    parser.add_argument('--port', type=int, default=7860, help='Port to run the server on')
    parser.add_argument('--host', default='127.0.0.1', help='Host to bind to')
    
    args = parser.parse_args()
    
    # Import here to avoid loading models during argument parsing
    try:
        from app import create_interface
        print("Loading ABSA models... This may take a few minutes on first run.")
        demo = create_interface()
        
        # Configure launch parameters based on mode
        launch_kwargs = {
            'server_port': args.port,
            'show_error': True
        }
        
        if args.mode == 'dev':
            launch_kwargs.update({
                'server_name': '127.0.0.1',
                'share': False,
                'debug': True
            })
            print(f"πŸš€ Starting in DEVELOPMENT mode on http://127.0.0.1:{args.port}")
            
        elif args.mode == 'prod':
            launch_kwargs.update({
                'server_name': '0.0.0.0',
                'share': False,
                'debug': False
            })
            print(f"πŸš€ Starting in PRODUCTION mode on http://0.0.0.0:{args.port}")
            
        elif args.mode == 'share':
            launch_kwargs.update({
                'server_name': '0.0.0.0',
                'share': True,
                'debug': False
            })
            print("πŸš€ Starting with PUBLIC LINK (share=True)")
            print("⚠️  The public link will be accessible from anywhere on the internet!")
        
        # Launch the application
        demo.launch(**launch_kwargs)
        
    except ImportError as e:
        print(f"❌ Error importing required modules: {e}")
        print("πŸ’‘ Make sure you've installed the requirements: pip install -r requirements.txt")
        sys.exit(1)
    except Exception as e:
        print(f"❌ Error starting the application: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()