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
5dc0739e
Commit
5dc0739e
authored
Oct 22, 2022
by
Stephen
Committed by
AUTOMATIC1111
Oct 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working mask
parent
9e1a8b77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
modules/api/api.py
modules/api/api.py
+12
-8
No files found.
modules/api/api.py
View file @
5dc0739e
...
...
@@ -33,6 +33,14 @@ class Api:
self
.
app
.
add_api_route
(
"/sdapi/v1/txt2img"
,
self
.
text2imgapi
,
methods
=
[
"POST"
])
self
.
app
.
add_api_route
(
"/sdapi/v1/img2img"
,
self
.
img2imgapi
,
methods
=
[
"POST"
])
def
__base64_to_image
(
self
,
base64_string
):
# if has a comma, deal with prefix
if
","
in
base64_string
:
base64_string
=
base64_string
.
split
(
","
)[
1
]
imgdata
=
base64
.
b64decode
(
base64_string
)
# convert base64 to PIL image
return
Image
.
open
(
io
.
BytesIO
(
imgdata
))
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
...
...
@@ -74,26 +82,22 @@ class Api:
mask
=
img2imgreq
.
mask
if
mask
:
raise
HTTPException
(
status_code
=
400
,
detail
=
"Mask not supported yet"
)
mask
=
self
.
__base64_to_image
(
mask
)
populate
=
img2imgreq
.
copy
(
update
=
{
# Override __init__ params
"sd_model"
:
shared
.
sd_model
,
"sampler_index"
:
sampler_index
[
0
],
"do_not_save_samples"
:
True
,
"do_not_save_grid"
:
True
"do_not_save_grid"
:
True
,
"mask"
:
mask
}
)
p
=
StableDiffusionProcessingImg2Img
(
**
vars
(
populate
))
imgs
=
[]
for
img
in
init_images
:
# if has a comma, deal with prefix
if
","
in
img
:
img
=
img
.
split
(
","
)[
1
]
# convert base64 to PIL image
img
=
base64
.
b64decode
(
img
)
img
=
Image
.
open
(
io
.
BytesIO
(
img
))
img
=
self
.
__base64_to_image
(
img
)
imgs
=
[
img
]
*
p
.
batch_size
p
.
init_images
=
imgs
...
...
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