File size: 3,918 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
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
#!/usr/bin/env python3
"""
LangChain + RAGAS Launch Script
Launch script for the NL→SQL Leaderboard with LangChain and RAGAS integration.
"""

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
        import langchain
        import langchain_community
        # import langchain_openai  # Removed OpenAI dependency
        import langsmith
        import ragas
        import torch
        import transformers
        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 check_api_keys():
    """Check for API keys and provide guidance."""
    has_hf_token = bool(os.getenv("HF_TOKEN"))
    has_langsmith = bool(os.getenv("LANGSMITH_API_KEY"))
    
    print("\n🔑 API Key Status:")
    print(f"   HuggingFace Token: {'✅' if has_hf_token else '❌'}")
    print(f"   LangSmith API Key: {'✅' if has_langsmith else '❌'}")
    
    if not has_hf_token:
        print("\n⚠️  No HuggingFace token detected!")
        print("   Available models will be limited to local models only.")
        print("   To use HuggingFace Hub models: export HF_TOKEN='your-token'")
    else:
        print("\n✅ HuggingFace token detected - full model access available")
    
    if not has_langsmith:
        print("\n💡 LangSmith tracking is optional but recommended for experiment monitoring")
        print("   To enable: export LANGSMITH_API_KEY='your-key'")
    
    print("\n🤖 RAGAS Evaluation:")
    print("   ✅ Using HuggingFace models for RAGAS metrics")
    print("   📊 Advanced evaluation metrics: faithfulness, relevancy, precision, recall")
    print("   ⚠️  Note: RAGAS still requires OpenAI API key for some internal operations")


def main():
    """Main launch function."""
    print("NL→SQL Leaderboard Launcher (LangChain + RAGAS)")
    print("=" * 60)
    
    # Check requirements
    if not check_requirements():
        sys.exit(1)
    
    # Check configuration
    if not check_config():
        sys.exit(1)
    
    # Check API keys
    check_api_keys()
    
    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("-" * 60)
    
    # Launch the app
    try:
        from langchain_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()