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
137ce534
Commit
137ce534
authored
Jan 08, 2023
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove some code duplication
remove calls to locals() add a test for img2img with script
parent
e7f2f1e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
17 deletions
+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
No files found.
modules/api/api.py
View file @
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
)
ui
.
create_ui
()
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
(
script_name
,
script_runner
.
selectable_scripts
)
script
=
script_runner
.
selectable_scripts
[
script_idx
]
return
script
,
script_idx
script_idx
=
script_name_to_index
(
txt2imgreq
.
script_name
,
scripts
.
scripts_txt2img
.
selectable_scripts
)
script
=
scripts
.
scripts_txt2img
.
selectable_scripts
[
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
View file @
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
()
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