-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·159 lines (137 loc) · 4.04 KB
/
start.sh
File metadata and controls
executable file
·159 lines (137 loc) · 4.04 KB
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
#!/bin/bash
# RAG Chatbot - Setup and Start Script
# This script automates the setup and startup of both backend and frontend
set -e # Exit on error
echo "=================================="
echo "RAG Chatbot Setup & Startup"
echo "=================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check Python
echo "Checking Python installation..."
if ! command -v python3 &> /dev/null; then
echo -e "${RED}Error: Python 3 is not installed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Python found: $(python3 --version)${NC}"
# Check Node.js
echo "Checking Node.js installation..."
if ! command -v node &> /dev/null; then
echo -e "${RED}Error: Node.js is not installed${NC}"
exit 1
fi
echo -e "${GREEN}✓ Node.js found: $(node --version)${NC}"
echo ""
# Setup Backend
echo "=================================="
echo "Setting up Backend..."
echo "=================================="
cd backend
# Create virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
echo "Creating Python virtual environment..."
python3 -m venv venv
echo -e "${GREEN}✓ Virtual environment created${NC}"
else
echo -e "${YELLOW}Virtual environment already exists${NC}"
fi
# Activate virtual environment
source venv/bin/activate
# Install dependencies
echo "Installing Python dependencies..."
pip install -r requirements.txt > /dev/null 2>&1
echo -e "${GREEN}✓ Dependencies installed${NC}"
# Check for .env file
if [ ! -f ".env" ]; then
echo -e "${YELLOW}Warning: .env file not found${NC}"
echo "Creating .env from .env.example..."
cp .env.example .env
echo -e "${RED}⚠ Please edit backend/.env and add your Google AI (Gemini) API key${NC}"
echo "Press Enter after updating the API key..."
read
fi
echo -e "${GREEN}✓ Backend setup complete${NC}"
cd ..
echo ""
# Setup Frontend
echo "=================================="
echo "Setting up Frontend..."
echo "=================================="
cd frontend
# Install dependencies if node_modules doesn't exist
if [ ! -d "node_modules" ]; then
echo "Installing Node.js dependencies..."
npm install
echo -e "${GREEN}✓ Dependencies installed${NC}"
else
echo -e "${YELLOW}Dependencies already installed${NC}"
fi
echo -e "${GREEN}✓ Frontend setup complete${NC}"
cd ..
echo ""
# Start servers
echo "=================================="
echo "Starting Servers..."
echo "=================================="
echo ""
# Start backend in background
echo "Starting Backend server..."
cd backend
source venv/bin/activate
python main.py > ../backend.log 2>&1 &
BACKEND_PID=$!
cd ..
echo -e "${GREEN}✓ Backend started (PID: $BACKEND_PID)${NC}"
echo " Backend logs: backend.log"
echo " Backend URL: http://localhost:8000"
echo ""
# Wait for backend to be ready
echo "Waiting for backend to be ready..."
for i in {1..30}; do
if curl -s http://localhost:8000/api/health > /dev/null 2>&1; then
echo -e "${GREEN}✓ Backend is ready${NC}"
break
fi
sleep 1
if [ $i -eq 30 ]; then
echo -e "${RED}Error: Backend did not start properly${NC}"
echo "Check backend.log for errors"
kill $BACKEND_PID 2>/dev/null
exit 1
fi
done
echo ""
# Start frontend
echo "Starting Frontend server..."
cd frontend
npm run dev > ../frontend.log 2>&1 &
FRONTEND_PID=$!
cd ..
echo -e "${GREEN}✓ Frontend started (PID: $FRONTEND_PID)${NC}"
echo " Frontend logs: frontend.log"
echo " Frontend URL: http://localhost:3000"
echo ""
# Save PIDs for cleanup
echo "$BACKEND_PID" > .backend.pid
echo "$FRONTEND_PID" > .frontend.pid
echo "=================================="
echo -e "${GREEN}Setup Complete!${NC}"
echo "=================================="
echo ""
echo "🚀 Your RAG Chatbot is now running!"
echo ""
echo "📱 Open your browser to: http://localhost:3000"
echo ""
echo "To stop the servers, run: ./stop.sh"
echo "Or press Ctrl+C and run: kill $BACKEND_PID $FRONTEND_PID"
echo ""
echo "Logs are available at:"
echo " - backend.log"
echo " - frontend.log"
echo ""
# Keep script running
wait