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
a546e2a8
Unverified
Commit
a546e2a8
authored
Nov 05, 2022
by
AUTOMATIC1111
Committed by
GitHub
Nov 05, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4173 from evshiron/fix/encode-pnginfo
add back png info in image api
parents
62e3d71a
b6cfaaa2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
api.py
modules/api/api.py
+24
-11
No files found.
modules/api/api.py
View file @
a546e2a8
...
@@ -10,6 +10,7 @@ from modules.api.models import *
...
@@ -10,6 +10,7 @@ from modules.api.models import *
from
modules.processing
import
StableDiffusionProcessingTxt2Img
,
StableDiffusionProcessingImg2Img
,
process_images
from
modules.processing
import
StableDiffusionProcessingTxt2Img
,
StableDiffusionProcessingImg2Img
,
process_images
from
modules.sd_samplers
import
all_samplers
from
modules.sd_samplers
import
all_samplers
from
modules.extras
import
run_extras
,
run_pnginfo
from
modules.extras
import
run_extras
,
run_pnginfo
from
PIL
import
PngImagePlugin
from
modules.sd_models
import
checkpoints_list
from
modules.sd_models
import
checkpoints_list
from
modules.realesrgan_model
import
get_realesrgan_models
from
modules.realesrgan_model
import
get_realesrgan_models
from
typing
import
List
from
typing
import
List
...
@@ -34,9 +35,21 @@ def setUpscalers(req: dict):
...
@@ -34,9 +35,21 @@ def setUpscalers(req: dict):
def
encode_pil_to_base64
(
image
):
def
encode_pil_to_base64
(
image
):
buffer
=
io
.
BytesIO
()
with
io
.
BytesIO
()
as
output_bytes
:
image
.
save
(
buffer
,
format
=
"png"
)
return
base64
.
b64encode
(
buffer
.
getvalue
())
# Copy any text-only metadata
use_metadata
=
False
metadata
=
PngImagePlugin
.
PngInfo
()
for
key
,
value
in
image
.
info
.
items
():
if
isinstance
(
key
,
str
)
and
isinstance
(
value
,
str
):
metadata
.
add_text
(
key
,
value
)
use_metadata
=
True
image
.
save
(
output_bytes
,
"PNG"
,
pnginfo
=
(
metadata
if
use_metadata
else
None
)
)
bytes_data
=
output_bytes
.
getvalue
()
return
base64
.
b64encode
(
bytes_data
)
class
Api
:
class
Api
:
...
@@ -205,7 +218,7 @@ class Api:
...
@@ -205,7 +218,7 @@ class Api:
shared
.
state
.
interrupt
()
shared
.
state
.
interrupt
()
return
{}
return
{}
def
get_config
(
self
):
def
get_config
(
self
):
options
=
{}
options
=
{}
for
key
in
shared
.
opts
.
data
.
keys
():
for
key
in
shared
.
opts
.
data
.
keys
():
...
@@ -214,9 +227,9 @@ class Api:
...
@@ -214,9 +227,9 @@ class Api:
options
.
update
({
key
:
shared
.
opts
.
data
.
get
(
key
,
shared
.
opts
.
data_labels
.
get
(
key
)
.
default
)})
options
.
update
({
key
:
shared
.
opts
.
data
.
get
(
key
,
shared
.
opts
.
data_labels
.
get
(
key
)
.
default
)})
else
:
else
:
options
.
update
({
key
:
shared
.
opts
.
data
.
get
(
key
,
None
)})
options
.
update
({
key
:
shared
.
opts
.
data
.
get
(
key
,
None
)})
return
options
return
options
def
set_config
(
self
,
req
:
OptionsModel
):
def
set_config
(
self
,
req
:
OptionsModel
):
# currently req has all options fields even if you send a dict like { "send_seed": false }, which means it will
# currently req has all options fields even if you send a dict like { "send_seed": false }, which means it will
# overwrite all options with default values.
# overwrite all options with default values.
...
@@ -237,13 +250,13 @@ class Api:
...
@@ -237,13 +250,13 @@ class Api:
def
get_upscalers
(
self
):
def
get_upscalers
(
self
):
upscalers
=
[]
upscalers
=
[]
for
upscaler
in
shared
.
sd_upscalers
:
for
upscaler
in
shared
.
sd_upscalers
:
u
=
upscaler
.
scaler
u
=
upscaler
.
scaler
upscalers
.
append
({
"name"
:
u
.
name
,
"model_name"
:
u
.
model_name
,
"model_path"
:
u
.
model_path
,
"model_url"
:
u
.
model_url
})
upscalers
.
append
({
"name"
:
u
.
name
,
"model_name"
:
u
.
model_name
,
"model_path"
:
u
.
model_path
,
"model_url"
:
u
.
model_url
})
return
upscalers
return
upscalers
def
get_sd_models
(
self
):
def
get_sd_models
(
self
):
return
[{
"title"
:
x
.
title
,
"model_name"
:
x
.
model_name
,
"hash"
:
x
.
hash
,
"filename"
:
x
.
filename
,
"config"
:
x
.
config
}
for
x
in
checkpoints_list
.
values
()]
return
[{
"title"
:
x
.
title
,
"model_name"
:
x
.
model_name
,
"hash"
:
x
.
hash
,
"filename"
:
x
.
filename
,
"config"
:
x
.
config
}
for
x
in
checkpoints_list
.
values
()]
...
@@ -255,11 +268,11 @@ class Api:
...
@@ -255,11 +268,11 @@ class Api:
def
get_realesrgan_models
(
self
):
def
get_realesrgan_models
(
self
):
return
[{
"name"
:
x
.
name
,
"path"
:
x
.
data_path
,
"scale"
:
x
.
scale
}
for
x
in
get_realesrgan_models
(
None
)]
return
[{
"name"
:
x
.
name
,
"path"
:
x
.
data_path
,
"scale"
:
x
.
scale
}
for
x
in
get_realesrgan_models
(
None
)]
def
get_promp_styles
(
self
):
def
get_promp_styles
(
self
):
styleList
=
[]
styleList
=
[]
for
k
in
shared
.
prompt_styles
.
styles
:
for
k
in
shared
.
prompt_styles
.
styles
:
style
=
shared
.
prompt_styles
.
styles
[
k
]
style
=
shared
.
prompt_styles
.
styles
[
k
]
styleList
.
append
({
"name"
:
style
[
0
],
"prompt"
:
style
[
1
],
"negative_prompr"
:
style
[
2
]})
styleList
.
append
({
"name"
:
style
[
0
],
"prompt"
:
style
[
1
],
"negative_prompr"
:
style
[
2
]})
return
styleList
return
styleList
...
...
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