Spaces:
Running
Running
File size: 4,068 Bytes
06e73d2 | 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 | #!/bin/bash
# ============================================================
# Fake News Detection - Environment Setup Script
# This script creates virtual environment and installs all dependencies
# ============================================================
set -e # Exit on error
echo ""
echo "============================================================"
echo "FAKE NEWS DETECTION - ENVIRONMENT SETUP"
echo "============================================================"
echo ""
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if Python is installed
echo "[1/5] Checking Python installation..."
if ! command -v python3 &> /dev/null; then
if ! command -v python &> /dev/null; then
echo -e "${RED}[ERROR] Python is not installed${NC}"
echo "Please install Python 3.9 or higher"
exit 1
else
PYTHON_CMD=python
fi
else
PYTHON_CMD=python3
fi
$PYTHON_CMD --version
echo -e "${GREEN}[SUCCESS] Python is installed${NC}"
echo ""
# Check if virtual environment already exists
if [ -d "venv" ]; then
echo -e "${YELLOW}[WARNING] Virtual environment already exists${NC}"
read -p "Do you want to recreate it? (y/n): " recreate
if [[ $recreate =~ ^[Yy]$ ]]; then
echo "[2/5] Removing existing virtual environment..."
rm -rf venv
echo -e "${GREEN}[SUCCESS] Removed existing virtual environment${NC}"
else
echo "[INFO] Using existing virtual environment"
fi
fi
# Create virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
echo "[2/5] Creating virtual environment..."
$PYTHON_CMD -m venv venv
echo -e "${GREEN}[SUCCESS] Virtual environment created${NC}"
echo ""
else
echo "[2/5] Virtual environment already exists"
echo ""
fi
# Activate virtual environment
echo "[3/5] Activating virtual environment..."
source venv/bin/activate
echo -e "${GREEN}[SUCCESS] Virtual environment activated${NC}"
echo ""
# Upgrade pip
echo "[4/5] Upgrading pip..."
pip install --upgrade pip --quiet
echo -e "${GREEN}[SUCCESS] Pip upgraded${NC}"
echo ""
# Install requirements
echo "[5/5] Installing dependencies from requirements.txt..."
echo "This may take a few minutes..."
echo ""
if pip install -r requirements.txt; then
echo ""
echo "============================================================"
echo "INSTALLATION COMPLETE"
echo "============================================================"
echo ""
echo -e "${GREEN}[SUCCESS] All dependencies installed successfully!${NC}"
echo ""
echo "Virtual environment location: $(pwd)/venv"
echo "Python version: $($PYTHON_CMD --version)"
echo ""
echo "Installed packages:"
pip list | grep -E "torch|transformers|fastapi|supabase"
echo ""
else
echo ""
echo -e "${RED}[ERROR] Failed to install some dependencies${NC}"
echo "Please check the error messages above"
echo ""
echo "Common solutions:"
echo "1. Make sure you have internet connection"
echo "2. Check if requirements.txt exists"
echo "3. Install build tools if needed"
echo ""
exit 1
fi
echo "============================================================"
echo "NEXT STEPS"
echo "============================================================"
echo ""
echo "1. Virtual environment is already activated"
echo ""
echo "2. Download models from Hugging Face:"
echo " python scripts/download_models.py"
echo ""
echo "3. Setup Supabase database:"
echo " - Open Supabase dashboard"
echo " - Run scripts/setup_supabase.sql in SQL Editor"
echo ""
echo "4. Test connections:"
echo " python scripts/test_connections.py"
echo ""
echo "5. Start the API server:"
echo " uvicorn src.api.main:app --reload"
echo ""
echo "============================================================"
echo ""
echo "To activate virtual environment in future sessions:"
echo " source venv/bin/activate"
echo ""
echo "To deactivate:"
echo " deactivate"
echo ""
echo "============================================================"
echo ""
|