File size: 2,703 Bytes
acd8e16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Launch script for the NL→SQL Leaderboard
"""

import os
import sys
import subprocess
from pathlib import Path


def check_requirements():
    """Check if all requirements are installed."""
    try:
        import gradio
        import pandas
        import duckdb
        import sqlglot
        import yaml
        print("✓ All required packages are installed")
        return True
    except ImportError as e:
        print(f"✗ Missing required package: {e}")
        print("Please install requirements: pip install -r requirements.txt")
        return False


def check_config():
    """Check if configuration files exist."""
    required_files = [
        "config/models.yaml",
        "prompts/template_presto.txt",
        "prompts/template_bigquery.txt", 
        "prompts/template_snowflake.txt",
        "tasks/nyc_taxi_small/schema.sql",
        "tasks/nyc_taxi_small/loader.py",
        "tasks/nyc_taxi_small/cases.yaml"
    ]
    
    missing_files = []
    for file_path in required_files:
        if not os.path.exists(file_path):
            missing_files.append(file_path)
    
    if missing_files:
        print("✗ Missing required files:")
        for file_path in missing_files:
            print(f"  - {file_path}")
        return False
    else:
        print("✓ All configuration files are present")
        return True


def main():
    """Main launch function."""
    print("NL→SQL Leaderboard Launcher")
    print("=" * 40)
    
    # Check requirements
    if not check_requirements():
        sys.exit(1)
    
    # Check configuration
    if not check_config():
        sys.exit(1)
    
    # Check for API keys and model configuration
    has_hf_token = bool(os.getenv("HF_TOKEN"))
    
    if has_hf_token:
        print("🔑 HF_TOKEN detected - using Hugging Face model APIs")
    else:
        print("🏠 No HF_TOKEN detected - using local models")
        print("   Models will be downloaded and run locally")
    
    print("\n🚀 Starting the NL→SQL Leaderboard...")
    print("The app will be available at: http://localhost:7860")
    print("Press Ctrl+C to stop the server")
    print("-" * 40)
    
    # Launch the app
    try:
        from app import create_interface
        app = create_interface()
        app.launch(
            server_name="0.0.0.0",
            server_port=7860,
            share=False,  # Set to True for public sharing
            show_error=True
        )
    except KeyboardInterrupt:
        print("\n👋 Shutting down the NL→SQL Leaderboard...")
    except Exception as e:
        print(f"\n❌ Error launching the app: {e}")
        sys.exit(1)


if __name__ == "__main__":
    main()