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
4ff852ff
Commit
4ff852ff
authored
Oct 23, 2022
by
Bruno Seoane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add batch processing "extras" endpoint
parent
0523704d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
api.py
modules/api/api.py
+23
-2
models.py
modules/api/models.py
+14
-1
No files found.
modules/api/api.py
View file @
4ff852ff
...
@@ -10,6 +10,7 @@ import base64
...
@@ -10,6 +10,7 @@ import base64
from
modules.api.models
import
*
from
modules.api.models
import
*
from
PIL
import
Image
from
PIL
import
Image
from
modules.extras
import
run_extras
from
modules.extras
import
run_extras
from
gradio
import
processing_utils
def
upscaler_to_index
(
name
:
str
):
def
upscaler_to_index
(
name
:
str
):
try
:
try
:
...
@@ -44,6 +45,7 @@ class Api:
...
@@ -44,6 +45,7 @@ class Api:
self
.
queue_lock
=
queue_lock
self
.
queue_lock
=
queue_lock
self
.
app
.
add_api_route
(
"/sdapi/v1/txt2img"
,
self
.
text2imgapi
,
methods
=
[
"POST"
],
response_model
=
TextToImageResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/txt2img"
,
self
.
text2imgapi
,
methods
=
[
"POST"
],
response_model
=
TextToImageResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/extra-single-image"
,
self
.
extras_single_image_api
,
methods
=
[
"POST"
],
response_model
=
ExtrasSingleImageResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/extra-single-image"
,
self
.
extras_single_image_api
,
methods
=
[
"POST"
],
response_model
=
ExtrasSingleImageResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/extra-batch-image"
,
self
.
extras_batch_images_api
,
methods
=
[
"POST"
],
response_model
=
ExtrasBatchImagesResponse
)
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionProcessingAPI
):
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionProcessingAPI
):
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
...
@@ -78,12 +80,31 @@ class Api:
...
@@ -78,12 +80,31 @@ class Api:
reqDict
.
pop
(
'upscaler_1'
)
reqDict
.
pop
(
'upscaler_1'
)
reqDict
.
pop
(
'upscaler_2'
)
reqDict
.
pop
(
'upscaler_2'
)
reqDict
[
'image'
]
=
base64_to_images
([
reqDict
[
'image'
]])[
0
]
reqDict
[
'image'
]
=
processing_utils
.
decode_base64_to_file
(
reqDict
[
'image'
])
with
self
.
queue_lock
:
with
self
.
queue_lock
:
result
=
run_extras
(
**
reqDict
,
extras_upscaler_1
=
upscaler1Index
,
extras_upscaler_2
=
upscaler2Index
,
extras_mode
=
0
,
image_folder
=
""
,
input_dir
=
""
,
output_dir
=
""
)
result
=
run_extras
(
**
reqDict
,
extras_upscaler_1
=
upscaler1Index
,
extras_upscaler_2
=
upscaler2Index
,
extras_mode
=
0
,
image_folder
=
""
,
input_dir
=
""
,
output_dir
=
""
)
return
ExtrasSingleImageResponse
(
image
=
"data:image/png;base64,"
+
img_to_base64
(
result
[
0
]),
html_info_x
=
result
[
1
],
html_info
=
result
[
2
])
return
ExtrasSingleImageResponse
(
image
=
processing_utils
.
encode_pil_to_base64
(
result
[
0
]),
html_info_x
=
result
[
1
],
html_info
=
result
[
2
])
def
extras_batch_images_api
(
self
,
req
:
ExtrasBatchImagesRequest
):
upscaler1Index
=
upscaler_to_index
(
req
.
upscaler_1
)
upscaler2Index
=
upscaler_to_index
(
req
.
upscaler_2
)
reqDict
=
vars
(
req
)
reqDict
.
pop
(
'upscaler_1'
)
reqDict
.
pop
(
'upscaler_2'
)
reqDict
[
'image_folder'
]
=
list
(
map
(
processing_utils
.
decode_base64_to_file
,
reqDict
[
'imageList'
]))
reqDict
.
pop
(
'imageList'
)
with
self
.
queue_lock
:
result
=
run_extras
(
**
reqDict
,
extras_upscaler_1
=
upscaler1Index
,
extras_upscaler_2
=
upscaler2Index
,
extras_mode
=
1
,
image
=
""
,
input_dir
=
""
,
output_dir
=
""
)
return
ExtrasBatchImagesResponse
(
images
=
list
(
map
(
processing_utils
.
encode_pil_to_base64
,
result
[
0
])),
html_info_x
=
result
[
1
],
html_info
=
result
[
2
])
def
extras_folder_processing_api
(
self
):
raise
NotImplementedError
def
pnginfoapi
(
self
):
def
pnginfoapi
(
self
):
raise
NotImplementedError
raise
NotImplementedError
...
...
modules/api/models.py
View file @
4ff852ff
...
@@ -29,4 +29,17 @@ class ExtrasSingleImageRequest(ExtrasBaseRequest):
...
@@ -29,4 +29,17 @@ class ExtrasSingleImageRequest(ExtrasBaseRequest):
image
:
str
=
Field
(
default
=
""
,
title
=
"Image"
,
description
=
"Image to work on, must be a Base64 string containing the image's data."
)
image
:
str
=
Field
(
default
=
""
,
title
=
"Image"
,
description
=
"Image to work on, must be a Base64 string containing the image's data."
)
class
ExtrasSingleImageResponse
(
ExtraBaseResponse
):
class
ExtrasSingleImageResponse
(
ExtraBaseResponse
):
image
:
str
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
image
:
str
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
\ No newline at end of file
class
SerializableImage
(
BaseModel
):
path
:
str
=
Field
(
title
=
"Path"
,
description
=
"The image's path ()"
)
class
ImageItem
(
BaseModel
):
data
:
str
=
Field
(
title
=
"image data"
)
name
:
str
=
Field
(
title
=
"filename"
)
class
ExtrasBatchImagesRequest
(
ExtrasBaseRequest
):
imageList
:
list
[
str
]
=
Field
(
title
=
"Images"
,
description
=
"List of images to work on. Must be Base64 strings"
)
class
ExtrasBatchImagesResponse
(
ExtraBaseResponse
):
images
:
list
[
str
]
=
Field
(
title
=
"Images"
,
description
=
"The generated images in base64 format."
)
\ No newline at end of file
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