Klace / stable-diffusion-webui-instruct-pix2pix

Extension for webui to run instruct-pix2pix
Other
320 stars 20 forks source link

add instruct-pix2pix/img2img api endpoint #57

Closed mix1009 closed 1 year ago

mix1009 commented 1 year ago

Created /instruct-pix2pix/img2img API endpoint :)

스크린샷 2023-02-01 오후 11 37 39

Demo API usage using webuiapi (pip install webuiapi)

import webuiapi
api = webuiapi.WebUIApi()
import io
import base64
from PIL import Image

def b64_img(image: Image):
    buffered = io.BytesIO()
    image.save(buffered, format="PNG")
    img_base64 = 'data:image/png;base64,' + str(base64.b64encode(buffered.getvalue()), 'utf-8')
    return img_base64
api.util_set_model('model.ckpt')
r = api.txt2img(prompt='a cute puppy in the park')
img = r.image
img

aaa

api.util_set_model('instruct-pix2pix')
payload = {}
payload['init_images'] = [b64_img(img)]
payload['prompt'] = 'sunset'
payload['text_cfg'] = 7.5
payload['img_cfg'] = 1.5
payload['sampler'] = 'Euler a'
r = api.custom_post('instruct-pix2pix/img2img', payload=payload, baseurl=False)
r.image

aab