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

add sd-webui api doc and script #559

Merged
merged 9 commits into from
Jan 23, 2024
Merged

add sd-webui api doc and script #559

merged 9 commits into from
Jan 23, 2024

Conversation

marigoold
Copy link
Contributor

@marigoold marigoold commented Jan 23, 2024

api 代码参考了 sd-webui 的 wiki:https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API ,改动是在 request 的 data 中增加了对应的字段。

由于现在 OneDiff 还不支持 img2img,所以注释掉了脚本中对应的部分。

Comment on lines 70 to 73
# Enable OneDiff speed up
"script_name": "onediff_diffusion_model",
# If you are using OneDiff Enterprise, add the field below to enable quant feature
# "script_args" : [{"0": True}],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加这里的字段就可以使用 OneDiff 的加速功能,下面的 script_args : [{"0": True}] 是开启量化功能

}
call_txt2img_api(**payload)

# OneDiff sd-webui doesn't support img2img now, the feature is under urgent development
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OneDiff sd-webui 似乎不支持 img2img,所以这里先注释掉了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接删除吧。 img2img 之后另外准备一个新的脚本

@@ -0,0 +1,170 @@
from datetime import datetime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新建个 api 目录吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新建个 api 目录吧

新建了一个 api_examples 目录

@@ -0,0 +1,170 @@
from datetime import datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个作为 example,单独放到一个 examples 目录吧。现在是 txt2img 的例子,未来还有 img2img, controlnet 的例子

@@ -0,0 +1,170 @@
from datetime import datetime
import urllib.request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里注释加一下原始来源吧,方便以后维护这个脚本的人定位更新。

而且可以注释里,把因为适配 onediff 改动的地方强调下。让后面维护的人,以及用户,都知道改动不用特别多、怎么改。

@@ -98,6 +98,28 @@ If you possess a OneDiff Enterprise license key, you can access instructions on

Note: The quantified model doesn't currently support LoRA loading, and related features are under emergency development.

## API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## API
## Invoke OneDiff by API

”用 api 方式调用onediff",具体英文是否正确你再确认下吧。

Comment on lines 103 to 105
To use the OneDiff-based sd-webui API, you only need to add a `"script": "onediff_diffusion_model"` field to the request to speed up model inference.

For OneDiff Enterprise, add `"script_args" : [{"0": True}]` to use the quantization feature.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得这些东西放 py 脚本里,作为注释就可以了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是这么想的,对于经常用 api 调用 sd-webui 的用户,看到文档里这么写就能明白怎么用了,省去了一步扒代码的过程

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那也可以保留。不过我建议换一下顺序:先介绍如何跑起来。然后再解释在干什么。
因为大部分看这个文档的,是想要 “howto”,就是照着就能复现,复现成功了,再看能干嘛


For OneDiff Enterprise, add `"script_args" : [{"0": True}]` to use the quantization feature.

Check file `extensions/onediff_sd_webui_extensions/api.py` for more details.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Check file `extensions/onediff_sd_webui_extensions/api.py` for more details.
Check file [api.py](./api.py) for more details.

改成超链接(这个路径只是当前的例子。需要合并前根据实际情况更新)


Then you can get the images returned by sd-webui client at `api_out/txt2img/`.

Note: OneDiff sd-webui only supports txt2img now, img2img and ControlNet is under urgent development.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句可以删除?

# If you are using OneDiff Enterprise, add the field below to enable quant feature
# "script_args" : [{"0": True}],

# example args for x/y/z plot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些是原来脚本就有的注释吧。

不知道有特殊意义没有,为了干净可以删掉?

}
call_txt2img_api(**payload)

# OneDiff sd-webui doesn't support img2img now, the feature is under urgent development
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接删除吧。 img2img 之后另外准备一个新的脚本

@marigoold marigoold merged commit d4d1ea0 into main Jan 23, 2024
5 checks passed
@marigoold marigoold deleted the dev_wy_sdwebui_api branch January 23, 2024 06:31
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

Successfully merging this pull request may close these issues.

3 participants