Spaces:
Sleeping
Sleeping
File size: 4,831 Bytes
f123c00 | 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 | # π Deployment Guide: Hugging Face Spaces
This guide will help you deploy your Multi-Personality Chatbot to Hugging Face Spaces for **free public access**.
## π Prerequisites
1. **Hugging Face Account** (free)
- Sign up at: https://huggingface.co/join
- Verify your email
2. **Git and Git LFS installed**
- Git: https://git-scm.com/downloads
- Git LFS: https://git-lfs.github.com/
## π― Step-by-Step Deployment
### Step 1: Create a Hugging Face Space
1. Go to https://huggingface.co/spaces
2. Click **"Create new Space"**
3. Fill in:
- **Space name**: `personality-chatbot` (or your preferred name)
- **License**: MIT or Apache 2.0
- **Select SDK**: Choose **Gradio**
- **Hardware**: Start with **CPU basic** (free), upgrade to GPU if needed
- **Visibility**: Public (so anyone can access)
4. Click **"Create Space"**
### Step 2: Set Up Local Repository
Open PowerShell in your project folder:
```powershell
# Navigate to your project
cd C:\Users\dcast\LLM\Project3\llm-project
# Initialize git (if not already done)
git init
# Install Git LFS (for large model files)
git lfs install
# Track large files with Git LFS
git lfs track "*.safetensors"
git lfs track "*.bin"
git lfs track "*.json"
# Add all files
git add .gitattributes
git add .
# Commit
git commit -m "Initial commit: Multi-personality chatbot"
```
### Step 3: Push to Hugging Face
Replace `YOUR_USERNAME` and `YOUR_SPACE_NAME` with your actual values:
```powershell
# Add Hugging Face remote
git remote add space https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
# Push to Hugging Face
git push --set-upstream space main
```
**Authentication**: You'll be prompted for username and password
- **Username**: Your Hugging Face username
- **Password**: Use your **Hugging Face Access Token** (not your account password)
- Get token at: https://huggingface.co/settings/tokens
- Create a **Write** token
### Step 4: Wait for Build
1. Go to your Space URL: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
2. The Space will automatically build (takes 5-15 minutes first time)
3. You'll see build logs in the "Logs" tab
4. Once done, your app will be live! π
### Step 5: Share Your App
Your app will be accessible at:
```
https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space
```
Anyone can access this URL without authentication!
## π Troubleshooting
### "Repository too large" error
**Problem**: Adapter files are too big for free tier
**Solution**: Upload adapters to Hugging Face Model Hub separately
1. Create model repos for each adapter:
```powershell
# Install huggingface-hub
pip install huggingface-hub
# Upload each adapter (run in Python)
python -c "from huggingface_hub import HfApi; api = HfApi(); api.upload_folder(folder_path='pirate-lora-adapter', repo_id='YOUR_USERNAME/pirate-lora', repo_type='model')"
```
2. Update `app.py` to load from Hub:
```python
ADAPTERS = {
"π΄ββ οΈ Pirate": "YOUR_USERNAME/pirate-lora",
"π§ Yoda": "YOUR_USERNAME/yoda-lora",
"π€ Nerd": "YOUR_USERNAME/nerd-lora",
"π§ Brainrot": "YOUR_USERNAME/brainrot-lora",
}
```
### "Out of memory" on CPU
**Solution**: Upgrade to GPU hardware
1. Go to Space Settings
2. Click "Change hardware"
3. Select **"GPU - T4 small"** (free tier)
### Build fails with "Module not found"
**Solution**: Check `requirements.txt` has all dependencies
```
gradio>=4.0.0
torch>=2.0.0
transformers>=4.35.0
peft>=0.7.0
accelerate>=0.24.0
safetensors>=0.4.0
```
## π¨ Customization
### Change app title/description
Edit `app.py` - modify the `gr.Markdown()` sections
### Add more personalities
1. Train a new adapter
2. Add to `ADAPTERS` dict in `app.py`
3. Upload the new adapter folder
4. Push changes: `git add . && git commit -m "Add new personality" && git push space main`
### Improve performance
- Use GPU hardware (Space settings)
- Reduce `max_tokens` default
- Add response caching
## π Free Tier Limits
**Hugging Face Spaces Free Tier:**
- β
CPU: Unlimited (but slow for LLMs)
- β
GPU T4: Limited hours/month (check your account)
- β
Storage: 50GB total
- β
Persistence: 24/7 uptime
- β
Public access: Unlimited users
**Tips to stay within limits:**
- Start with CPU, upgrade to GPU if too slow
- Keep model size small (Qwen2-0.5B is perfect)
- Monitor usage in Space Settings
## π Useful Links
- Hugging Face Spaces Docs: https://huggingface.co/docs/hub/spaces
- Gradio Docs: https://www.gradio.app/docs
- Git LFS Guide: https://git-lfs.github.com/
## π Need Help?
If you encounter issues:
1. Check Space logs (Logs tab)
2. Check build status
3. Ask in Hugging Face Discord: https://discuss.huggingface.co/
---
**That's it!** Your chatbot is now publicly accessible to anyone with the URL. π
|