Spaces:
Running on Zero
Running on Zero
File size: 7,624 Bytes
0828c2c | 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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | # π Setup Guide - ProfillyBot
This guide will walk you through setting up ProfillyBot, your personal profile chatbot, from scratch.
## π Prerequisites
### 1. Install Python 3.10+
```bash
# Check your Python version
python --version # Should be 3.10 or higher
```
### 2. Install UV Package Manager
```bash
# Linux/macOS
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
irm https://astral.sh/uv/install.ps1 | iex
```
### 3. Install Ollama
Download and install from [ollama.ai](https://ollama.ai)
```bash
# Verify installation
ollama --version
```
## π οΈ Local Setup
### Step 1: Clone and Install
```bash
# Clone the repository
git clone https://github.com/Tin-Hoang/slm-profile-rag.git
cd slm-profile-rag # or rename the folder to profillybot if you prefer
# Create virtual environment with UV
uv venv
# Activate virtual environment
# Linux/macOS:
source .venv/bin/activate
# Windows:
# .venv\Scripts\activate
# Install dependencies
uv pip install -r requirements.txt
```
### Step 2: Configuration
#### 2.1 Environment Variables
```bash
# Copy environment template
cp env.template .env
# Edit .env file (optional, defaults work for local development)
# Update OLLAMA_BASE_URL if needed
```
#### 2.2 Configure Your Profile
Edit `config.yaml`:
```yaml
profile:
name: "Your Full Name" # β οΈ CHANGE THIS
title: "Your Professional Title" # β οΈ CHANGE THIS
greeting: "Hi! I'm ProfillyBot, trained on {name}'s professional background..."
llm:
model: "llama3.2:3b" # Choose based on your hardware
temperature: 0.7
# Adjust other settings as needed
```
### Step 3: Pull LLM Model
```bash
# Pull the model specified in config.yaml
ollama pull llama3.2:3b
# Or try other models:
# ollama pull phi3:mini # Microsoft Phi-3 (3.8B)
# ollama pull gemma2:2b # Google Gemma 2 (2B)
# ollama pull llama3.1:8b # Larger, better quality (if you have GPU)
```
### Step 4: Add Your Documents
```bash
# Navigate to documents directory
cd data/documents
# Copy your profile documents here
# Supported formats: PDF, DOCX, HTML, TXT, MD
```
**Recommended Documents:**
- β
Resume/CV (PDF or DOCX)
- β
LinkedIn profile (export as PDF)
- β
Project reports and case studies
- β
Portfolio descriptions
- β
Publications, certifications
- β
Cover letters, personal statements
**Tips:**
- Use descriptive filenames
- Ensure documents are well-structured with headings
- Include detailed information (the more context, the better!)
- Remove the sample `SAMPLE_README.md` file
### Step 5: Build Vector Store
```bash
# Make sure you're in the project root
cd ../.. # if you're still in data/documents
# Build the vector database
python -m src.build_vectorstore
# Output should show:
# - Processing documents from: ./data/documents
# - Successfully processed X document chunks
# - β
Vector store built successfully!
```
**Troubleshooting:**
- If no documents found: Check `data/documents/` directory
- If import errors: Ensure virtual environment is activated
- If memory issues: Reduce chunk_size in `config.yaml`
### Step 6: Start Ollama (if not running)
```bash
# Start Ollama server
ollama serve
```
Keep this terminal running, or run it as a background service.
### Step 7: Run the Application
```bash
# In a new terminal (with virtual environment activated)
streamlit run app.py
# The app will open at: http://localhost:8501
```
## π¨ Customization
### Change UI Theme
Edit `.streamlit/config.toml`:
```toml
[theme]
primaryColor = "#FF4B4B" # Change to your color
backgroundColor = "#FFFFFF"
```
### Adjust RAG Settings
Edit `config.yaml`:
```yaml
document_processing:
chunk_size: 1000 # Increase for more context per chunk
chunk_overlap: 200 # Increase for better continuity
vectorstore:
search_kwargs:
k: 4 # Number of chunks to retrieve (increase for more context)
llm:
temperature: 0.7 # Lower (0.3) for factual, higher (0.9) for creative
max_tokens: 512 # Maximum response length
```
### Add Example Questions
Edit `config.yaml`:
```yaml
ui:
example_questions:
- "What is {name}'s background?"
- "What programming languages does {name} know?"
- "Tell me about {name}'s biggest project"
# Add your own questions
```
### Customize System Prompt
Edit `config.yaml`:
```yaml
llm:
system_prompt: |
You are an AI assistant representing {name}.
[Customize your instructions here]
```
## π Deployment to Hugging Face Spaces
### Option 1: Direct Upload
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
2. Click "Create new Space"
3. Choose "Streamlit" SDK
4. Upload all project files
5. Add your documents to `data/documents/`
6. Space will automatically build and deploy
### Option 2: Git Integration
```bash
# Initialize git (if not already)
git init
git add .
git commit -m "Initial commit"
# Add Hugging Face as remote
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/SPACE_NAME
# Push to deploy
git push hf main
```
### Important for HF Spaces
1. **Pre-build Vector Store**: Build locally and include `chroma_db/` in git
```bash
# Build locally
python -m src.build_vectorstore
# Remove chroma_db from .gitignore temporarily
# Commit and push
git add chroma_db/
git commit -m "Add pre-built vector store"
git push hf main
```
2. **Model Size**: Use small models (3B-7B params) for free tier
- Recommended: `llama3.2:3b`, `phi3:mini`, `gemma2:2b`
3. **Persistent Storage**: Enable in Space settings for ChromaDB
4. **Secrets**: Add API keys in Space Settings β Repository secrets
## π§ͺ Testing
```bash
# Install dev dependencies
uv pip install pytest pytest-cov ruff
# Run tests
pytest
# Run linter
ruff check .
# Format code
ruff format .
```
## π§ Common Issues
### Issue: "Ollama connection failed"
**Solution:**
```bash
# Make sure Ollama is running
ollama serve
# Check if model is pulled
ollama list
# Pull model if missing
ollama pull llama3.2:3b
```
### Issue: "Vector store not found"
**Solution:**
```bash
# Rebuild vector store
python -m src.build_vectorstore --force-rebuild
```
### Issue: "No documents found"
**Solution:**
- Check `data/documents/` has files
- Verify file extensions are supported (.pdf, .docx, .html, .txt, .md)
- Check file permissions
### Issue: "Out of memory"
**Solution:**
```yaml
# Reduce chunk size in config.yaml
document_processing:
chunk_size: 500 # Reduced from 1000
# Or use a smaller model
llm:
model: "gemma2:2b"
```
### Issue: "Slow response times"
**Solution:**
- Use smaller model: `gemma2:2b` or `phi3:mini`
- Reduce retrieval chunks: `k: 2` instead of `k: 4`
- Lower temperature: `temperature: 0.5`
- Enable GPU for Ollama (if available)
## π Performance Optimization
### For Local Development
```yaml
# config.yaml
embeddings:
device: "cuda" # If you have GPU
llm:
model: "llama3.1:8b" # Better quality with GPU
```
### For Production/HF Spaces
```yaml
embeddings:
device: "cpu"
model_name: "sentence-transformers/all-MiniLM-L6-v2" # Fast, lightweight
llm:
model: "llama3.2:3b" # Best balance for CPU
temperature: 0.6
max_tokens: 384 # Faster responses
```
## π― Next Steps
1. β
Customize your profile information
2. β
Add comprehensive documents
3. β
Test with various questions
4. β
Deploy to Hugging Face Spaces
5. β
Share the link with recruiters!
## π Support
- Check [README.md](README.md) for general information
- Review [config.yaml](config.yaml) for all options
- See [tests/](tests/) for examples
- Open an issue for bugs
---
**Happy chatting! π**
|