#!/bin/bash set -e echo "🚀 Starting RAG Pipeline Optimizer..." echo "================================================" # Display Python and Streamlit versions echo "📦 Environment Information:" python --version streamlit --version echo "================================================" # Check if running on HuggingFace Spaces if [ -n "$SPACE_ID" ]; then echo "🤗 Running on HuggingFace Spaces: $SPACE_ID" else echo "💻 Running in local environment" fi echo "================================================" # Download ChromaDB data if not present echo "📥 Checking ChromaDB data..." if [ -f "scripts/download_data.py" ]; then python scripts/download_data.py if [ $? -ne 0 ]; then echo "❌ Failed to download ChromaDB data" exit 1 fi else echo "⚠️ download_data.py not found, skipping data download" echo "Assuming data is already present in the repository" fi echo "================================================" # Check environment variables echo "🔍 Checking environment variables..." # Azure OpenAI if [ -n "$AZURE_OPENAI_API_KEY" ]; then echo "✅ AZURE_OPENAI_API_KEY is set" else echo "⚠️ WARNING: AZURE_OPENAI_API_KEY not set!" fi if [ -n "$AZURE_OPENAI_ENDPOINT" ]; then echo "✅ AZURE_OPENAI_ENDPOINT is set" else echo "⚠️ WARNING: AZURE_OPENAI_ENDPOINT not set!" fi # Azure Embeddings if [ -n "$AZURE_OPENAI_EMBEDDING_API_KEY" ]; then echo "✅ AZURE_OPENAI_EMBEDDING_API_KEY is set" else echo "⚠️ WARNING: AZURE_OPENAI_EMBEDDING_API_KEY not set!" fi # Cohere Rerank if [ -n "$AZURE_COHERE_RERANK_KEY" ]; then echo "✅ AZURE_COHERE_RERANK_KEY is set" else echo "⚠️ WARNING: AZURE_COHERE_RERANK_KEY not set!" fi # Anthropic if [ -n "$ANTHROPIC_API_KEY" ]; then echo "✅ ANTHROPIC_API_KEY is set" else echo "⚠️ ANTHROPIC_API_KEY not set (optional)" fi echo "================================================" # Check if ChromaDB data exists echo "🔍 Verifying ChromaDB collections..." PIPELINES=("a" "b" "c" "d" "e" "f") DATA_DIR="data/vector_stores" if [ -d "$DATA_DIR" ]; then FOUND_COUNT=0 for pipeline in "${PIPELINES[@]}"; do CORPUS_PATH="$DATA_DIR/pipeline_${pipeline}_corpus" if [ -d "$CORPUS_PATH" ]; then echo " ✓ Pipeline ${pipeline^^} corpus found" FOUND_COUNT=$((FOUND_COUNT + 1)) else echo " ✗ Pipeline ${pipeline^^} corpus MISSING" fi done echo "Found $FOUND_COUNT out of 6 pipeline collections" if [ $FOUND_COUNT -eq 0 ]; then echo "⚠️ WARNING: No ChromaDB collections found!" echo "The app may not function correctly without vector stores." fi else echo "⚠️ WARNING: data/vector_stores directory not found!" fi echo "================================================" # Check database echo "🔍 Checking evaluation database..." if [ -f "data/evaluation_results.db" ]; then DB_SIZE=$(du -h data/evaluation_results.db | cut -f1) echo "✅ Evaluation database found (size: $DB_SIZE)" else echo "⚠️ evaluation_results.db not found - will be created on first run" fi echo "================================================" echo "🌐 Starting Streamlit on port 8501..." echo "================================================" echo "" echo "🎯 Access the dashboard at:" echo " Local: http://localhost:8501" if [ -n "$SPACE_ID" ]; then echo " Public: https://huggingface.co/spaces/$SPACE_ID" fi echo "" echo "================================================" # Start Streamlit with proper configuration exec streamlit run app/dashboard.py \ --server.port=8501 \ --server.address=0.0.0.0 \ --server.headless=true \ --browser.gatherUsageStats=false \ --server.enableCORS=false \ --server.enableXsrfProtection=false \ --theme.base=dark \ --logger.level=info