Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 5,807 Bytes
a8fb296 | 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 | # Yes DATABASE-DRIVEN HOMEPAGE - READY TO USE!
## What's Done
Your homepage is now **100% database-driven** with all **235 causes** ready to generate images for!
### Yes Completed
1. **API Endpoint** - `/api/trending` serves causes from parquet files
2. **Frontend Integration** - Homepage fetches from database (not hardcoded!)
3. **Image Generator** - Script to create images for ALL 235 causes
4. **Build Verified** - TypeScript compiles Yes, Build succeeds Yes
---
## Quick Start (3 Steps)
### 1. Generate Images for Your Causes
```bash
cd /home/developer/projects/open-navigator
source .venv/bin/activate
# Get Gemini API key: https://makersuite.google.com/app/apikey
echo "GEMINI_API_KEY=your_key_here" >> .env
# Generate images for ALL 235 causes (~10-15 min)
python scripts/media/generate_all_cause_images.py
# OR test with 10 first
python scripts/media/generate_all_cause_images.py --limit 10
```
### 2. Copy Images to Frontend
```bash
mkdir -p frontend/public/images/causes
cp data/media/causes/*.png frontend/public/images/causes/
```
### 3. Test Live
```bash
./start-all.sh
# Visit: http://localhost:5173
```
You should see:
- Trending causes bar with database count
- "(12 from database)" indicator
- Causes dynamically loaded
---
## Your Causes Data
**Total: 235 causes in database**
### EveryOrg Causes (39)
Popular curated categories:
- Animals
- Arts & Culture
- Civil Rights
- Climate
- Disabilities
- Education
- Health
- Housing
- ...and 31 more
### NTEE Codes (196)
Official IRS nonprofit categories:
- **A** - Arts, Culture & Humanities
- **B** - Education
- **C** - Environment
- **D** - Animal-Related
- **E** - Health
- **F** - Mental Health
- ...all 26 major groups + subcategories
---
## Generated Images
For each cause, you get:
1. **Banner** (1200x600px)
- `everyorg_climate_banner.png`
- `ntee_E_banner.png`
- Use: Hero images, featured stories
2. **Square** (400x400px)
- `everyorg_climate_square.png`
- `ntee_E_square.png`
- Use: Topic cards, trending bar
3. **AI Color Scheme**
- Gemini generates thematic colors
- Saved in `metadata.json`
---
## API Endpoints
### `GET /api/trending`
**Get trending causes:**
```bash
# Mix of both sources (default)
curl http://localhost:8001/api/trending?source=mixed&limit=12
# Only popular causes
curl http://localhost:8001/api/trending?source=everyorg&limit=12
# Only IRS categories
curl http://localhost:8001/api/trending?source=ntee&level=1
# View stats
curl http://localhost:8001/api/trending/stats
```
**Response:**
```json
{
"causes": [
{
"name": "Climate",
"icon": "",
"category": "primary",
"description": "Climate change mitigation...",
"image_url": "/images/causes/everyorg_climate_square.png",
"popularity_rank": 4
}
],
"total": 12
}
```
---
## Files Created
### API
- Yes `api/routes/trending.py` - Trending causes endpoint
- Yes `api/main.py` - Router registered
### Frontend
- Yes `frontend/src/pages/Home.tsx` - Database-driven causes
### Scripts
- Yes `scripts/media/generate_all_cause_images.py` - Batch generator for all causes
- Yes `scripts/media/generate_topic_images.py` - Base image generator
### Documentation
- Yes `DATABASE_DRIVEN_HOMEPAGE.md` - Full documentation
- Yes `QUICKSTART_HOMEPAGE.md` - Quick reference
---
## How It Works
```
Parquet Files (data/gold/)
ββ causes_everyorg_causes.parquet (39 rows)
ββ causes_ntee_codes (196 rows)
β
API (/api/trending)
ββ Reads parquet files
ββ Returns causes with metadata
ββ Includes image URLs
β
Frontend (Home.tsx)
ββ useQuery('trending-causes')
ββ Fetches from API on load
ββ Renders dynamically
```
---
## Advanced Options
### Generate Only Specific Causes
```bash
# Only EveryOrg (39 causes)
python scripts/media/generate_all_cause_images.py --type everyorg
# Only NTEE (196 causes)
python scripts/media/generate_all_cause_images.py --type ntee
# Skip existing images
python scripts/media/generate_all_cause_images.py --skip-existing
```
### Change Homepage Source
Edit `frontend/src/pages/Home.tsx`:
```typescript
// Line ~109 - Change source
const { data: trendingData } = useQuery({
queryFn: async () => {
const response = await api.get('/trending', {
params: {
source: 'everyorg', // 'everyorg', 'ntee', or 'mixed'
limit: 12
}
})
return response.data
}
})
```
### Add Custom Causes
```python
import polars as pl
# Load existing
df = pl.read_parquet('data/gold/causes_everyorg_causes.parquet')
# Add new cause
new = pl.DataFrame({
'cause_id': ['oral-health'],
'cause_name': ['Oral Health'],
'description': ['Dental care access'],
'category': ['primary'],
'icon': [''],
'popularity_rank': [40]
})
# Combine and save
pl.concat([df, new]).write_parquet('data/gold/causes_everyorg_causes.parquet')
# Generate image
python scripts/media/generate_all_cause_images.py --type everyorg
```
---
## Yes Build Status
**Verified:**
- Yes TypeScript compiles with no errors
- Yes Frontend builds successfully (5.21s)
- Yes Bundle size: 1.39 MB (gzipped: 380 KB)
- Yes All imports resolved
- Yes API endpoints registered
---
## Deploy
```bash
# Deploy to HuggingFace Spaces
./packages/hosting/scripts/huggingface/safe-deploy.sh
# Make sure images are included!
# Copy them to frontend/public/images/causes/ first
```
---
## Full Documentation
- **Complete Guide**: `DATABASE_DRIVEN_HOMEPAGE.md`
- **API Docs**: Visit `/docs` when API is running
- **Image Generator**: `scripts/media/README.md`
---
## Summary
**You now have:**
Yes 235 causes in database (39 EveryOrg + 196 NTEE)
Yes API endpoint serving causes dynamically
Yes Frontend fetching from database
Yes Image generator for all causes
Yes No more hardcoded data!
**Your homepage is database-driven!**
Just add your Gemini API key and run the image generator!
|