#!/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()