Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
β 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!
β Completed
- API Endpoint -
/api/trendingserves causes from parquet files - Frontend Integration - Homepage fetches from database (not hardcoded!)
- Image Generator - Script to create images for ALL 235 causes
- Build Verified - TypeScript compiles β , Build succeeds β
π Quick Start (3 Steps)
1. Generate Images for Your Causes
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
mkdir -p frontend/public/images/causes
cp data/media/causes/*.png frontend/public/images/causes/
3. Test Live
./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:
Banner (1200x600px)
everyorg_climate_banner.pngntee_E_banner.png- Use: Hero images, featured stories
Square (400x400px)
everyorg_climate_square.pngntee_E_square.png- Use: Topic cards, trending bar
AI Color Scheme
- Gemini generates thematic colors
- Saved in
metadata.json
π API Endpoints
GET /api/trending
Get trending causes:
# 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:
{
"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
- β
api/routes/trending.py- Trending causes endpoint - β
api/main.py- Router registered
Frontend
- β
frontend/src/pages/Home.tsx- Database-driven causes
Scripts
- β
scripts/media/generate_all_cause_images.py- Batch generator for all causes - β
scripts/media/generate_topic_images.py- Base image generator
Documentation
- β
DATABASE_DRIVEN_HOMEPAGE.md- Full documentation - β
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
# 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:
// 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
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
β Build Status
Verified:
- β TypeScript compiles with no errors
- β Frontend builds successfully (5.21s)
- β Bundle size: 1.39 MB (gzipped: 380 KB)
- β All imports resolved
- β API endpoints registered
π Deploy
# 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
/docswhen API is running - Image Generator:
scripts/media/README.md
π Summary
You now have:
β
235 causes in database (39 EveryOrg + 196 NTEE)
β
API endpoint serving causes dynamically
β
Frontend fetching from database
β
Image generator for all causes
β
No more hardcoded data!
Your homepage is database-driven! π
Just add your Gemini API key and run the image generator!