Skip to content

How to use inpaint upload through the API? #13596

Answered by missionfloyd
thefora asked this question in Q&A
Discussion options

You must be logged in to vote

Send the mask in the mask parameter. It's a base64-encoded white on black image.

import requests
import base64

with open("input.png", "rb") as f, open("mask.png", "rb") as m:
    img = base64.b64encode(f.read()).decode('utf-8')
    mask = base64.b64encode(m.read()).decode('utf-8')

payload = {
    "prompt": "hot air balloon",
    "init_images": [img],
    "mask": mask,
}

response = requests.post(url='http://127.0.0.1:7860/sdapi/v1/img2img', json=payload)
r = response.json()

with open('output.png', 'wb') as f:
    f.write(base64.b64decode(r['images'][0]))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thefora
Comment options

Answer selected by thefora
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants