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
b02926df
Commit
b02926df
authored
Oct 22, 2022
by
Bruno Seoane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved moodels to their own file and extracted base64 conversion to its own function
parent
1b4d0473
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
11 deletions
+14
-11
api.py
modules/api/api.py
+6
-11
models.py
modules/api/models.py
+8
-0
No files found.
modules/api/api.py
View file @
b02926df
...
...
@@ -4,17 +4,17 @@ from modules.sd_samplers import all_samplers
import
modules.shared
as
shared
import
uvicorn
from
fastapi
import
APIRouter
,
HTTPException
from
pydantic
import
BaseModel
,
Field
,
Json
import
json
import
io
import
base64
from
modules.api.models
import
*
sampler_to_index
=
lambda
name
:
next
(
filter
(
lambda
row
:
name
.
lower
()
==
row
[
1
]
.
name
.
lower
(),
enumerate
(
all_samplers
)),
None
)
class
TextToImageResponse
(
BaseModel
):
images
:
list
[
str
]
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
parameters
:
Json
info
:
Json
def
img_to_base64
(
img
):
buffer
=
io
.
BytesIO
(
)
img
.
save
(
buffer
,
format
=
"png"
)
return
base64
.
b64encode
(
buffer
.
getvalue
())
class
Api
:
def
__init__
(
self
,
app
,
queue_lock
):
...
...
@@ -41,16 +41,11 @@ class Api:
with
self
.
queue_lock
:
processed
=
process_images
(
p
)
b64images
=
[]
for
i
in
processed
.
images
:
buffer
=
io
.
BytesIO
()
i
.
save
(
buffer
,
format
=
"png"
)
b64images
.
append
(
base64
.
b64encode
(
buffer
.
getvalue
()))
b64images
=
list
(
map
(
img_to_base64
,
processed
.
images
))
return
TextToImageResponse
(
images
=
b64images
,
parameters
=
json
.
dumps
(
vars
(
txt2imgreq
)),
info
=
json
.
dumps
(
processed
.
info
))
def
img2imgapi
(
self
):
raise
NotImplementedError
...
...
modules/api/models.py
0 → 100644
View file @
b02926df
from
pydantic
import
BaseModel
,
Field
,
Json
class
TextToImageResponse
(
BaseModel
):
images
:
list
[
str
]
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
parameters
:
Json
info
:
Json
\ 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