Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
d38ede71
Unverified
Commit
d38ede71
authored
Jan 07, 2023
by
noodleanon
Committed by
GitHub
Jan 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added script support in txt2img endpoint
parent
50e25362
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
api.py
modules/api/api.py
+19
-3
models.py
modules/api/models.py
+1
-1
No files found.
modules/api/api.py
View file @
d38ede71
...
@@ -149,6 +149,14 @@ class Api:
...
@@ -149,6 +149,14 @@ class Api:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Incorrect username or password"
,
headers
=
{
"WWW-Authenticate"
:
"Basic"
})
raise
HTTPException
(
status_code
=
401
,
detail
=
"Incorrect username or password"
,
headers
=
{
"WWW-Authenticate"
:
"Basic"
})
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
if
txt2imgreq
.
script_name
is
not
None
:
if
scripts
.
scripts_txt2img
.
scripts
==
[]:
scripts
.
scripts_txt2img
.
initialize_scripts
(
True
)
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
]
populate
=
txt2imgreq
.
copy
(
update
=
{
# Override __init__ params
populate
=
txt2imgreq
.
copy
(
update
=
{
# Override __init__ params
"sampler_name"
:
validate_sampler_name
(
txt2imgreq
.
sampler_name
or
txt2imgreq
.
sampler_index
),
"sampler_name"
:
validate_sampler_name
(
txt2imgreq
.
sampler_name
or
txt2imgreq
.
sampler_index
),
"do_not_save_samples"
:
True
,
"do_not_save_samples"
:
True
,
...
@@ -158,11 +166,20 @@ class Api:
...
@@ -158,11 +166,20 @@ class Api:
if
populate
.
sampler_name
:
if
populate
.
sampler_name
:
populate
.
sampler_index
=
None
# prevent a warning later on
populate
.
sampler_index
=
None
# prevent a warning later on
args
=
vars
(
populate
)
args
.
pop
(
'script_name'
,
None
)
with
self
.
queue_lock
:
with
self
.
queue_lock
:
p
=
StableDiffusionProcessingTxt2Img
(
sd_model
=
shared
.
sd_model
,
**
vars
(
populate
)
)
p
=
StableDiffusionProcessingTxt2Img
(
sd_model
=
shared
.
sd_model
,
**
args
)
shared
.
state
.
begin
()
shared
.
state
.
begin
()
processed
=
process_images
(
p
)
if
'script'
in
locals
():
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
processed
=
scripts
.
scripts_txt2img
.
run
(
p
,
*
p
.
script_args
)
else
:
processed
=
process_images
(
p
)
shared
.
state
.
end
()
shared
.
state
.
end
()
...
@@ -213,7 +230,6 @@ class Api:
...
@@ -213,7 +230,6 @@ class Api:
processed
=
scripts
.
scripts_img2img
.
run
(
p
,
*
p
.
script_args
)
processed
=
scripts
.
scripts_img2img
.
run
(
p
,
*
p
.
script_args
)
else
:
else
:
processed
=
process_images
(
p
)
processed
=
process_images
(
p
)
shared
.
state
.
end
()
shared
.
state
.
end
()
b64images
=
list
(
map
(
encode_pil_to_base64
,
processed
.
images
))
b64images
=
list
(
map
(
encode_pil_to_base64
,
processed
.
images
))
...
...
modules/api/models.py
View file @
d38ede71
...
@@ -100,7 +100,7 @@ class PydanticModelGenerator:
...
@@ -100,7 +100,7 @@ class PydanticModelGenerator:
StableDiffusionTxt2ImgProcessingAPI
=
PydanticModelGenerator
(
StableDiffusionTxt2ImgProcessingAPI
=
PydanticModelGenerator
(
"StableDiffusionProcessingTxt2Img"
,
"StableDiffusionProcessingTxt2Img"
,
StableDiffusionProcessingTxt2Img
,
StableDiffusionProcessingTxt2Img
,
[{
"key"
:
"sampler_index"
,
"type"
:
str
,
"default"
:
"Euler"
}]
[{
"key"
:
"sampler_index"
,
"type"
:
str
,
"default"
:
"Euler"
}
,
{
"key"
:
"script_name"
,
"type"
:
str
,
"default"
:
None
},
{
"key"
:
"script_args"
,
"type"
:
list
,
"default"
:
[]}
]
)
.
generate_model
()
)
.
generate_model
()
StableDiffusionImg2ImgProcessingAPI
=
PydanticModelGenerator
(
StableDiffusionImg2ImgProcessingAPI
=
PydanticModelGenerator
(
...
...
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