Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
22faf30c
Commit
22faf30c
authored
Sep 10, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add script for batch file processing
parent
6f678ec7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
scripts/batch.py
scripts/batch.py
+59
-0
No files found.
scripts/batch.py
0 → 100644
View file @
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
,
""
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment