Graph_RAG7 / deploy.sh
Aigenthix's picture
Upload 19 files
bc10808 verified
Raw
History Blame Contribute Delete
5.62 kB
#!/bin/bash
# Graph RAG Chatbot Deployment Script
# Supports: Local, Docker, Docker Compose, and Hugging Face Spaces
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}πŸ€– Graph RAG Chatbot Deployment Script${NC}\n"
# Check if GROQ_API_KEY is set
if [ -z "$GROQ_API_KEY" ]; then
if [ -f ".env" ]; then
export $(cat .env | grep GROQ_API_KEY)
else
echo -e "${YELLOW}⚠️ GROQ_API_KEY not found!${NC}"
echo "Please set it in .env file or as environment variable"
echo ""
echo "Getting Groq API Key:"
echo "1. Visit https://console.groq.com"
echo "2. Sign up/Login"
echo "3. Create an API key"
echo "4. Copy it"
echo ""
read -p "Enter your GROQ_API_KEY: " GROQ_API_KEY
echo "GROQ_API_KEY=$GROQ_API_KEY" > .env
echo -e "${GREEN}βœ… API key saved to .env${NC}"
fi
fi
echo -e "${GREEN}βœ… GROQ_API_KEY configured${NC}\n"
# Menu
echo "Select deployment method:"
echo "1) Local (Python venv)"
echo "2) Docker (Single container)"
echo "3) Docker Compose (Recommended)"
echo "4) Hugging Face Spaces"
echo ""
read -p "Enter choice (1-4): " choice
case $choice in
1)
echo -e "\n${GREEN}πŸ“¦ Local Deployment${NC}\n"
if ! command -v python3 &> /dev/null; then
echo -e "${RED}❌ Python 3 not found. Please install Python 3.8+${NC}"
exit 1
fi
echo "Creating virtual environment..."
python3 -m venv venv
echo "Activating virtual environment..."
source venv/bin/activate
echo "Installing dependencies..."
pip install --upgrade pip
pip install -r requirements.txt
echo ""
echo -e "${GREEN}βœ… Installation complete!${NC}"
echo ""
echo "To start the app, run:"
echo " source venv/bin/activate"
echo " python app.py"
echo ""
echo "Then open: http://localhost:7860"
;;
2)
echo -e "\n${GREEN}🐳 Docker Deployment${NC}\n"
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker not found. Please install Docker.${NC}"
echo "Visit: https://docs.docker.com/get-docker/"
exit 1
fi
echo "Building Docker image..."
docker build -t graph-rag-chatbot .
echo -e "\n${GREEN}βœ… Image built successfully!${NC}"
echo ""
echo "To run the container, use:"
echo " docker run -p 7860:7860 \\"
echo " -e GROQ_API_KEY=$GROQ_API_KEY \\"
echo " -v \$(pwd)/data:/app/data \\"
echo " graph-rag-chatbot"
echo ""
echo "Or use Docker Compose: docker-compose up"
echo ""
read -p "Start container now? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker run -p 7860:7860 \
-e GROQ_API_KEY=$GROQ_API_KEY \
-v $(pwd)/data:/app/data \
graph-rag-chatbot
fi
;;
3)
echo -e "\n${GREEN}🐳 Docker Compose Deployment${NC}\n"
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}❌ Docker Compose not found.${NC}"
echo "Visit: https://docs.docker.com/compose/install/"
exit 1
fi
echo "Ensuring .env file exists..."
if [ ! -f ".env" ]; then
cp .env.example .env
sed -i "s/your_groq_api_key_here/$GROQ_API_KEY/" .env
fi
echo "Starting Docker Compose services..."
docker-compose up -d
echo -e "\n${GREEN}βœ… Services started!${NC}"
echo ""
echo "Access the app at: http://localhost:7860"
echo ""
echo "Useful commands:"
echo " docker-compose logs -f # View logs"
echo " docker-compose ps # View services"
echo " docker-compose down # Stop services"
;;
4)
echo -e "\n${GREEN}πŸ€— Hugging Face Spaces Deployment${NC}\n"
if ! command -v git &> /dev/null; then
echo -e "${RED}❌ Git not found. Please install Git.${NC}"
exit 1
fi
echo "Steps to deploy to HF Spaces:"
echo ""
echo "1. Create a new Space:"
echo " https://huggingface.co/spaces"
echo " - Select Docker as SDK"
echo " - Name: graph-rag-chatbot"
echo ""
echo "2. Clone the Space:"
read -p "Enter your HF username: " hf_username
git clone https://huggingface.co/spaces/$hf_username/graph-rag-chatbot hf-space-clone
cd hf-space-clone
# Copy all files
echo "Copying project files..."
cp -r ../app.py .
cp -r ../templates .
cp -r ../Dockerfile .
cp -r ../requirements.txt .
cp -r ../.dockerignore .
git add .
git commit -m "Initial Graph RAG deployment"
git push
echo -e "\n${GREEN}βœ… Files pushed to HF Spaces!${NC}"
echo ""
echo "Final step: Add your API key as a secret"
echo "1. Go to: https://huggingface.co/spaces/$hf_username/graph-rag-chatbot"
echo "2. Click Settings β†’ Repository secrets"
echo "3. Add new secret:"
echo " Name: GROQ_API_KEY"
echo " Value: $GROQ_API_KEY"
echo ""
echo "Your app will be live in a few minutes!"
;;
*)
echo -e "${RED}❌ Invalid choice${NC}"
exit 1
;;
esac
echo ""
echo -e "${GREEN}πŸŽ‰ Deployment configured!${NC}"