Step-by-step guide from raw data to live hackathon demo.
⏱️ Runtime Strategy: ~6-12 hours across distributed local instances (Run Async) ⚙️ Hardware Requirement: standard CPU, high bandwidth connection, 500GB+ NVMe SSD recommended.
cd e:\campus-ai
python scripts/pinterest_scraper.py- Downloads 1900 images per theme across 55 categories
- Saves to
data/raw/with hierarchical folders (tech_fest/hackathon/, etc.) - Global Deduplication: Uses a custom
GlobalImageDeduplicatoremploying Perceptual Hashing (PHash) and a high-performance SQLite caching layer (data/phash_cache.db). Scans ~130,000+ existing images instantly to ensure zero duplicates across the entire corpus. - Skips already-downloaded images safely — safe to restart
⏱️ ~1-2 hours (Targeted run)
cd e:\campus-ai
python scripts/pinterest_tuning_scraper.py- Strict Enforcement Engine: Uses a heavily modified Selenium scraper that recursively scrolls and cycles through search queries until it achieves strictly 100 unique images per 55 specific subcategories.
- Data Isolation: Saves uniquely to
data/tuning/<category>/<subcategory>/. - Absolute Uniqueness: Pipes newly scraped images through the identical
GlobalImageDeduplicatorcache, guaranteeing these 5,500 tuning images have absolutely zero overlap with the 100k+ images in the maindata/raw,data/train, ordata/valdatasets.
⚙️ Algorithm: Offloads Canny Edge / Laplacian Variance calculations to CUDA to rapidly sweep 130k+ images for optimal sharpness and color contrast.
python scripts/quality_filter.pyRemoves blurry, low-res, duplicate images → saves to data/processed/
⚙️ Model Architecture: Microsoft Florence-2-large via HuggingFace transformers.
⚙️ Hardware Target: RTX 4070 Ti / 5070 Ti (Float16 precision, ~12GB VRAM allocation).
python scripts/caption_generator.py- Transforms pixel data into rich spatial text (e.g., "Bold sans-serif typography on the top left, neon cyber-punk background, dates on bottom right"). Saves
.txtpairs todata/final/. These pairs are critical for SDXL cross-attention during LoRA tuning.
⚙️ Logic: Deterministic pseudo-random seed to guarantee identical splits across team machines.
python scripts/split_dataset.pySplits into 1000 train / 200 val / 100 test per theme → data/train/, data/val/, data/test/
Core Training Engine: ai-toolkit featuring LoRA+ optimization. Employs a tri-phase curriculum to circumvent catastrophic forgetting while molding the SDXL 1.0 architecture.
- Objective: Teaches the model the macro-composition, layout, and lighting of the 55 event categories.
- Data Source: Exclusively uses
data/train/(to preserve validation sets for Phase 2).
# 1. Generate optimal JSON layout training config
python scripts/create_training_config.py
# 2. Train Layout Pass (Learning Rate: 1e-4)
python ai-toolkit/run.py configs/train_sdxl_lora.yamlOutput: models/sdxl/checkpoints/campus_ai_poster_sdxl/campus_ai_poster_sdxl.safetensors
- Objective: Bakes in micro-details, sharp Indian cultural textures (e.g., diwali lamps, specific fonts), and perfect aesthetic adherence.
- Mechanics: Resumes gracefully from the Phase 1
.safetensorsweights. Drops learning rate sequentially (2e-5) while utilizing the full 100% data blend (train,val,test).
# Train Perfection Pass (Internal Checkpoint Resume)
python ai-toolkit/run.py configs/train_sdxl_lora_phase2.yamlOutput: Overwrites the .safetensors with the high-fidelity weights.
- Objective: Final polish for 8 unique typography layout styles and precise color-matching, training the model to leave clean negative space for compositor overlay.
- Mechanics: Drops learning rate to (5e-6). Uses a small, highly curated dataset of typography-heavy posters.
# Train Style Pass
python ai-toolkit/run.py configs/train_sdxl_lora_phase3.yamlOutput: Final campus_ai_poster_sdxl_phase3.safetensors ready for deployment.
Objective. To teach the model to blend styles across categories (e.g. tech fest layouts with cultural lighting).
python scripts/create_mixed_genre_dataset.py --source data/train --output data/tuning-2 --target-per-cat 3000Produces ~165,000 blended caption samples for experimental Phase 4 training.
# Train Phase 4 Mixed-Genre
python ai-toolkit/run.py configs/train_sdxl_lora_phase4.yamlOutput: Final campus_ai_poster_sdxl_phase4.safetensors ready for deployment.
Before deploying to the cloud, spin up the 6-tab Gradio UI locally using your RTX 5070 Ti.
python deployment/app.pyOpen http://localhost:7860 to verify all 6 tabs (Text→Poster, Reference Image, Image Transform, Inpaint/Edit, HD Upscale, Edit Poster) and LoRA integration are working correctly.
In the future, when ready to push to production:
pip install huggingface-hub[cli]
huggingface-cli login
# Paste your token from https://huggingface.co/settings/tokenshuggingface-cli upload YOUR_USERNAME/campus-ai-poster-sdxl models/sdxl/checkpoints/campus_ai_poster_sdxl/ .cd deployment
git init
huggingface-cli repo create campus-ai-poster-generator --type space --space-sdk gradio
git remote add space https://huggingface.co/spaces/YOUR_USERNAME/campus-ai-poster-generator
git add app.py pipelines.py prompt_engine.py poster_compositor.py requirements.txt README.md
git commit -m "Deploy Campus-AI by CounciL"
git push space mainGo to Space Settings → Variables and Secrets and add:
| Secret Name | Value |
|---|---|
HF_USERNAME |
your HF username |
GROQ_API_KEY |
your Groq API key |
Open https://huggingface.co/spaces/YOUR_USERNAME/campus-ai-poster-generator and test all 6 tabs.
| Feature | Free | Pro ($9/mo) |
|---|---|---|
| ZeroGPU (shared A100) | ✅ Low priority | ✅ High priority |
| Private Spaces | ❌ | ✅ |
| Persistent Storage | ❌ | ✅ |
| Cold start | Slower | Faster |
Verdict: Free tier works for a hackathon demo. Upgrade to Pro only if the queue is too slow during judging.
pinterest_scraper.py → data/raw/ (1900 images/theme)
pinterest_tuning_scraper.py → data/tuning/ (Strictly 100 entirely unique images/theme)
image_deduplicator.py → data/phash_cache.db (O(1) lookups via SQLite PHash)
quality_filter.py → data/processed/ (~1300 quality-passed/theme)
caption_generator.py → data/final/ (image + caption pairs)
split_dataset.py → data/train/val/test/ (1000/200/100)
create_training_config.py → configs/train_sdxl_lora.yaml
ai-toolkit/run.py → configs/train_sdxl_lora.yaml (Phase 1 Layout)
ai-toolkit/run.py → configs/train_sdxl_lora_phase2.yaml (Phase 2 Detail)
test_checkpoint.py → poster_compositor.py (SDXL Art + PIL Typography)
deployment/app.py → Local 6-Tab Gradio Server (Primary Test)
deployment/prompt_engine.py → v3.0 (20 styles, 30 events, 7 lighting, 10 color harmonies)
deployment/poster_compositor.py → PIL Typography (auto zone detection, 3 layouts)
huggingface-cli upload → HF Space (Future Production)
Campus-AI by CounciL — Built for the Indian campus community