Spaces:
Sleeping
Sleeping
File size: 5,501 Bytes
29104c7 |
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 |
#!/usr/bin/env python3
"""
DigiTwin RAG Setup Script
Helps users install and configure the RAG system dependencies
"""
import subprocess
import sys
import os
from pathlib import Path
def run_command(command, description):
"""Run a command and handle errors"""
print(f"π {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"β
{description} completed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"β {description} failed: {e}")
print(f"Error output: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible"""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("β Python 3.8 or higher is required")
return False
print(f"β
Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
def install_dependencies():
"""Install RAG dependencies"""
print("π Installing DigiTwin RAG Dependencies")
print("=" * 50)
# Check Python version
if not check_python_version():
return False
# Install core dependencies
dependencies = [
("sentence-transformers", "Sentence Transformers for embeddings"),
("faiss-cpu", "FAISS vector database"),
("weaviate-client", "Weaviate vector database client"),
("groq", "Groq LLM API client"),
("ollama", "Ollama local LLM client"),
("numpy", "Numerical computing"),
("pandas", "Data manipulation"),
("streamlit", "Web application framework")
]
success_count = 0
for package, description in dependencies:
if run_command(f"pip install {package}", f"Installing {description}"):
success_count += 1
print(f"\nπ Installation Summary: {success_count}/{len(dependencies)} packages installed successfully")
return success_count == len(dependencies)
def setup_environment():
"""Setup environment variables and configuration"""
print("\nπ§ Setting up environment...")
# Create .env file template
env_content = """# DigiTwin RAG Environment Configuration
# Groq API Configuration
# Get your API key from: https://console.groq.com/
GROQ_API_KEY=your_groq_api_key_here
# Ollama Configuration (optional)
# Install Ollama from: https://ollama.ai/
OLLAMA_HOST=http://localhost:11434
# Vector Database Configuration
# Weaviate (optional) - Install with: docker run -d -p 8080:8080 semitechnologies/weaviate:1.22.4
WEAVIATE_URL=http://localhost:8080
# Embedding Model Configuration
EMBEDDING_MODEL=all-MiniLM-L6-v2
"""
env_file = Path(".env")
if not env_file.exists():
with open(env_file, "w") as f:
f.write(env_content)
print("β
Created .env file template")
print("π Please edit .env file with your API keys")
else:
print("βΉοΈ .env file already exists")
def create_directories():
"""Create necessary directories"""
print("\nπ Creating directories...")
directories = [
"vector_store",
"logs",
"models"
]
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print(f"β
Created directory: {directory}")
def test_installation():
"""Test the RAG installation"""
print("\nπ§ͺ Testing RAG installation...")
test_script = """
import sys
import importlib
# Test imports
modules_to_test = [
'sentence_transformers',
'faiss',
'weaviate',
'groq',
'ollama',
'numpy',
'pandas',
'streamlit'
]
print("Testing module imports...")
for module in modules_to_test:
try:
importlib.import_module(module)
print(f"β
{module}")
except ImportError as e:
print(f"β {module}: {e}")
print("\\nTesting embedding model...")
try:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
test_embedding = model.encode(['test sentence'])
print(f"β
Embedding model working (shape: {test_embedding.shape})")
except Exception as e:
print(f"β Embedding model failed: {e}")
print("\\nRAG system test completed!")
"""
with open("test_rag.py", "w") as f:
f.write(test_script)
if run_command("python test_rag.py", "Running RAG system test"):
print("β
RAG system test passed!")
os.remove("test_rag.py")
else:
print("β RAG system test failed. Please check the errors above.")
def main():
"""Main setup function"""
print("π€ DigiTwin RAG Setup")
print("=" * 50)
# Install dependencies
if not install_dependencies():
print("\nβ Some dependencies failed to install. Please check the errors above.")
return
# Setup environment
setup_environment()
# Create directories
create_directories()
# Test installation
test_installation()
print("\nπ Setup completed!")
print("\nπ Next steps:")
print("1. Edit .env file with your API keys")
print("2. Install Ollama (optional): https://ollama.ai/")
print("3. Start Weaviate (optional): docker run -d -p 8080:8080 semitechnologies/weaviate:1.22.4")
print("4. Run the application: streamlit run notifs.py")
print("\nπ Happy coding with DigiTwin RAG!")
if __name__ == "__main__":
main()
|