mix1009 / sdwebuiapi

Python API client for AUTOMATIC1111/stable-diffusion-webui
MIT License
1.35k stars 182 forks source link

About the progress of the API. #94

Closed zhangdanfeng888 closed 1 year ago

zhangdanfeng888 commented 1 year ago

When I want to get the progress of text2img, api.get_progress() can get it, but the result is always less than 1. And when the task is done, it turns into 0. How can I get 1 when the task is done? image

zhangdanfeng888 commented 1 year ago

Task done by coding.

`import asyncio import webuiapi import sys

async def main(): api = webuiapi.WebUIApi(host='127.0.0.1', port=7860) task = api.txt2img(prompt="cute kitten", use_async=True) tmp = 0 while not task.done(): progress = api.get_progress() print(progress) await asyncio.sleep(0.1) if progress['progress'] >= tmp: percentage = round(progress['progress'] / 1 100) else: percentage = 100 print("\r进度: {}%: ".format(percentage), "▓" (percentage // 2), end="") sys.stdout.flush() tmp = progress['progress'] if percentage == 100: break

asyncio.run(main()) `