Spaces:
Running
Running
File size: 7,704 Bytes
baf62a0 | 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | #!/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"
|