#!/usr/bin/env bash
# make_image.sh — ask NVIDIA's FLUX.1-schnell image model to paint a picture
# from your Mac (or any) Terminal.
#
# Setup (one time):
#   1. Get a FREE key at https://build.nvidia.com (top-right "Get API Key")
#   2. Save it as the NVIDIA_API_KEY environment variable so every script finds it:
#        export NVIDIA_API_KEY="nvapi-your_real_key_here"
#      Add the line above to ~/.zshrc so every new Terminal has it.
#
# Run it:
#   bash make_image.sh
#
# NVIDIA's image API returns JSON with the picture inside a base64 string, so we
# pipe through Python to decode it into a normal .jpg file.
#
# Companion lesson: https://krueng.ai/nvidia_api.html

curl https://ai.api.nvidia.com/v1/genai/black-forest-labs/flux.1-schnell \
  -X POST \
  -H "Authorization: Bearer $NVIDIA_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"a friendly robot painting a colorful picture","mode":"base","cfg_scale":0,"width":1024,"height":1024,"seed":0,"steps":4}' \
  | python -c "import sys,json,base64; open('robot.jpg','wb').write(base64.b64decode(json.load(sys.stdin)['artifacts'][0]['base64']))"

echo "Done! Open robot.jpg to see your picture. 🎨"
