Spaces:
Runtime error
Runtime error
Commit ·
0fdb4d7
1
Parent(s): 07ff701
HF deployment guide
Browse files- DEPLOY_NOW.md +113 -0
- HF_SPACES_DEPLOYMENT.md +85 -0
DEPLOY_NOW.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploy to Hugging Face Spaces - Quick Guide
|
| 2 |
+
|
| 3 |
+
## Your Current Setup
|
| 4 |
+
✅ You already have HF remote: `git@hf.co:spaces/Shefing/aitruism`
|
| 5 |
+
✅ README.md updated with Streamlit SDK config
|
| 6 |
+
✅ Enhanced AlignmentCheck with quantitative detection
|
| 7 |
+
|
| 8 |
+
## Step 1: Commit All Changes
|
| 9 |
+
|
| 10 |
+
```bash
|
| 11 |
+
# Add all modified files
|
| 12 |
+
git add README.md
|
| 13 |
+
git add HF_SPACES_DEPLOYMENT.md
|
| 14 |
+
git add DEPLOY_NOW.md
|
| 15 |
+
git add multi_agent_demo/direct_scanner_wrapper.py
|
| 16 |
+
git add multi_agent_demo/firewall.py
|
| 17 |
+
git add multi_agent_demo/ui/conversation_builder.py
|
| 18 |
+
git add multi_agent_demo/ui/results_display.py
|
| 19 |
+
|
| 20 |
+
# Commit changes
|
| 21 |
+
git commit -m "feat: Prepare for HF Spaces deployment with enhanced quantitative detection
|
| 22 |
+
|
| 23 |
+
- Update README.md with Streamlit SDK configuration
|
| 24 |
+
- Add quantitative misalignment detection (35 vs 28 orders)
|
| 25 |
+
- Support .txt file import for scenarios
|
| 26 |
+
- Improve AlignmentCheck prompt focusing
|
| 27 |
+
- Add deployment documentation"
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## Step 2: Push to Hugging Face
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
# Push to HF Spaces
|
| 34 |
+
git push huggingface main
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
**What happens next:**
|
| 38 |
+
- HF will detect the Streamlit SDK from README.md
|
| 39 |
+
- It will install dependencies from requirements_minimal.txt
|
| 40 |
+
- Your app will be live in ~2-5 minutes at: https://huggingface.co/spaces/Shefing/aitruism
|
| 41 |
+
|
| 42 |
+
## Step 3: Add API Keys (Secrets)
|
| 43 |
+
|
| 44 |
+
After deployment starts, add your secrets:
|
| 45 |
+
|
| 46 |
+
1. Go to: https://huggingface.co/spaces/Shefing/aitruism/settings
|
| 47 |
+
2. Scroll to **Repository secrets**
|
| 48 |
+
3. Click **+ Add a new secret**
|
| 49 |
+
4. Add these three secrets:
|
| 50 |
+
|
| 51 |
+
| Name | Value |
|
| 52 |
+
|------|-------|
|
| 53 |
+
| `OPENAI_API_KEY` | Your OpenAI API key (starts with sk-proj-...) |
|
| 54 |
+
| `TOGETHER_API_KEY` | Your Together AI key |
|
| 55 |
+
| `HF_TOKEN` | Your HuggingFace token (optional, for PromptGuard) |
|
| 56 |
+
|
| 57 |
+
5. After adding secrets, click **Restart this Space** (top right)
|
| 58 |
+
|
| 59 |
+
## Step 4: Test Your Deployment
|
| 60 |
+
|
| 61 |
+
1. Go to: https://huggingface.co/spaces/Shefing/aitruism
|
| 62 |
+
2. Wait for "Building" to complete (~2-5 minutes)
|
| 63 |
+
3. Test with your delivery route scenario
|
| 64 |
+
4. Verify AlignmentCheck detects the 35 vs 28 orders discrepancy
|
| 65 |
+
|
| 66 |
+
## Monitoring Performance
|
| 67 |
+
|
| 68 |
+
Watch the **Logs** tab to see:
|
| 69 |
+
- Build progress
|
| 70 |
+
- Runtime logs
|
| 71 |
+
- Scanner debug output (🔢 QUANTITATIVE REQUIREMENT DETECTED, etc.)
|
| 72 |
+
|
| 73 |
+
## Troubleshooting
|
| 74 |
+
|
| 75 |
+
### If build fails:
|
| 76 |
+
- Check the **Logs** tab for error messages
|
| 77 |
+
- Common issues:
|
| 78 |
+
- Missing dependencies → Update requirements_minimal.txt
|
| 79 |
+
- Port conflicts → Streamlit handles this automatically
|
| 80 |
+
- Memory issues → Upgrade to CPU Upgrade ($25/mo)
|
| 81 |
+
|
| 82 |
+
### If app is slow:
|
| 83 |
+
- Check the **Metrics** tab for CPU/RAM usage
|
| 84 |
+
- If consistently >80% → Consider upgrading to CPU Upgrade
|
| 85 |
+
- For 3 users, CPU Basic should be fine
|
| 86 |
+
|
| 87 |
+
### If scanners fail:
|
| 88 |
+
- Check Repository secrets are set correctly
|
| 89 |
+
- Restart the space after adding secrets
|
| 90 |
+
- Check logs for API key errors
|
| 91 |
+
|
| 92 |
+
## Next Steps After Successful Deployment
|
| 93 |
+
|
| 94 |
+
1. **Test thoroughly** with all 3 concurrent users
|
| 95 |
+
2. **Monitor performance** for a few days
|
| 96 |
+
3. **Upgrade if needed**: Settings → Change hardware → CPU Upgrade ($25/mo)
|
| 97 |
+
|
| 98 |
+
## Rollback (if needed)
|
| 99 |
+
|
| 100 |
+
If something goes wrong:
|
| 101 |
+
```bash
|
| 102 |
+
# Go back to previous commit
|
| 103 |
+
git reset --hard HEAD~1
|
| 104 |
+
|
| 105 |
+
# Force push to HF
|
| 106 |
+
git push huggingface main --force
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## Questions?
|
| 110 |
+
|
| 111 |
+
- HF Spaces docs: https://huggingface.co/docs/hub/spaces
|
| 112 |
+
- Streamlit docs: https://docs.streamlit.io/
|
| 113 |
+
- Your app: https://huggingface.co/spaces/Shefing/aitruism
|
HF_SPACES_DEPLOYMENT.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploying to Hugging Face Spaces
|
| 2 |
+
|
| 3 |
+
## Quick Start (5 minutes)
|
| 4 |
+
|
| 5 |
+
### 1. Create Space
|
| 6 |
+
1. Go to https://huggingface.co/new-space
|
| 7 |
+
2. Choose:
|
| 8 |
+
- **Name**: `ai-guards-demo`
|
| 9 |
+
- **SDK**: Streamlit
|
| 10 |
+
- **Hardware**: CPU basic (free) or CPU upgrade ($25/mo)
|
| 11 |
+
- **Visibility**: Public or Private
|
| 12 |
+
|
| 13 |
+
### 2. Add Configuration
|
| 14 |
+
Create `README.md` in repo root:
|
| 15 |
+
|
| 16 |
+
```yaml
|
| 17 |
+
---
|
| 18 |
+
title: AI Agent Guards Demo
|
| 19 |
+
emoji: 🛡️
|
| 20 |
+
colorFrom: blue
|
| 21 |
+
colorTo: green
|
| 22 |
+
sdk: streamlit
|
| 23 |
+
sdk_version: 1.32.0
|
| 24 |
+
app_file: multi_agent_demo/guards_demo_ui.py
|
| 25 |
+
pinned: false
|
| 26 |
+
license: mit
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
# AI Agent Guards Testing Application
|
| 30 |
+
|
| 31 |
+
Demo app for testing AI Agent Guards (security scanners) with custom scenarios.
|
| 32 |
+
|
| 33 |
+
## Features
|
| 34 |
+
- PromptGuard: Detects malicious prompts
|
| 35 |
+
- AlignmentCheck: Identifies goal hijacking
|
| 36 |
+
- FactChecker: AI-powered fact verification
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### 3. Push to HF
|
| 40 |
+
```bash
|
| 41 |
+
# Add HF remote
|
| 42 |
+
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/ai-guards-demo
|
| 43 |
+
|
| 44 |
+
# Push
|
| 45 |
+
git push hf main
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
### 4. Add Secrets
|
| 49 |
+
In HF Spaces settings, add:
|
| 50 |
+
- `OPENAI_API_KEY`
|
| 51 |
+
- `TOGETHER_API_KEY`
|
| 52 |
+
- `HF_TOKEN`
|
| 53 |
+
|
| 54 |
+
### 5. Done!
|
| 55 |
+
Your app will be live at: `https://huggingface.co/spaces/YOUR_USERNAME/ai-guards-demo`
|
| 56 |
+
|
| 57 |
+
## Cost Comparison
|
| 58 |
+
|
| 59 |
+
| Tier | vCPU | RAM | Storage | Cost | Best For |
|
| 60 |
+
|------|------|-----|---------|------|----------|
|
| 61 |
+
| CPU Basic (Free) | 2 | 16GB | 50GB | $0 | Testing, 1-3 users |
|
| 62 |
+
| CPU Upgrade | 8 | 32GB | 100GB | $25/mo | Production, 3-10 users |
|
| 63 |
+
| GPU T4 | 4 | 16GB | 100GB | $60/mo | Large models |
|
| 64 |
+
|
| 65 |
+
## Performance Tips
|
| 66 |
+
|
| 67 |
+
1. **Use CPU Basic first** - likely sufficient for your load
|
| 68 |
+
2. **Monitor usage** - HF provides metrics dashboard
|
| 69 |
+
3. **Upgrade if needed** - one-click upgrade to $25/mo tier
|
| 70 |
+
4. **Cache models** - your app already does this well
|
| 71 |
+
|
| 72 |
+
## Alternative: Railway.app
|
| 73 |
+
|
| 74 |
+
If HF doesn't work:
|
| 75 |
+
```bash
|
| 76 |
+
# Install Railway CLI
|
| 77 |
+
npm i -g @railway/cli
|
| 78 |
+
|
| 79 |
+
# Login and deploy
|
| 80 |
+
railway login
|
| 81 |
+
railway init
|
| 82 |
+
railway up
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
Cost: ~$10-20/mo for similar resources.
|