File size: 3,736 Bytes
72f90b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
"""
Simple startup script for the Language Detection App

This script provides an easy way to run the app with different configurations.
"""

import sys
import os
import argparse
from pathlib import Path

def check_dependencies():
    """Check if required dependencies are installed."""
    try:
        import gradio
        print("βœ… Gradio is available")
    except ImportError:
        print("❌ Gradio not found. Install with: pip install -r requirements.txt")
        return False
    
    return True

def run_tests():
    """Run the test suite."""
    print("πŸ§ͺ Running tests...")
    os.system("python test_app.py")

def run_app(model_type="placeholder", host="0.0.0.0", port=7860, share=False):
    """Run the main application."""
    
    if not check_dependencies():
        return 1
    
    # Set environment variables for configuration
    os.environ["MODEL_TYPE"] = model_type
    os.environ["HOST"] = host
    os.environ["PORT"] = str(port)
    os.environ["SHARE"] = str(share).lower()
    
    print(f"πŸš€ Starting Language Detection App...")
    print(f"πŸ“Š Model: {model_type}")
    print(f"🌐 Host: {host}:{port}")
    print(f"πŸ”— Share: {share}")
    print("-" * 50)
    
    # Import and run the app
    try:
        from app import main
        app = main()
        app.launch(
            server_name=host,
            server_port=port,
            share=share,
            debug=True
        )
    except KeyboardInterrupt:
        print("\nπŸ‘‹ App stopped by user")
    except Exception as e:
        print(f"❌ Error running app: {e}")
        return 1
    
    return 0

def main():
    """Main entry point."""
    parser = argparse.ArgumentParser(
        description="Language Detection App Runner",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:
  python run.py                          # Run with default settings
  python run.py --test                   # Run tests only
  python run.py --model huggingface      # Use Hugging Face model (if available)
  python run.py --port 8080              # Run on port 8080
  python run.py --share                  # Create public link
        """
    )
    
    parser.add_argument(
        "--test", 
        action="store_true",
        help="Run tests instead of starting the app"
    )
    
    parser.add_argument(
        "--model",
        choices=["placeholder", "huggingface", "custom"],
        default="placeholder",
        help="Model type to use (default: placeholder)"
    )
    
    parser.add_argument(
        "--host",
        default="0.0.0.0",
        help="Host to bind to (default: 0.0.0.0)"
    )
    
    parser.add_argument(
        "--port",
        type=int,
        default=7860,
        help="Port to bind to (default: 7860)"
    )
    
    parser.add_argument(
        "--share",
        action="store_true",
        help="Create a public link via Gradio"
    )
    
    args = parser.parse_args()
    
    print("🌍 Language Detection App Runner")
    print("=" * 40)
    
    if args.test:
        run_tests()
        return 0
    
    # Validate model choice
    if args.model == "huggingface":
        try:
            import transformers
            print("βœ… Transformers available for Hugging Face model")
        except ImportError:
            print("⚠️  Transformers not available. Install with:")
            print("   pip install transformers torch")
            print("   Falling back to placeholder model...")
            args.model = "placeholder"
    
    return run_app(
        model_type=args.model,
        host=args.host,
        port=args.port,
        share=args.share
    )

if __name__ == "__main__":
    sys.exit(main())