-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
321 lines (261 loc) · 9.58 KB
/
Copy pathsetup.py
File metadata and controls
321 lines (261 loc) · 9.58 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/usr/bin/env python3
"""
Setup script for Youth Mental Wellness AI
Automated setup for development and deployment
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def print_header(text):
print("\n" + "=" * 60)
print(f" {text}")
print("=" * 60)
def print_step(step, description):
print(f"\n[Step {step}] {description}")
print("-" * 40)
def run_command(command, description, check=True):
"""Run a system command with error handling"""
try:
print(f"Running: {command}")
result = subprocess.run(command, shell=True, check=check, capture_output=True, text=True)
if result.stdout:
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
if e.stderr:
print(f"Error details: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible"""
print_step(1, "Checking Python Version")
if sys.version_info < (3, 8):
print("❌ Error: Python 3.8 or higher is required")
print(f"Current version: {sys.version}")
return False
print(f"✅ Python version {sys.version.split()[0]} is compatible")
return True
def create_virtual_environment():
"""Create virtual environment if it doesn't exist"""
print_step(2, "Setting up Virtual Environment")
venv_path = Path("venv")
if venv_path.exists():
print("✅ Virtual environment already exists")
return True
print("Creating virtual environment...")
if run_command(f"{sys.executable} -m venv venv", "Creating virtual environment"):
print("✅ Virtual environment created successfully")
return True
print("❌ Failed to create virtual environment")
return False
def activate_and_install_dependencies():
"""Install Python dependencies"""
print_step(3, "Installing Dependencies")
# Determine the activation script path based on OS
if os.name == 'nt': # Windows
activate_script = "venv\\Scripts\\activate.bat"
pip_path = "venv\\Scripts\\pip"
else: # Unix/Linux/MacOS
activate_script = "source venv/bin/activate"
pip_path = "venv/bin/pip"
print("Installing required packages...")
# Install packages one by one for better error handling
packages = [
"google-generativeai==0.3.2",
"flask==2.3.3",
"flask-cors==4.0.0",
"python-dotenv==1.0.0",
"langdetect==1.0.9",
"textblob==0.17.1",
"numpy==1.24.3",
"pandas==2.0.3",
"scikit-learn==1.3.0",
"requests==2.31.0",
"nltk==3.8.1"
]
failed_packages = []
for package in packages:
print(f"Installing {package}...")
if not run_command(f"{pip_path} install {package}", f"Installing {package}", check=False):
failed_packages.append(package)
if failed_packages:
print(f"⚠️ Warning: Failed to install: {', '.join(failed_packages)}")
print("You may need to install these manually")
return False
print("✅ All dependencies installed successfully")
return True
def setup_environment_file():
"""Create .env file from .env.example"""
print_step(4, "Setting up Environment Configuration")
env_example = Path(".env.example")
env_file = Path(".env")
if not env_example.exists():
print("❌ Error: .env.example file not found")
return False
if env_file.exists():
print("✅ .env file already exists")
print("⚠️ Please ensure your API keys are configured")
return True
try:
shutil.copy2(env_example, env_file)
print("✅ Created .env file from template")
print("\n📝 IMPORTANT: Please edit .env file and add your API keys:")
print(" - GEMINI_API_KEY: Your Google Gemini API key")
print(" - FLASK_SECRET_KEY: A secure random string")
print("\n🔧 To get a Gemini API key:")
print(" 1. Go to https://makersuite.google.com/app/apikey")
print(" 2. Create a new API key")
print(" 3. Copy it to your .env file")
return True
except Exception as e:
print(f"❌ Error creating .env file: {e}")
return False
def download_nltk_data():
"""Download required NLTK data"""
print_step(5, "Setting up NLTK Data")
try:
import nltk
print("Downloading NLTK data...")
nltk.download('punkt', quiet=True)
nltk.download('vader_lexicon', quiet=True)
nltk.download('stopwords', quiet=True)
print("✅ NLTK data downloaded successfully")
return True
except Exception as e:
print(f"⚠️ Warning: Could not download NLTK data: {e}")
print("You may need to download this manually later")
return False
def create_necessary_directories():
"""Create necessary directories for the application"""
print_step(6, "Creating Directory Structure")
directories = [
"logs",
"data/temp",
"static/uploads",
"instance"
]
for directory in directories:
dir_path = Path(directory)
try:
dir_path.mkdir(parents=True, exist_ok=True)
print(f"✅ Created directory: {directory}")
except Exception as e:
print(f"⚠️ Warning: Could not create directory {directory}: {e}")
return True
def run_initial_tests():
"""Run basic tests to ensure setup is working"""
print_step(7, "Running Initial Tests")
try:
# Test imports
print("Testing core imports...")
test_imports = [
"import flask",
"import google.generativeai as genai",
"from flask_cors import CORS",
"from dotenv import load_dotenv",
"import langdetect",
"import textblob",
"import nltk"
]
for import_statement in test_imports:
try:
exec(import_statement)
print(f"✅ {import_statement}")
except ImportError as e:
print(f"❌ {import_statement} - {e}")
return False
print("✅ All core imports successful")
return True
except Exception as e:
print(f"❌ Error during testing: {e}")
return False
def display_next_steps():
"""Display next steps for the user"""
print_header("Setup Complete! Next Steps:")
print("""
🎉 Installation completed successfully!
📋 Next Steps:
1. Configure your API keys:
- Edit the .env file in the project root
- Add your Google Gemini API key
- Set a secure Flask secret key
2. Start the application:
- Windows: venv\\Scripts\\activate && python app.py
- Mac/Linux: source venv/bin/activate && python app.py
3. Open your browser:
- Navigate to http://localhost:5000
- Start using MindMitra!
🔑 Getting API Keys:
Google Gemini API:
- Visit: https://makersuite.google.com/app/apikey
- Create a new API key
- Copy to GEMINI_API_KEY in .env file
🆘 Need Help?
- Check the README.md file
- Review the privacy policy at /privacy
- Test with the resources page at /resources
⚠️ Important Security Notes:
- Never commit your .env file to version control
- Keep your API keys private
- The application is designed for development use
🎯 Features Available:
✅ Anonymous, confidential conversations
✅ Crisis detection and emergency resources
✅ Cultural sensitivity for Indian youth
✅ Emotion analysis and support recommendations
✅ Multi-language support (English, Hindi, Hinglish)
✅ Privacy-focused design with auto-cleanup
""")
def main():
"""Main setup function"""
print_header("Youth Mental Wellness AI - Setup Script")
print("This script will set up the development environment for MindMitra")
# Check if running from correct directory
if not Path("app.py").exists():
print("❌ Error: Please run this script from the project root directory")
print("The directory should contain app.py, requirements.txt, etc.")
sys.exit(1)
steps_completed = 0
total_steps = 7
# Step 1: Check Python version
if check_python_version():
steps_completed += 1
else:
print("❌ Setup failed: Incompatible Python version")
sys.exit(1)
# Step 2: Create virtual environment
if create_virtual_environment():
steps_completed += 1
else:
print("❌ Setup failed: Could not create virtual environment")
sys.exit(1)
# Step 3: Install dependencies
if activate_and_install_dependencies():
steps_completed += 1
else:
print("⚠️ Warning: Some dependencies failed to install")
print("You may need to install them manually")
# Step 4: Setup environment file
if setup_environment_file():
steps_completed += 1
# Step 5: Download NLTK data
if download_nltk_data():
steps_completed += 1
# Step 6: Create directories
if create_necessary_directories():
steps_completed += 1
# Step 7: Run tests
if run_initial_tests():
steps_completed += 1
# Display results
print(f"\n📊 Setup Progress: {steps_completed}/{total_steps} steps completed")
if steps_completed == total_steps:
display_next_steps()
else:
print("⚠️ Setup completed with some warnings")
print("Please review the messages above and resolve any issues")
print("You may still be able to run the application")
if __name__ == "__main__":
main()