Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: How do I use the API to call this function? thanks. #42

Closed
bieyongdapaodawenzi opened this issue Aug 2, 2023 · 2 comments
Closed

Comments

@bieyongdapaodawenzi
Copy link

bieyongdapaodawenzi commented Aug 2, 2023

Expected behavior

payload = {
"prompt": aPrompt,
"negative_prompt": aNprompt,
"width": 512,
"height": 768,
"steps": 25,
"sampler_index": "Euler a"
}

response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)


This is a request to call a txt2img, but I'm not sure how to call "AnimateDiff" here to generate an animation. thanks

@bluewayg
Copy link

bluewayg commented Aug 7, 2023

"alwayson_scripts":{"AnimateDiff": {"args": [true,0,24,6,"mm_sd_v15.ckpt"]}

@bieyongdapaodawenzi
Copy link
Author

bieyongdapaodawenzi commented Aug 7, 2023

"alwayson_scripts":{"AnimateDiff": {"args": [true,0,24,6,"mm_sd_v15.ckpt"]}

这确实可以触发动画图片生成。但通过txt2img调用,在api/api.py的text2imgapi函数中,processed.images得到的并不是Image.Image对象,而是gif图片的路径。所以系统崩溃了。
我在text2imgapi函数中打了一个patch,他可以正常工作了

def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
......
# at end add by paulhan
if isinstance(processed.images[0], str):
path = processed.images[0]
b64images = []
b64images.append(encode_path_to_base64(path))
else:
b64images = list(map(encode_pil_to_base64, processed.images)) if send_images else []
return models.TextToImageResponse(images=b64images, parameters=vars(txt2imgreq), info=processed.js())

def encode_path_to_base64(path):
f = open(path, 'rb')
b64images = base64.b64encode(f.read())
f.close()
return b64images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants