Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
137ce534
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1749
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
137ce534
编写于
1月 08, 2023
作者:
A
AUTOMATIC
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove some code duplication
remove calls to locals() add a test for img2img with script
上级
e7f2f1e1
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
22 addition
and
17 deletion
+22
-17
modules/api/api.py
modules/api/api.py
+16
-17
test/basic_features/img2img_test.py
test/basic_features/img2img_test.py
+6
-0
未找到文件。
modules/api/api.py
浏览文件 @
137ce534
...
...
@@ -148,14 +148,20 @@ class Api:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Incorrect username or password"
,
headers
=
{
"WWW-Authenticate"
:
"Basic"
})
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
if
txt2imgreq
.
script_name
is
not
None
:
if
scripts
.
scripts_txt2img
.
scripts
==
[]:
scripts
.
scripts_txt2img
.
initialize_scripts
(
False
)
def
get_script
(
self
,
script_name
,
script_runner
):
if
script_name
is
None
:
return
None
,
None
if
not
script_runner
.
scripts
:
script_runner
.
initialize_scripts
(
False
)
ui
.
create_ui
()
script_idx
=
script_name_to_index
(
txt2imgreq
.
script_name
,
scripts
.
scripts_txt2img
.
selectable_scripts
)
script
=
scripts
.
scripts_txt2img
.
selectable_scripts
[
script_idx
]
script_idx
=
script_name_to_index
(
script_name
,
script_runner
.
selectable_scripts
)
script
=
script_runner
.
selectable_scripts
[
script_idx
]
return
script
,
script_idx
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
script
,
script_idx
=
self
.
get_script
(
txt2imgreq
.
script_name
,
scripts
.
scripts_txt2img
)
populate
=
txt2imgreq
.
copy
(
update
=
{
# Override __init__ params
"sampler_name"
:
validate_sampler_name
(
txt2imgreq
.
sampler_name
or
txt2imgreq
.
sampler_index
),
...
...
@@ -173,7 +179,7 @@ class Api:
p
=
StableDiffusionProcessingTxt2Img
(
sd_model
=
shared
.
sd_model
,
**
args
)
shared
.
state
.
begin
()
if
'script'
in
locals
()
:
if
script
is
not
None
:
p
.
outpath_grids
=
opts
.
outdir_txt2img_grids
p
.
outpath_samples
=
opts
.
outdir_txt2img_samples
p
.
script_args
=
[
script_idx
+
1
]
+
[
None
]
*
(
script
.
args_from
-
1
)
+
p
.
script_args
...
...
@@ -182,7 +188,6 @@ class Api:
processed
=
process_images
(
p
)
shared
.
state
.
end
()
b64images
=
list
(
map
(
encode_pil_to_base64
,
processed
.
images
))
return
TextToImageResponse
(
images
=
b64images
,
parameters
=
vars
(
txt2imgreq
),
info
=
processed
.
js
())
...
...
@@ -192,13 +197,7 @@ class Api:
if
init_images
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"Init image not found"
)
if
img2imgreq
.
script_name
is
not
None
:
if
scripts
.
scripts_img2img
.
scripts
==
[]:
scripts
.
scripts_img2img
.
initialize_scripts
(
True
)
ui
.
create_ui
()
script_idx
=
script_name_to_index
(
img2imgreq
.
script_name
,
scripts
.
scripts_img2img
.
selectable_scripts
)
script
=
scripts
.
scripts_img2img
.
selectable_scripts
[
script_idx
]
script
,
script_idx
=
self
.
get_script
(
img2imgreq
.
script_name
,
scripts
.
scripts_img2img
)
mask
=
img2imgreq
.
mask
if
mask
:
...
...
@@ -223,7 +222,7 @@ class Api:
p
.
init_images
=
[
decode_base64_to_image
(
x
)
for
x
in
init_images
]
shared
.
state
.
begin
()
if
'script'
in
locals
()
:
if
script
is
not
None
:
p
.
outpath_grids
=
opts
.
outdir_img2img_grids
p
.
outpath_samples
=
opts
.
outdir_img2img_samples
p
.
script_args
=
[
script_idx
+
1
]
+
[
None
]
*
(
script
.
args_from
-
1
)
+
p
.
script_args
...
...
test/basic_features/img2img_test.py
浏览文件 @
137ce534
...
...
@@ -50,6 +50,12 @@ class TestImg2ImgWorking(unittest.TestCase):
self
.
simple_img2img
[
"mask"
]
=
encode_pil_to_base64
(
Image
.
open
(
r
"test/test_files/mask_basic.png"
))
self
.
assertEqual
(
requests
.
post
(
self
.
url_img2img
,
json
=
self
.
simple_img2img
).
status_code
,
200
)
def
test_img2img_sd_upscale_performed
(
self
):
self
.
simple_img2img
[
"script_name"
]
=
"sd upscale"
self
.
simple_img2img
[
"script_args"
]
=
[
""
,
8
,
"Lanczos"
,
2.0
]
self
.
assertEqual
(
requests
.
post
(
self
.
url_img2img
,
json
=
self
.
simple_img2img
).
status_code
,
200
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录