maheshsmc/D17-image-caption-decoder
0
Day 17 – Image Caption Generator (ViT + GPT2)
Track 2 (Coding) starter project. Minimal, production‑leaning skeleton with a clean Streamlit UI.
🚀 Quickstart
# 1) Create env (optional)
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
# 2) Install minimal deps
pip install -r requirements.txt
# 3) Run UI
streamlit run app.pyBy default, the app uses a placeholder captioner (works without heavy deps). Toggle “Use real model” in the sidebar to run the actual ViT+GPT2 model (requires torch and transformers).
Real Model (optional)
pip install torch transformers
# Then in the UI, enable "Use real model"🧭 Flow (Input → Output)
Image → preprocess (resize) → [ViT encoder] → embedding → [GPT2 decoder] → caption → sanitize → UI🗂️ Project Layout
Day17_ImageCaption/
├─ app.py
├─ utils.py
├─ build_index.py
├─ requirements.txt
├─ README.md
├─ logs/
│ └─ (inference_log.jsonl will appear after first run)
└─ docs/
└─ flow.txt📒 Logging & Evaluation
- Inference runs are appended to
logs/inference_log.jsonl. - Convert to CSV for quick analysis:
python build_index.py🧰 Hugging Face Spaces (Streamlit)
- Space SDK: Streamlit
- Runs on: CPU is fine (real model is slower). For better speed, choose GPU.
- Add a
requirements.txtwith the same deps; includetorchandtransformersif using real model. - Push this folder to a repo and connect to a Space.
🔒 Notes
- This starter includes a light safety/sanitization step in
sanitize_caption. - For production, consider better filtering and evaluation harnesses.
Generated on 2025-09-09 06:35:49 (local build)
