CoolFace
Apppublic

maheshsmc/D17-image-caption-decoder

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

Day 17 – Image Caption Generator (ViT + GPT2)

Track 2 (Coding) starter project. Minimal, production‑leaning skeleton with a clean Streamlit UI.

🚀 Quickstart

bash
# 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.py

By 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)

bash
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:
bash
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.txt with the same deps; include torch and transformers if 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)