Spaces:
Sleeping
Add Hugging Face Spaces deployment configuration
Browse filesAdded files for deploying AI Personas to Hugging Face Spaces with GPU:
1. requirements_hf.txt - Dependencies for HF Spaces deployment
- Includes PyTorch, transformers, PEFT for Be.FM model
- Optimized for GPU inference on T4/A10G hardware
2. README_HF.md - Space homepage with metadata
- Hugging Face Space configuration in frontmatter
- User-facing documentation
- Model selection guide
3. .streamlit/config.toml - Streamlit configuration
- Custom theme colors
- Server settings for HF deployment
- Browser optimizations
4. DEPLOY_TO_HF.md - Complete deployment guide
- Step-by-step instructions for HF Spaces setup
- Cost estimates for GPU tiers
- Troubleshooting tips
- Secret management for API keys
This enables colleagues to access the app via browser with GPU-accelerated
Be.FM model at ~$0.60/hour on T4 small GPU.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- .streamlit/config.toml +14 -0
- DEPLOY_TO_HF.md +142 -0
- README_HF.md +42 -0
- requirements_hf.txt +21 -0
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
primaryColor = "#667eea"
|
| 3 |
+
backgroundColor = "#FFFFFF"
|
| 4 |
+
secondaryBackgroundColor = "#f0f2f6"
|
| 5 |
+
textColor = "#262730"
|
| 6 |
+
font = "sans serif"
|
| 7 |
+
|
| 8 |
+
[server]
|
| 9 |
+
headless = true
|
| 10 |
+
enableCORS = false
|
| 11 |
+
enableXsrfProtection = true
|
| 12 |
+
|
| 13 |
+
[browser]
|
| 14 |
+
gatherUsageStats = false
|
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploying AI Personas to Hugging Face Spaces
|
| 2 |
+
|
| 3 |
+
## Prerequisites
|
| 4 |
+
|
| 5 |
+
1. **Hugging Face Account**: Sign up at https://huggingface.co/join
|
| 6 |
+
2. **Git installed** on your Mac (you already have this)
|
| 7 |
+
|
| 8 |
+
## Step-by-Step Deployment
|
| 9 |
+
|
| 10 |
+
### 1. Create a New Space
|
| 11 |
+
|
| 12 |
+
1. Go to https://huggingface.co/spaces
|
| 13 |
+
2. Click "Create new Space"
|
| 14 |
+
3. Fill in:
|
| 15 |
+
- **Space name**: `ai-personas-urban-planning` (or your choice)
|
| 16 |
+
- **License**: MIT
|
| 17 |
+
- **SDK**: Streamlit
|
| 18 |
+
- **Space hardware**: **T4 small** (GPU, ~$0.60/hour) or **A10G small** (~$3/hour, faster)
|
| 19 |
+
- **Visibility**: Public or Private (your choice)
|
| 20 |
+
4. Click "Create Space"
|
| 21 |
+
|
| 22 |
+
### 2. Clone Your New Space
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
# In terminal on your Mac
|
| 26 |
+
cd ~/Desktop # or wherever you want
|
| 27 |
+
|
| 28 |
+
# Clone the empty space (replace USERNAME and SPACENAME)
|
| 29 |
+
git clone https://huggingface.co/spaces/USERNAME/SPACENAME
|
| 30 |
+
cd SPACENAME
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
### 3. Copy Your AI Personas Files
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
# From your AI_Personas directory, copy everything except git history
|
| 37 |
+
cd ~/path/to/AI_Personas
|
| 38 |
+
|
| 39 |
+
# Copy all necessary files
|
| 40 |
+
cp -r data/ pages/ src/ ../SPACENAME/
|
| 41 |
+
cp web_app.py ../SPACENAME/
|
| 42 |
+
cp requirements_hf.txt ../SPACENAME/requirements.txt
|
| 43 |
+
cp README_HF.md ../SPACENAME/README.md
|
| 44 |
+
cp -r .streamlit/ ../SPACENAME/
|
| 45 |
+
|
| 46 |
+
# Copy these if they exist
|
| 47 |
+
cp *.py ../SPACENAME/ 2>/dev/null || true
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
### 4. Commit and Push to Hugging Face
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
cd ../SPACENAME
|
| 54 |
+
|
| 55 |
+
# Add all files
|
| 56 |
+
git add .
|
| 57 |
+
|
| 58 |
+
# Commit
|
| 59 |
+
git commit -m "Initial deployment of AI Personas app"
|
| 60 |
+
|
| 61 |
+
# Push to Hugging Face (will trigger deployment)
|
| 62 |
+
git push
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
### 5. Wait for Build
|
| 66 |
+
|
| 67 |
+
1. Go to your Space page: `https://huggingface.co/spaces/USERNAME/SPACENAME`
|
| 68 |
+
2. Watch the "Building" status (takes 5-10 minutes first time)
|
| 69 |
+
3. Once it says "Running", click the app!
|
| 70 |
+
|
| 71 |
+
### 6. Configure Secrets (for Anthropic Claude)
|
| 72 |
+
|
| 73 |
+
If you want the Anthropic Claude option to work:
|
| 74 |
+
|
| 75 |
+
1. Go to your Space → Settings → Repository secrets
|
| 76 |
+
2. Add secret:
|
| 77 |
+
- **Name**: `ANTHROPIC_API_KEY`
|
| 78 |
+
- **Value**: Your Claude API key
|
| 79 |
+
3. Save
|
| 80 |
+
|
| 81 |
+
Then update `src/llm/anthropic_client.py` to use it:
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
# In __init__ method, change:
|
| 85 |
+
self.api_key = api_key or os.environ.get("ANTHROPIC_API_KEY")
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Cost Estimates
|
| 89 |
+
|
| 90 |
+
- **T4 small GPU**: ~$0.60/hour = ~$14/day if running 24/7
|
| 91 |
+
- **Free tier**: CPU only (Be.FM won't work well)
|
| 92 |
+
- **Pause when not in use**: Turn off in Space settings to save costs
|
| 93 |
+
|
| 94 |
+
## Sharing with Colleagues
|
| 95 |
+
|
| 96 |
+
Once deployed, share the URL:
|
| 97 |
+
```
|
| 98 |
+
https://huggingface.co/spaces/USERNAME/SPACENAME
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
Anyone can use it! No installation needed.
|
| 102 |
+
|
| 103 |
+
## Troubleshooting
|
| 104 |
+
|
| 105 |
+
**Space keeps crashing?**
|
| 106 |
+
- Check the "Logs" tab in your Space
|
| 107 |
+
- You might need more RAM → upgrade to A10G
|
| 108 |
+
|
| 109 |
+
**Be.FM loading slowly?**
|
| 110 |
+
- First load takes 2-3 minutes to download model
|
| 111 |
+
- After that, it's cached and loads in ~30 seconds
|
| 112 |
+
|
| 113 |
+
**Want to update the app?**
|
| 114 |
+
```bash
|
| 115 |
+
# Make changes locally
|
| 116 |
+
git add .
|
| 117 |
+
git commit -m "Update app"
|
| 118 |
+
git push
|
| 119 |
+
|
| 120 |
+
# Space will auto-rebuild in 2-5 minutes
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
## Alternative: Free CPU-Only Deployment
|
| 124 |
+
|
| 125 |
+
If you don't want to pay for GPU:
|
| 126 |
+
|
| 127 |
+
1. Change hardware to "CPU basic" (free)
|
| 128 |
+
2. Modify `src/llm/local_model_client.py`:
|
| 129 |
+
```python
|
| 130 |
+
# Force CPU mode
|
| 131 |
+
self.device = "cpu"
|
| 132 |
+
```
|
| 133 |
+
3. Set expectation with colleagues: responses take 2-3 minutes each
|
| 134 |
+
|
| 135 |
+
Free but slow!
|
| 136 |
+
|
| 137 |
+
---
|
| 138 |
+
|
| 139 |
+
## Need Help?
|
| 140 |
+
|
| 141 |
+
Check the Hugging Face Spaces documentation:
|
| 142 |
+
https://huggingface.co/docs/hub/spaces-overview
|
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AI Personas for Urban Planning
|
| 3 |
+
emoji: 🏙️
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.28.0"
|
| 8 |
+
app_file: web_app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# 🏙️ AI Personas for Urban Planning
|
| 14 |
+
|
| 15 |
+
An AI-powered simulation system that models diverse stakeholder perspectives on urban planning issues using LLM-based personas.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
- **Interactive Chat**: Query individual personas to understand their unique perspectives
|
| 20 |
+
- **Population Analysis**: Analyze responses across population distributions
|
| 21 |
+
- **Opinion Equilibria**: Model how opinions evolve through social influence dynamics
|
| 22 |
+
- **Edit Personas**: Customize stakeholder profiles and urban contexts
|
| 23 |
+
|
| 24 |
+
## Models
|
| 25 |
+
|
| 26 |
+
- **Anthropic Claude**: High-quality API-based responses (requires API key)
|
| 27 |
+
- **Local Be.FM**: Stanford's Be.FM model running on GPU (free, no API key needed)
|
| 28 |
+
|
| 29 |
+
## Usage
|
| 30 |
+
|
| 31 |
+
1. Select a model from the sidebar (Be.FM recommended for this Space)
|
| 32 |
+
2. Choose a persona or use Population Analysis
|
| 33 |
+
3. Ask questions about urban planning scenarios
|
| 34 |
+
4. Explore how different stakeholders respond
|
| 35 |
+
|
| 36 |
+
## About Be.FM
|
| 37 |
+
|
| 38 |
+
Be.FM is a fine-tuned Llama-3.1-8B model trained on behavioral economics data, designed to simulate realistic human decision-making in urban planning contexts.
|
| 39 |
+
|
| 40 |
+
## Credits
|
| 41 |
+
|
| 42 |
+
Built with Streamlit, Anthropic Claude, and Stanford's Be.FM model.
|
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces Requirements
|
| 2 |
+
# For GPU-accelerated deployment with Be.FM model
|
| 3 |
+
|
| 4 |
+
streamlit>=1.28.0
|
| 5 |
+
anthropic>=0.7.0
|
| 6 |
+
pydantic>=2.0.0
|
| 7 |
+
plotly>=5.17.0
|
| 8 |
+
networkx>=3.1
|
| 9 |
+
numpy>=1.24.0
|
| 10 |
+
pandas>=2.0.0
|
| 11 |
+
|
| 12 |
+
# PyTorch and ML dependencies
|
| 13 |
+
torch>=2.1.0
|
| 14 |
+
transformers>=4.35.0
|
| 15 |
+
accelerate>=0.24.0
|
| 16 |
+
peft>=0.6.0
|
| 17 |
+
sentencepiece>=0.1.99
|
| 18 |
+
protobuf>=3.20.0
|
| 19 |
+
|
| 20 |
+
# For better performance
|
| 21 |
+
bitsandbytes>=0.41.0
|