File size: 6,229 Bytes
4b62d23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@echo off
REM MongoDB & Redis Integration - Setup Script for Windows
setlocal enabledelayedexpansion

echo ==============================================
echo MongoDB ^& Redis Integration - Setup Helper
echo ==============================================
echo.

REM Check if .env exists
if exist .env (
    echo WARNING: .env file already exists!
    set /p "overwrite=Do you want to overwrite it? (y/N): "
    if /i not "!overwrite!"=="y" (
        echo Setup cancelled.
        exit /b 1
    )
)

REM Copy template
echo Creating .env file from template...
copy .env.example .env >nul

echo.
echo --------------------------------------------------
echo MongoDB Configuration
echo --------------------------------------------------
echo Choose MongoDB option:
echo   1^) MongoDB Atlas (cloud^)
echo   2^) Local MongoDB
echo   3^) Skip (configure manually later^)
set /p "mongo_choice=Enter choice (1-3): "

if "%mongo_choice%"=="1" (
    echo.
    echo MongoDB Atlas Setup:
    echo 1. Go to https://www.mongodb.com/cloud/atlas
    echo 2. Create a free cluster
    echo 3. Create a database user
    echo 4. Whitelist your IP
    echo 5. Get your connection string
    echo.
    set /p "mongo_uri=Enter MongoDB Atlas URI: "
    
    REM Update .env file
    powershell -Command "(Get-Content .env) -replace 'MONGO_URI=', 'MONGO_URI=!mongo_uri!' | Set-Content .env"
)

if "%mongo_choice%"=="2" (
    echo.
    set /p "mongo_host=Enter MongoDB host (default: localhost): "
    if "!mongo_host!"=="" set "mongo_host=localhost"
    
    set /p "mongo_port=Enter MongoDB port (default: 27017): "
    if "!mongo_port!"=="" set "mongo_port=27017"
    
    set /p "mongo_db=Enter database name (default: absa-insights): "
    if "!mongo_db!"=="" set "mongo_db=absa-insights"
    
    set "mongo_uri=mongodb://!mongo_host!:!mongo_port!/!mongo_db!"
    powershell -Command "(Get-Content .env) -replace 'MONGO_URI=', 'MONGO_URI=!mongo_uri!' | Set-Content .env"
)

if "%mongo_choice%"=="3" (
    echo Skipping MongoDB configuration
)

echo.
echo --------------------------------------------------
echo Redis Configuration
echo --------------------------------------------------
echo Choose Redis option:
echo   1^) Redis Cloud (cloud^)
echo   2^) Local Redis
echo   3^) Skip (configure manually later^)
set /p "redis_choice=Enter choice (1-3): "

if "%redis_choice%"=="1" (
    echo.
    echo Redis Cloud Setup:
    echo 1. Go to https://redis.com/try-free/
    echo 2. Create a free database
    echo 3. Get connection details
    echo.
    set /p "redis_host=Enter Redis host: "
    set /p "redis_port=Enter Redis port: "
    set /p "redis_password=Enter Redis password: "
    
    powershell -Command "(Get-Content .env) -replace 'REDIS_HOST=localhost', 'REDIS_HOST=!redis_host!' | Set-Content .env"
    powershell -Command "(Get-Content .env) -replace 'REDIS_PORT=6379', 'REDIS_PORT=!redis_port!' | Set-Content .env"
    powershell -Command "(Get-Content .env) -replace 'REDIS_PASSWORD=', 'REDIS_PASSWORD=!redis_password!' | Set-Content .env"
)

if "%redis_choice%"=="2" (
    echo.
    set /p "redis_host=Enter Redis host (default: localhost): "
    if "!redis_host!"=="" set "redis_host=localhost"
    
    set /p "redis_port=Enter Redis port (default: 6379): "
    if "!redis_port!"=="" set "redis_port=6379"
    
    powershell -Command "(Get-Content .env) -replace 'REDIS_HOST=localhost', 'REDIS_HOST=!redis_host!' | Set-Content .env"
    powershell -Command "(Get-Content .env) -replace 'REDIS_PORT=6379', 'REDIS_PORT=!redis_port!' | Set-Content .env"
    echo No password set for local Redis
)

if "%redis_choice%"=="3" (
    echo Skipping Redis configuration
)

echo.
echo --------------------------------------------------
echo Admin Token
echo --------------------------------------------------
set /p "gen_token=Generate random admin token? (Y/n): "
if /i not "!gen_token!"=="n" (
    REM Generate random token using PowerShell
    for /f %%i in ('powershell -Command "[System.Web.Security.Membership]::GeneratePassword(64,16)"') do set "admin_token=%%i"
    powershell -Command "(Get-Content .env) -replace 'ADMIN_TOKEN=', 'ADMIN_TOKEN=!admin_token!' | Set-Content .env"
    echo Admin token generated and saved to .env
) else (
    echo Skipping admin token generation
)

echo.
echo --------------------------------------------------
echo IPinfo Token
echo --------------------------------------------------
echo Get your free token from: https://ipinfo.io/signup
set /p "ipinfo_token=Enter IPinfo token (or press Enter to skip): "

if not "!ipinfo_token!"=="" (
    powershell -Command "(Get-Content .env) -replace 'IPINFO_TOKEN=', 'IPINFO_TOKEN=!ipinfo_token!' | Set-Content .env"
    echo IPinfo token saved
) else (
    echo Skipping IPinfo token
)

echo.
echo --------------------------------------------------
echo HuggingFace Token (Optional^)
echo --------------------------------------------------
set /p "hf_token=Enter HuggingFace token (or press Enter to skip): "

if not "!hf_token!"=="" (
    powershell -Command "(Get-Content .env) -replace 'HF_TOKEN=', 'HF_TOKEN=!hf_token!' | Set-Content .env"
    echo HuggingFace token saved
) else (
    echo Skipping HuggingFace token
)

echo.
echo ==============================================
echo Setup Complete!
echo ==============================================
echo.
echo Configuration saved to: .env
echo.
echo Next steps:
echo 1. Review .env and make any adjustments
echo 2. Install dependencies: pip install -r requirements-backend.txt
echo 3. Start the backend: python api_server.py
echo 4. Test health: curl http://localhost:7860/health
echo.
echo Documentation:
echo - Quick Start: QUICK_START.md
echo - Full Docs: MONGODB_REDIS_IMPLEMENTATION.md
echo - Admin Dashboard: streamlit run admin_dashboard.py
echo.
echo ==============================================

echo.
set /p "install_deps=Install dependencies now? (Y/n): "
if /i not "!install_deps!"=="n" (
    echo.
    echo Installing dependencies...
    pip install -r requirements-backend.txt
    echo Dependencies installed!
) else (
    echo Skipping dependency installation
    echo Remember to run: pip install -r requirements-backend.txt
)

echo.
echo All done! You're ready to go!
echo.
pause