Spaces:
Running
Running
Download setup_script.sh from u-r-a-bot/RAGassignment: direct link, hf CLI and curl.
- Browser
- Download file 7.7 kB
-
https://huggingface.co/spaces/u-r-a-bot/RAGassignment/resolve/main/setup_script.sh
- Command line
-
hf download hf://spaces/u-r-a-bot/RAGassignment/setup_script.sh
-
curl -L -o setup_script.sh https://huggingface.co/spaces/u-r-a-bot/RAGassignment/resolve/main/setup_script.sh
7.7 kB
| # 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" | |