-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
214 lines (180 loc) · 6.16 KB
/
setup.py
File metadata and controls
214 lines (180 loc) · 6.16 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
import os
import sys
import subprocess
import platform
from pathlib import Path
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 8):
print("❌ Python 3.8+ required")
return False
print(f"✅ Python {sys.version} detected")
return True
def install_ollama():
"""Install Ollama based on OS"""
system = platform.system().lower()
print("🔧 Installing Ollama...")
try:
if system == "linux":
subprocess.run(["curl", "-fsSL", "https://ollama.com/install.sh", "|", "sh"], shell=True, check=True)
elif system == "darwin": # macOS
print("Please install Ollama from https://ollama.com/download")
print("Or use: brew install ollama")
elif system == "windows":
print("Please download and install Ollama from https://ollama.com/download")
print("✅ Ollama installation initiated")
return True
except Exception as e:
print(f"❌ Ollama installation failed: {e}")
return False
def setup_virtual_environment():
"""Setup Python virtual environment"""
venv_path = Path("venv")
if venv_path.exists():
print("✅ Virtual environment already exists")
return True
try:
print("🔧 Creating virtual environment...")
subprocess.run([sys.executable, "-m", "venv", "venv"], check=True)
print("✅ Virtual environment created")
return True
except Exception as e:
print(f"❌ Failed to create virtual environment: {e}")
return False
def install_requirements():
"""Install Python requirements"""
try:
print("🔧 Installing Python packages...")
# Determine pip executable based on OS
if platform.system() == "Windows":
pip_cmd = ["venv/Scripts/pip"]
else:
pip_cmd = ["venv/bin/pip"]
# Upgrade pip first
subprocess.run(pip_cmd + ["install", "--upgrade", "pip"], check=True)
# Install requirements
subprocess.run(pip_cmd + ["install", "-r", "requirements.txt"], check=True)
print("✅ All packages installed successfully")
return True
except Exception as e:
print(f"❌ Package installation failed: {e}")
return False
def download_ai_models():
"""Download required AI models"""
models = ["llama3.1:8b", "nomic-embed-text"]
for model in models:
try:
print(f"🔧 Downloading {model}...")
subprocess.run(["ollama", "pull", model], check=True)
print(f"✅ {model} downloaded successfully")
except Exception as e:
print(f"⚠️ Failed to download {model}: {e}")
def create_directories():
"""Create necessary directories"""
directories = ["data", "logs", "exports", "temp"]
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print(f"✅ Created directory: {directory}")
def create_config_files():
"""Create configuration files"""
# .env file
env_content = """# Local AI System Configuration
DATA_DIRECTORY=./data
LOG_LEVEL=INFO
MODEL_NAME=llama3.1:8b
EMBEDDING_MODEL=nomic-embed-text
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
MAX_FILE_SIZE=100MB
ENABLE_SYSTEM_FILES=false
"""
# VS Code settings
vscode_settings = """{
"python.defaultInterpreterPath": "./venv/bin/python",
"python.terminal.activateEnvironment": true,
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"files.associations": {
"*.py": "python"
},
"editor.formatOnSave": true,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
]
}"""
# VS Code launch configuration
launch_config = """{
"version": "0.2.0",
"configurations": [
{
"name": "Run Local AI System",
"type": "python",
"request": "launch",
"program": "local_ai_system.py",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
},
{
"name": "Streamlit App",
"type": "python",
"request": "launch",
"module": "streamlit",
"args": ["run", "local_ai_system.py"],
"console": "integratedTerminal"
}
]
}"""
# Create files
with open(".env", "w") as f:
f.write(env_content)
print("✅ Created .env configuration")
# Create VS Code directory and files
vscode_dir = Path(".vscode")
vscode_dir.mkdir(exist_ok=True)
with open(vscode_dir / "settings.json", "w") as f:
f.write(vscode_settings)
print("✅ Created VS Code settings")
with open(vscode_dir / "launch.json", "w") as f:
f.write(launch_config)
print("✅ Created VS Code launch configuration")
def main():
"""Main setup function"""
print("🚀 Setting up Local AI File Manager...")
print("=" * 50)
# Check Python version
if not check_python_version():
sys.exit(1)
# Setup virtual environment
if not setup_virtual_environment():
sys.exit(1)
# Install requirements
if not install_requirements():
sys.exit(1)
# Create directories
create_directories()
# Create configuration files
create_config_files()
# Install Ollama
install_ollama()
# Download models (optional, might take time)
download_models = input("\\n🤖 Download AI models now? (y/N): ").lower().strip()
if download_models == 'y':
download_ai_models()
print("\\n" + "=" * 50)
print("🎉 Setup complete!")
print("\\nNext steps:")
print("1. Activate virtual environment:")
if platform.system() == "Windows":
print(" venv\\\\Scripts\\\\activate")
else:
print(" source venv/bin/activate")
print("\\n2. Start the application:")
print(" streamlit run local_ai_system.py")
print("\\n3. Or open in VS Code and press F5")
if __name__ == "__main__":
main()