-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
278 lines (242 loc) · 8.93 KB
/
setup.py
File metadata and controls
278 lines (242 loc) · 8.93 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
#!/usr/bin/env python3
"""
LocalMind - LIVE-OFFLINE AI Assistant Setup Script
This setup script initializes LocalMind for offline operation including:
- Model download and quantization
- Knowledge base initialization
- Resource optimization configuration
- Security setup
"""
from setuptools import setup, find_packages
import os
import sys
import subprocess
import platform
from pathlib import Path
# Project metadata
PROJECT_NAME = "LocalMind"
VERSION = "1.0.0"
DESCRIPTION = "LIVE-OFFLINE AI Assistant for Education and Healthcare"
AUTHOR = "LocalMind Development Team"
LICENSE = "Apache 2.0"
# Minimum system requirements
MIN_PYTHON_VERSION = (3, 8)
MIN_RAM_GB = 8
RECOMMENDED_RAM_GB = 16
MIN_STORAGE_GB = 20
def check_system_requirements():
"""Check if system meets minimum requirements for LocalMind."""
print("🔍 Checking system requirements...")
# Check Python version
if sys.version_info < MIN_PYTHON_VERSION:
print(f"❌ Python {MIN_PYTHON_VERSION[0]}.{MIN_PYTHON_VERSION[1]}+ required, found {sys.version}")
sys.exit(1)
# Check available RAM
try:
import psutil
ram_gb = psutil.virtual_memory().total / (1024**3)
if ram_gb < MIN_RAM_GB:
print(f"⚠️ Warning: {ram_gb:.1f}GB RAM detected, {MIN_RAM_GB}GB minimum required")
print(" LocalMind will use resource-constrained mode")
elif ram_gb >= RECOMMENDED_RAM_GB:
print(f"✅ {ram_gb:.1f}GB RAM detected - optimal for LocalMind")
else:
print(f"✅ {ram_gb:.1f}GB RAM detected - sufficient for LocalMind")
except ImportError:
print("⚠️ Could not check RAM - install psutil for full system check")
# Check available storage
try:
disk_usage = os.statvfs('.')
free_gb = (disk_usage.f_bavail * disk_usage.f_frsize) / (1024**3)
if free_gb < MIN_STORAGE_GB:
print(f"❌ {free_gb:.1f}GB free space, {MIN_STORAGE_GB}GB minimum required")
sys.exit(1)
else:
print(f"✅ {free_gb:.1f}GB free space available")
except AttributeError:
# Windows doesn't have statvfs
print("✅ Storage check skipped on Windows")
print("✅ System requirements check complete\n")
def create_directory_structure():
"""Create necessary directories for LocalMind operation."""
print("📁 Creating directory structure...")
directories = [
"data/knowledge/embeddings",
"data/knowledge/documents",
"data/models/quantized",
"data/user/profiles",
"data/user/history",
"logs",
"cache"
]
for directory in directories:
Path(directory).mkdir(parents=True, exist_ok=True)
print(f" Created: {directory}")
print("✅ Directory structure created\n")
def download_models():
"""Download and prepare offline models."""
print("🤖 Setting up offline models...")
# This would typically download models from Hugging Face
# For demo purposes, we'll create placeholder files
models_dir = Path("data/models")
# Create model configuration files
model_configs = {
"mistral-7b-instruct-v0.1": {
"size": "7B",
"quantization": "4bit",
"domains": ["general", "education", "healthcare"],
"languages": ["en", "es", "fr", "pt", "ar"]
},
"llama-2-7b-chat": {
"size": "7B",
"quantization": "8bit",
"domains": ["general", "education"],
"languages": ["en", "es", "zh"]
}
}
for model_name, config in model_configs.items():
config_path = models_dir / f"{model_name}.json"
with open(config_path, 'w') as f:
import json
json.dump(config, f, indent=2)
print(f" Configured: {model_name}")
print("✅ Model setup complete\n")
def initialize_knowledge_base():
"""Initialize the local knowledge base with essential content."""
print("📚 Initializing knowledge base...")
knowledge_dir = Path("data/knowledge")
# Create sample knowledge base entries
educational_content = {
"mathematics": [
"Basic arithmetic operations and properties",
"Algebra fundamentals and equation solving",
"Geometry principles and theorems",
"Statistics and probability concepts"
],
"science": [
"Scientific method and inquiry",
"Biology basics and human anatomy",
"Chemistry fundamentals",
"Physics principles and laws"
],
"languages": [
"Grammar rules and sentence structure",
"Vocabulary building techniques",
"Reading comprehension strategies",
"Writing and communication skills"
]
}
healthcare_content = {
"first_aid": [
"Basic wound care and cleaning",
"CPR and emergency response",
"Recognition of common symptoms",
"When to seek medical attention"
],
"preventive_care": [
"Hygiene and sanitation practices",
"Nutrition and healthy eating",
"Exercise and physical activity",
"Mental health and stress management"
],
"common_conditions": [
"Cold and flu management",
"Digestive health basics",
"Skin care and common issues",
"Pain management techniques"
]
}
# Save knowledge base content
import json
with open(knowledge_dir / "educational_base.json", 'w') as f:
json.dump(educational_content, f, indent=2)
with open(knowledge_dir / "healthcare_base.json", 'w') as f:
json.dump(healthcare_content, f, indent=2)
print(" Educational knowledge base: ✅")
print(" Healthcare knowledge base: ✅")
print("✅ Knowledge base initialization complete\n")
def configure_security():
"""Set up security and privacy configurations."""
print("🔒 Configuring security settings...")
# Create security configuration
security_config = {
"encryption": {
"enabled": True,
"algorithm": "AES-256",
"key_derivation": "PBKDF2"
},
"privacy": {
"data_retention_days": 30,
"anonymize_logs": True,
"local_only": True
},
"content_filtering": {
"enabled": True,
"strict_mode": True,
"blocked_categories": ["adult", "violence", "harmful"]
}
}
import json
with open("data/user/security_config.json", 'w') as f:
json.dump(security_config, f, indent=2)
print("✅ Security configuration complete\n")
def main():
"""Main setup function."""
print("=" * 60)
print("🧠 LocalMind - LIVE-OFFLINE AI Assistant Setup")
print("=" * 60)
print()
try:
check_system_requirements()
create_directory_structure()
download_models()
initialize_knowledge_base()
configure_security()
print("🎉 LocalMind setup complete!")
print()
print("Next steps:")
print("1. Run: python src/app.py --cli (for command-line interface)")
print("2. Run: python src/app.py --gui (for graphical interface)")
print("3. Check config.yaml for customization options")
print()
print("LocalMind is now ready for LIVE-OFFLINE operation! 🚀")
except Exception as e:
print(f"❌ Setup failed: {e}")
print("Please check the error and try again.")
sys.exit(1)
if __name__ == "__main__":
# Standard setuptools configuration
setup(
name=PROJECT_NAME,
version=VERSION,
description=DESCRIPTION,
author=AUTHOR,
license=LICENSE,
packages=find_packages(),
python_requires=f">={MIN_PYTHON_VERSION[0]}.{MIN_PYTHON_VERSION[1]}",
install_requires=[
line.strip() for line in open('requirements.txt').readlines()
if line.strip() and not line.startswith('#')
],
entry_points={
'console_scripts': [
'localmind=src.app:main',
],
},
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Education',
'Intended Audience :: Healthcare Industry',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Education',
'Topic :: Scientific/Engineering :: Medical Science Apps.',
],
)
# Run setup if called directly
if len(sys.argv) > 1 and sys.argv[1] == 'install':
main()