Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
22faf30c
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
11 个月 前同步成功
通知
1767
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
22faf30c
编写于
9月 10, 2022
作者:
A
AUTOMATIC
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add script for batch file processing
上级
6f678ec7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
0 deletion
+59
-0
scripts/batch.py
scripts/batch.py
+59
-0
未找到文件。
scripts/batch.py
0 → 100644
浏览文件 @
22faf30c
import
math
import
os
import
sys
import
traceback
import
modules.scripts
as
scripts
import
gradio
as
gr
from
modules.processing
import
Processed
,
process_images
from
PIL
import
Image
from
modules.shared
import
opts
,
cmd_opts
,
state
class
Script
(
scripts
.
Script
):
def
title
(
self
):
return
"Batch processing"
def
show
(
self
,
is_img2img
):
return
is_img2img
def
ui
(
self
,
is_img2img
):
input_dir
=
gr
.
Textbox
(
label
=
"Input directory"
,
lines
=
1
)
output_dir
=
gr
.
Textbox
(
label
=
"Output directory"
,
lines
=
1
)
return
[
input_dir
,
output_dir
]
def
run
(
self
,
p
,
input_dir
,
output_dir
):
images
=
[
file
for
file
in
[
os
.
path
.
join
(
input_dir
,
x
)
for
x
in
os
.
listdir
(
input_dir
)]
if
os
.
path
.
isfile
(
file
)]
batch_count
=
math
.
ceil
(
len
(
images
)
/
p
.
batch_size
)
print
(
f
"Will process
{
len
(
images
)
}
images in
{
batch_count
}
batches."
)
p
.
batch_count
=
1
p
.
do_not_save_grid
=
True
p
.
do_not_save_samples
=
True
state
.
job_count
=
batch_count
for
batch_no
in
range
(
batch_count
):
batch_images
=
[]
for
path
in
images
[
batch_no
*
p
.
batch_size
:(
batch_no
+
1
)
*
p
.
batch_size
]:
try
:
img
=
Image
.
open
(
path
)
batch_images
.
append
((
img
,
path
))
except
:
print
(
f
"Error processing
{
path
}
:"
,
file
=
sys
.
stderr
)
print
(
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
if
len
(
batch_images
)
==
0
:
continue
state
.
job
=
f
"
{
batch_no
}
out of
{
batch_count
}
:
{
batch_images
[
0
][
1
]
}
"
p
.
init_images
=
[
x
[
0
]
for
x
in
batch_images
]
proc
=
process_images
(
p
)
for
image
,
(
_
,
path
)
in
zip
(
proc
.
images
,
batch_images
):
filename
=
os
.
path
.
basename
(
path
)
image
.
save
(
os
.
path
.
join
(
output_dir
,
filename
))
return
Processed
(
p
,
[],
p
.
seed
,
""
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录