Luna is my white German Shepherd dog and she'll be helping us experiment with generative AI in this runme.dev notebook.
cat hi_luna.png
In this case, we chose to leverage OpenAI's Dall-E image editing capabilities. Let's jump in.
# homebrew on macOS or apt on Ubuntu
which brew && brew install jq curl; true
which apt && apt install && sudo apt install -y jq curl 2>/dev/null; true
That's really all you need. Please enter when prompted.
export OPENAI_API_KEY=Your OpenAI key here
Describe the whole scene, not just the parts you'd like to be edited.
export SCENE="a happy german shepherd dog surrounded by cheeseburgers"
export DALLE="$(curl https://api.openai.com/v1/images/edits \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F image="@luna.png" \
-F mask="@luna_mask.png" \
-F prompt="$SCENE" \
-F n=1 \
-F size="512x512" \
-s)"
echo $DALLE | jq -c .
Give it a sec... OpenAI takes about ~20-40s to produce results.
curl -s "$(echo $DALLE | jq -r '.data[0].url')"
You basically give Dall-E two images:
- The original image plus
- A version of the same photo with roughly whatever you want to be replaced with generative imagery
Details are available in OpenAI's docs on image edits.
What's more important is that the dimension match a square.
A version that acts like a mask (background 100% transparent) to let the AI know to not preserve the background.
One could use another AI to remove the background. In my case, I just used Apple's Preview which comes with smart lasso selection.