File size: 5,622 Bytes
bc10808
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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}"