RAGassignment / setup_script.sh
u-r-a-bot's picture
Upload all the 23 files
baf62a0 verified
Raw History Blame Contribute Delete
7.7 kB
#!/bin/bash
# JioPay RAG System - Setup Script
# This script sets up the complete environment for the RAG system
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Banner
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════╗"
echo "β•‘ JioPay RAG System - Automated Setup v1.0 β•‘"
echo "β•‘ Setting up your RAG environment... β•‘"
echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•"
echo -e "${NC}"
# Function to print colored messages
print_status() {
echo -e "${GREEN}[βœ“]${NC} $1"
}
print_error() {
echo -e "${RED}[βœ—]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${NC} $1"
}
print_info() {
echo -e "${BLUE}[i]${NC} $1"
}
# Check Python version
print_info "Checking Python version..."
if command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version | cut -d " " -f 2 | cut -d "." -f 1,2)
REQUIRED_VERSION="3.8"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
print_status "Python $PYTHON_VERSION detected (>= 3.8 required)"
else
print_error "Python version $PYTHON_VERSION is too old. Please install Python 3.8 or higher."
exit 1
fi
else
print_error "Python 3 is not installed. Please install Python 3.8 or higher."
exit 1
fi
# Create virtual environment
print_info "Creating virtual environment..."
if [ -d "venv" ]; then
print_warning "Virtual environment already exists. Skipping creation."
else
python3 -m venv venv
print_status "Virtual environment created"
fi
# Activate virtual environment
print_info "Activating virtual environment..."
source venv/bin/activate
print_status "Virtual environment activated"
# Upgrade pip
print_info "Upgrading pip..."
pip install --upgrade pip --quiet
print_status "pip upgraded"
# Install requirements
print_info "Installing dependencies (this may take a few minutes)..."
# Core dependencies
pip install --quiet requests beautifulsoup4 trafilatura playwright aiohttp lxml
print_status "Web scraping libraries installed"
pip install --quiet nltk spacy sentencepiece
print_status "NLP libraries installed"
pip install --quiet sentence-transformers transformers torch tokenizers
print_status "Embedding libraries installed"
pip install --quiet faiss-cpu chromadb hnswlib
print_status "Vector database libraries installed"
pip install --quiet google-generativeai langchain langchain-google-genai
print_status "LLM libraries installed"
pip install --quiet pandas numpy scikit-learn
print_status "Data processing libraries installed"
pip install --quiet tqdm click rich
print_status "CLI libraries installed"
pip install --quiet streamlit gradio fastapi uvicorn
print_status "Web interface libraries installed"
pip install --quiet python-dotenv pyyaml jsonlines
print_status "Utility libraries installed"
pip install --quiet rouge-score bert-score matplotlib seaborn
print_status "Evaluation libraries installed"
# Install Playwright browsers
print_info "Installing Playwright browsers..."
playwright install chromium
print_status "Playwright browsers installed"
# Download NLTK data
print_info "Downloading NLTK data..."
python3 -c "import nltk; nltk.download('punkt', quiet=True); nltk.download('stopwords', quiet=True)"
print_status "NLTK data downloaded"
# Create directory structure
print_info "Creating directory structure..."
mkdir -p scraped_data chunked_data evaluation_results logs backups
print_status "Directories created"
# Create .env file if it doesn't exist
if [ ! -f .env ]; then
print_info "Creating .env file..."
cat > .env << EOF
# JioPay RAG System Environment Variables
# API Keys (REQUIRED - Add your actual key)
GEMINI_API_KEY=your_gemini_api_key_here
# Optional API Keys
# OPENAI_API_KEY=your_openai_key_here
# Database (if using PostgreSQL)
# DB_PASSWORD=your_database_password
# Other settings
LOG_LEVEL=INFO
CACHE_ENABLED=true
EOF
print_status ".env file created"
print_warning "Please edit .env and add your GEMINI_API_KEY"
else
print_warning ".env file already exists. Please ensure GEMINI_API_KEY is set."
fi
# Create a simple test script
print_info "Creating test script..."
cat > test_setup.py << EOF
#!/usr/bin/env python3
"""Quick test to verify setup"""
import sys
def test_imports():
"""Test if all key libraries can be imported"""
libraries = [
('requests', 'Web scraping'),
('bs4', 'BeautifulSoup'),
('trafilatura', 'Trafilatura'),
('sentence_transformers', 'Sentence Transformers'),
('transformers', 'Transformers'),
('faiss', 'FAISS'),
('chromadb', 'ChromaDB'),
('google.generativeai', 'Google Gemini'),
('streamlit', 'Streamlit'),
('tqdm', 'Progress bars'),
]
print("Testing library imports...")
success = True
for lib, name in libraries:
try:
__import__(lib)
print(f" βœ“ {name}")
except ImportError as e:
print(f" βœ— {name}: {str(e)}")
success = False
return success
def test_gemini_key():
"""Test if Gemini API key is set"""
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('GEMINI_API_KEY')
if api_key and api_key != 'your_gemini_api_key_here':
print(" βœ“ Gemini API key is set")
return True
else:
print(" βœ— Gemini API key not set. Please edit .env file")
return False
if __name__ == "__main__":
print("\nRunning setup verification...")
print("-" * 40)
imports_ok = test_imports()
print()
key_ok = test_gemini_key()
print("-" * 40)
if imports_ok and key_ok:
print("✨ Setup completed successfully!")
sys.exit(0)
else:
print("⚠️ Setup incomplete. Please fix the issues above.")
sys.exit(1)
EOF
chmod +x test_setup.py
print_status "Test script created"
# Run the test
print_info "Running setup verification..."
python3 test_setup.py
# Final instructions
echo ""
echo -e "${GREEN}════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Setup Complete! Next Steps:${NC}"
echo -e "${GREEN}════════════════════════════════════════════════════════${NC}"
echo ""
echo "1. Edit .env file and add your GEMINI_API_KEY:"
echo " nano .env"
echo ""
echo "2. Run the full pipeline:"
echo " python main.py full"
echo ""
echo "3. Or run individual components:"
echo " python main.py scrape # Web scraping"
echo " python main.py chunk # Document chunking"
echo " python main.py index # Vector indexing"
echo " python main.py evaluate # Evaluation"
echo ""
echo "4. Launch interactive modes:"
echo " python main.py chat # CLI chat interface"
echo " python main.py web # Web UI (Streamlit)"
echo ""
echo "5. For help:"
echo " python main.py --help"
echo ""
echo -e "${BLUE}Happy RAG building! πŸš€${NC}"
echo ""
# Reminder about activation
print_warning "Remember to activate the virtual environment in new terminal sessions:"
echo " source venv/bin/activate"