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
c328deb5
Unverified
Commit
c328deb5
authored
Oct 29, 2022
by
AUTOMATIC1111
Committed by
GitHub
Oct 29, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3934 from bamarillo/api-add-png-info-endpoint
[API][Feature] Add png info endpoint
parents
9bb6b650
83a1f44a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
api.py
modules/api/api.py
+9
-3
models.py
modules/api/models.py
+8
-1
No files found.
modules/api/api.py
View file @
c328deb5
...
@@ -5,7 +5,7 @@ import modules.shared as shared
...
@@ -5,7 +5,7 @@ import modules.shared as shared
from
modules.api.models
import
*
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
from
modules.extras
import
run_extras
,
run_pnginfo
def
upscaler_to_index
(
name
:
str
):
def
upscaler_to_index
(
name
:
str
):
try
:
try
:
...
@@ -32,6 +32,7 @@ class Api:
...
@@ -32,6 +32,7 @@ class Api:
self
.
app
.
add_api_route
(
"/sdapi/v1/img2img"
,
self
.
img2imgapi
,
methods
=
[
"POST"
],
response_model
=
ImageToImageResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/img2img"
,
self
.
img2imgapi
,
methods
=
[
"POST"
],
response_model
=
ImageToImageResponse
)
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-images"
,
self
.
extras_batch_images_api
,
methods
=
[
"POST"
],
response_model
=
ExtrasBatchImagesResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/extra-batch-images"
,
self
.
extras_batch_images_api
,
methods
=
[
"POST"
],
response_model
=
ExtrasBatchImagesResponse
)
self
.
app
.
add_api_route
(
"/sdapi/v1/png-info"
,
self
.
pnginfoapi
,
methods
=
[
"POST"
],
response_model
=
PNGInfoResponse
)
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
...
@@ -125,8 +126,13 @@ class Api:
...
@@ -125,8 +126,13 @@ class Api:
return
ExtrasBatchImagesResponse
(
images
=
list
(
map
(
encode_pil_to_base64
,
result
[
0
])),
html_info
=
result
[
1
])
return
ExtrasBatchImagesResponse
(
images
=
list
(
map
(
encode_pil_to_base64
,
result
[
0
])),
html_info
=
result
[
1
])
def
pnginfoapi
(
self
):
def
pnginfoapi
(
self
,
req
:
PNGInfoRequest
):
raise
NotImplementedError
if
(
not
req
.
image
.
strip
()):
return
PNGInfoResponse
(
info
=
""
)
result
=
run_pnginfo
(
decode_base64_to_image
(
req
.
image
.
strip
()))
return
PNGInfoResponse
(
info
=
result
[
1
])
def
launch
(
self
,
server_name
,
port
):
def
launch
(
self
,
server_name
,
port
):
self
.
app
.
include_router
(
self
.
router
)
self
.
app
.
include_router
(
self
.
router
)
...
...
modules/api/models.py
View file @
c328deb5
import
inspect
import
inspect
from
click
import
prompt
from
pydantic
import
BaseModel
,
Field
,
create_model
from
pydantic
import
BaseModel
,
Field
,
create_model
from
typing
import
Any
,
Optional
from
typing
import
Any
,
Optional
from
typing_extensions
import
Literal
from
typing_extensions
import
Literal
...
@@ -148,4 +149,10 @@ class ExtrasBatchImagesRequest(ExtrasBaseRequest):
...
@@ -148,4 +149,10 @@ class ExtrasBatchImagesRequest(ExtrasBaseRequest):
imageList
:
list
[
FileData
]
=
Field
(
title
=
"Images"
,
description
=
"List of images to work on. Must be Base64 strings"
)
imageList
:
list
[
FileData
]
=
Field
(
title
=
"Images"
,
description
=
"List of images to work on. Must be Base64 strings"
)
class
ExtrasBatchImagesResponse
(
ExtraBaseResponse
):
class
ExtrasBatchImagesResponse
(
ExtraBaseResponse
):
images
:
list
[
str
]
=
Field
(
title
=
"Images"
,
description
=
"The generated images in base64 format."
)
images
:
list
[
str
]
=
Field
(
title
=
"Images"
,
description
=
"The generated images in base64 format."
)
\ No newline at end of file
class
PNGInfoRequest
(
BaseModel
):
image
:
str
=
Field
(
title
=
"Image"
,
description
=
"The base64 encoded PNG image"
)
class
PNGInfoResponse
(
BaseModel
):
info
:
str
=
Field
(
title
=
"Image info"
,
description
=
"A string with all the info the image had"
)
\ 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