Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Music Memory Agent

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

What it produces

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.


Quickstart (Web UI)

# 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:5000

Drop 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.


Quickstart (CLI)

# 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.html

Each 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).


Getting your Spotify data

Spotify offers two exports — the agent handles both:

  1. Account data (5-day wait, last ~12 months) — StreamingHistory_music_*.json
  2. 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.


How it works

   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.


Customizing

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

Files

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)

Tips for nicer output

  • 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_prompt in the saved output/wrapped.json and rerunning with that JSON loaded — no need to redo era detection.
  • Use --keep-remote-urls if you want the HTML to reference GMI's image URLs directly instead of downloading them locally (handy for sharing a single file without an images/ folder).

Deploy on GMI AgentBox

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 and push the image

# 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

Register via the AgentBox wizard

  1. Open console.gmicloud.ai → AgentBox → Register & List.

  2. Step 1 — Basic Info: Name, description, category. Pick GMI CE Deployment (recommended) to have GMI host your container.

  3. Step 2 — Infrastructure:

    • Image source: Registry URL → docker.io/your-username/music-memory-agent:latest (or ghcr.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_KEY and GMI_MAAS_BASE_URL automatically, plus a GMI_MODELS UUID reference.
  4. Step 3 — Env Variables: AgentBox auto-injects the MaaS variables, but GMI_MODELS is a UUID — not a model name the LLM API can call. Add these custom variables:

    Variable Type Value Notes
    GMI_LLM_MODEL Plain anthropic/claude-sonnet-4.6 The readable name the LLM endpoint expects. Match the model you picked in Step 2.
    GMI_IMAGE_MODEL Plain gemini-3-pro-image-preview Optional — default is already this. Override to use a different image model.
    GMI_API_KEY Secret (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 to GMI_MAAS_API_KEY otherwise.

    GMI auto-injects (don't add these manually):

    • GMI_MAAS_API_KEY — the LLM/MaaS auth token
    • GMI_MAAS_BASE_URL — typically https://api.gmi-serving.com
    • GMI_MODELS — UUID reference to your Step 2 selection (the agent ignores this in favor of GMI_LLM_MODEL)
  5. Step 4 — Review & Register: Confirm, click Register. AgentBox pulls your image and exposes a public URL on port 443.

Test the live endpoint

# 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/

Important notes for AgentBox

  • 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 the JOBS dict in web.py for Redis (inject the Redis URL as a Step 3 secret).
  • Single worker by design: the gunicorn invocation runs --workers 1. Multiple workers would each have their own JOBS dict, breaking cross-worker lookups. The gthread worker 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 at console.gmicloud.ai/api/v1/ie/requestqueue/apikey/ and uses the same API key — the injected GMI_MAAS_API_KEY should authenticate against both. If you ever need a separate key for image gen, set GMI_IMAGE_API_KEY as a secret in Step 3 and read it in gmi_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).

Local Docker test before pushing

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:8080

Don'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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages