Test Drive: StabilityAI search and replace
Published on .
Today I’m test driving Stability AI’s search and replace API for inpainting for a little Halloween fun that I’ll unveil at a Meetup next week. I have dealt with generating semantic masks locally and it is a chore, so its kind of amazing that they can do it for you so simply with the search_prompt
argument. So the process is:
- Get an API key
- Write your generation prompt and sample prompt.
- Implement
- Invoke
The output is great — filling in the lawn with what you describe in the prompt! The code I used is below
import requests
from PIL import Image
import io
from textwrap import dedent
response = requests.post(
f"https://api.stability.ai/v2beta/stable-image/edit/search-and-replace",
headers={
"authorization": f"Bearer {key}",
"accept": "image/*"
},
files={
"image": open("./whitehouse.jpg", "rb")
},
data={
"prompt": dedent("""\
House with a lawn decorated with fairies"""),
"search_prompt": "lawn",
"output_format": "webp",
},
)
display(Image.open(io.BytesIO(response.content)))