An AI agent that turns your Spotify listening history into a Spotify-Wrapped-style narrative slideshow — with the eras of your year, the emotional memories attached to each one, the songs that defined them, five recommendations Claude thinks belong in each era, and a cinematic image for every chapter.
Powered by GMI Cloud:
- Claude Opus 4.7 for era detection + copywriting
- Gemini 3 Pro (image preview) for the cinematic per-era artwork
Two ways to run it:
- Web UI — drag-and-drop your Spotify export, watch the pipeline run, view the slideshow
- CLI — same pipeline, scriptable
A carousel slideshow. Intro slide → one full-viewport slide per era → outro stats. Each era slide has:
┌───────────────────────────────────────────────────────┐
│ 02 / 05 JAN – FEB 2023 [palette] │
│ │
│ ┌─────────────┐ ■ DEFINING TRACKS / what played │
│ │ [polaroid │ 01 Funny You Should Ask ... │
│ │ image, │ 02 Anti-Curse ... │
│ │ rotated] │ ... │
│ └─────────────┘ │
│ ■ WORTH ADDING / 5 from Claude │
│ January 2023: 01 Linger ... │
│ Quiet rooms, 02 If Books Could Kill ... │
│ loud headphones ... │
│ │
│ [vibe] │
│ [emotional memory paragraph] │
│ │
│ [←] [→] │
└───────────────────────────────────────────────────────┘
Navigation: arrow keys, scroll, side dots, or the on-screen ← / → buttons.
# 1. Install deps
pip install -r requirements.txt
# 2. (Optional but recommended) Set your GMI key once
export GMI_API_KEY=your_key
# 3. Launch the web app
python web.py
# → opens http://localhost:5000Drop your Spotify export .zip (or a single .json) on the upload zone, click Generate, and watch the pipeline run. When it's done click View your year.
If you don't have your data yet, click Try demo — it skips all API calls and renders the bundled example eras so you can see the slideshow design.
# Run on your Spotify history (a JSON file or a directory of them):
python agent.py /path/to/spotify/export --out output/wrapped.html
# Or use the bundled synthetic 14-month history to test the full pipeline:
python agent.py samples/sample_history.json --out output/wrapped.html
# Or just see the rendered design without burning credits:
python agent.py --demo --out output/wrapped.htmlEach real run is well under a dollar — one Claude Opus 4.7 call (~$0.10–0.20 depending on how much history) plus one Gemini 3 Pro image per era (4–7 images at ~$0.04 each).
Spotify offers two exports — the agent handles both:
- Account data (5-day wait, last ~12 months) —
StreamingHistory_music_*.json - Extended streaming history (30-day wait, your entire account) —
Streaming_History_Audio_*.json, much more detail
Request either at spotify.com/account/privacy. Drop the .zip they email you straight into the web UI, or unzip it and pass the folder to the CLI.
A synthetic 14-month history is bundled at samples/sample_history.json for testing.
Spotify history JSON
│
▼
┌───────────────────┐
│ spotify_parser │ normalize both export formats,
│ bucket_by_month │ aggregate top artists/tracks per month,
└───────────────────┘ compute late-night + weekend ratios
│
▼
┌───────────────────┐
│ era_detector │ Claude Opus 4.7 reads the monthly stats and
│ detect_eras() │ returns JSON with 4–7 eras: title, vibe,
└───────────────────┘ emotional memory, top 5 defining songs,
top 5 recommended songs, color palette,
image prompt
│
▼
┌───────────────────┐
│ GMI image API │ for each era, submit prompt to Gemini 3 Pro,
│ (async queue) │ poll until success, download the image
└───────────────────┘
│
▼
┌───────────────────┐
│ renderer │ builds the self-contained HTML slideshow
│ │ with one slide per era + intro + outro
└───────────────────┘
The era detection prompt is in era_detector.py — that's the file to edit if you want a different voice, more eras, shorter copy, or different recommendation rules.
| Thing you want to change | Where |
|---|---|
| LLM model (e.g. swap for cheaper Sonnet) | GMI_LLM_MODEL env var, defaults to anthropic/claude-opus-4.7 |
Image model (e.g. gemini-2.5-flash-image for speed) |
GMI_IMAGE_MODEL env var |
| The agent's voice / number of eras / recommendation rules | SYSTEM_PROMPT in era_detector.py |
| Slide design (fonts, animation, layout) | _CSS and _JS in renderer.py |
| Upload-page design | templates/index.html |
| Aspect ratio + resolution of generated images | client.generate_image() call in agent.py |
music_memory_agent/
├── agent.py CLI orchestrator + progress-callback API
├── web.py Flask app (upload, SSE progress, viewer)
├── gmi_client.py GMI LLM + async image-queue client
├── spotify_parser.py loads + buckets play history
├── era_detector.py LLM prompt + JSON parsing
├── renderer.py HTML slideshow generator
├── templates/index.html web UI (gmicloud.ai-styled landing page)
├── requirements.txt
├── samples/
│ ├── sample_history.json synthetic 14-month listening history
│ └── demo_eras.json pre-baked LLM output for demo mode
└── output/ CLI runs land here (web UI uses /tmp)
- Give it more history. With less than 6 months the era detector can't find shifts. A full year is the sweet spot.
- Re-roll just the images by changing
image_promptin the savedoutput/wrapped.jsonand rerunning with that JSON loaded — no need to redo era detection. - Use
--keep-remote-urlsif you want the HTML to reference GMI's image URLs directly instead of downloading them locally (handy for sharing a single file without animages/folder).
The app is already AgentBox-compatible. The Dockerfile, the polling job pattern (POST /generate → GET /jobs/{id}), 0.0.0.0:8080 binding, /health endpoint, and GMI_MAAS_* env-var reading are all in place.
# Build (use --platform if registering from arm64 — AgentBox expects amd64)
docker build --platform linux/amd64 -t your-username/music-memory-agent:latest .
# Push to your registry (Docker Hub, GHCR, etc.)
docker push your-username/music-memory-agent:latest-
Open console.gmicloud.ai → AgentBox → Register & List.
-
Step 1 — Basic Info: Name, description, category. Pick GMI CE Deployment (recommended) to have GMI host your container.
-
Step 2 — Infrastructure:
- Image source: Registry URL →
docker.io/your-username/music-memory-agent:latest(orghcr.io/...) - Enable Credentials: OFF (assuming public image; ON if private, then supply a registry token)
- Compute: Container, 2 vCPU / 4 GB
- Region: IOWA IDC-1 (or closest to your users)
- Port mapping:
443 → 8080(default — this is what the container exposes) - MaaS integration: ON, then select the LLM you want the agent to use (e.g., Claude Sonnet 4.6). MaaS injects
GMI_MAAS_API_KEYandGMI_MAAS_BASE_URLautomatically, plus aGMI_MODELSUUID reference.
- Image source: Registry URL →
-
Step 3 — Env Variables: AgentBox auto-injects the MaaS variables, but
GMI_MODELSis a UUID — not a model name the LLM API can call. Add these custom variables:Variable Type Value Notes GMI_LLM_MODELPlain anthropic/claude-sonnet-4.6The readable name the LLM endpoint expects. Match the model you picked in Step 2. GMI_IMAGE_MODELPlain gemini-3-pro-image-previewOptional — default is already this. Override to use a different image model. GMI_API_KEYSecret (your GMI key) Optional — only needed for the image queue API ( console.gmicloud.ai), which lives outside MaaS. If you set this, the agent uses it for image gen and falls back toGMI_MAAS_API_KEYotherwise.GMI auto-injects (don't add these manually):
GMI_MAAS_API_KEY— the LLM/MaaS auth tokenGMI_MAAS_BASE_URL— typicallyhttps://api.gmi-serving.comGMI_MODELS— UUID reference to your Step 2 selection (the agent ignores this in favor ofGMI_LLM_MODEL)
-
Step 4 — Review & Register: Confirm, click Register. AgentBox pulls your image and exposes a public URL on port 443.
# Replace with the URL the wizard hands you
BASE=https://your-agent-id.gmicloud.ai
# Liveness
curl $BASE/health
# → {"status":"ok"}
# Start a demo run (no upload, no key needed)
JOB=$(curl -s -X POST $BASE/generate -F demo=1 | jq -r .job_id)
echo "job: $JOB"
# Poll
curl -s $BASE/jobs/$JOB | jq
# Result lives at $BASE/wrapped/$JOB/ once status is "done"
open $BASE/wrapped/$JOB/- In-memory job state: the container stores job progress in a
dict. If a container restarts, in-flight jobs are lost. For production multi-user reliability, swap theJOBSdict inweb.pyfor Redis (inject the Redis URL as a Step 3 secret). - Single worker by design: the
gunicorninvocation runs--workers 1. Multiple workers would each have their ownJOBSdict, breaking cross-worker lookups. Thegthreadworker class handles concurrent requests via threads instead. - Image generation API key: GMI's MaaS layer covers the LLM endpoint (
api.gmi-serving.com). The image queue lives atconsole.gmicloud.ai/api/v1/ie/requestqueue/apikey/and uses the same API key — the injectedGMI_MAAS_API_KEYshould authenticate against both. If you ever need a separate key for image gen, setGMI_IMAGE_API_KEYas a secret in Step 3 and read it ingmi_client.py. - Long-running requests: the agent already follows the async job pattern. The HTTP gateway never holds a connection longer than the initial
POST /generate(which returns within milliseconds).
docker build -t music-memory-agent:dev .
docker run --rm -p 8080:8080 \
-e GMI_MAAS_BASE_URL=https://api.gmi-serving.com \
-e GMI_MAAS_API_KEY=$GMI_API_KEY \
-e GMI_LLM_MODEL=anthropic/claude-sonnet-4.6 \
music-memory-agent:dev
# → open http://localhost:8080Don't try to mimic the UUID-style GMI_MODELS injection locally — the agent already prefers GMI_LLM_MODEL when set, which is exactly what the AgentBox guide tells you to add in Step 3.