Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
db9ab1a4
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1746
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
db9ab1a4
编写于
10月 24, 2022
作者:
S
Stephen
提交者:
AUTOMATIC1111
10月 26, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Bugfix][API] - Fix API response for colab users
上级
cbb857b6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
8 deletion
+19
-8
modules/api/api.py
modules/api/api.py
+13
-4
modules/api/models.py
modules/api/models.py
+6
-4
未找到文件。
modules/api/api.py
浏览文件 @
db9ab1a4
...
...
@@ -7,6 +7,7 @@ import uvicorn
from
fastapi
import
Body
,
APIRouter
,
HTTPException
from
fastapi.responses
import
JSONResponse
from
pydantic
import
BaseModel
,
Field
,
Json
from
typing
import
List
import
json
import
io
import
base64
...
...
@@ -15,12 +16,12 @@ from PIL import Image
sampler_to_index
=
lambda
name
:
next
(
filter
(
lambda
row
:
name
.
lower
()
==
row
[
1
].
name
.
lower
(),
enumerate
(
all_samplers
)),
None
)
class
TextToImageResponse
(
BaseModel
):
images
:
l
ist
[
str
]
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
images
:
L
ist
[
str
]
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
parameters
:
Json
info
:
Json
class
ImageToImageResponse
(
BaseModel
):
images
:
l
ist
[
str
]
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
images
:
L
ist
[
str
]
=
Field
(
default
=
None
,
title
=
"Image"
,
description
=
"The generated image in base64 format."
)
parameters
:
Json
info
:
Json
...
...
@@ -41,6 +42,9 @@ class Api:
# convert base64 to PIL image
return
Image
.
open
(
io
.
BytesIO
(
imgdata
))
def
__processed_info_to_json
(
self
,
processed
):
return
json
.
dumps
(
processed
.
info
)
def
text2imgapi
(
self
,
txt2imgreq
:
StableDiffusionTxt2ImgProcessingAPI
):
sampler_index
=
sampler_to_index
(
txt2imgreq
.
sampler_index
)
...
...
@@ -65,7 +69,7 @@ class Api:
i
.
save
(
buffer
,
format
=
"png"
)
b64images
.
append
(
base64
.
b64encode
(
buffer
.
getvalue
()))
return
TextToImageResponse
(
images
=
b64images
,
parameters
=
json
.
dumps
(
vars
(
txt2imgreq
)),
info
=
json
.
dumps
(
processed
.
info
))
return
TextToImageResponse
(
images
=
b64images
,
parameters
=
json
.
dumps
(
vars
(
txt2imgreq
)),
info
=
processed
.
js
(
))
...
...
@@ -111,7 +115,12 @@ class Api:
i
.
save
(
buffer
,
format
=
"png"
)
b64images
.
append
(
base64
.
b64encode
(
buffer
.
getvalue
()))
return
ImageToImageResponse
(
images
=
b64images
,
parameters
=
json
.
dumps
(
vars
(
img2imgreq
)),
info
=
json
.
dumps
(
processed
.
info
))
if
(
not
img2imgreq
.
include_init_images
):
# remove img2imgreq.init_images and img2imgreq.mask
img2imgreq
.
init_images
=
None
img2imgreq
.
mask
=
None
return
ImageToImageResponse
(
images
=
b64images
,
parameters
=
json
.
dumps
(
vars
(
img2imgreq
)),
info
=
processed
.
js
())
def
extrasapi
(
self
):
raise
NotImplementedError
...
...
modules/api/models.py
浏览文件 @
db9ab1a4
...
...
@@ -31,6 +31,7 @@ class ModelDef(BaseModel):
field_alias
:
str
field_type
:
Any
field_value
:
Any
field_exclude
:
bool
=
False
class
PydanticModelGenerator
:
...
...
@@ -68,7 +69,7 @@ class PydanticModelGenerator:
field
=
underscore
(
k
),
field_alias
=
k
,
field_type
=
field_type_generator
(
k
,
v
),
field_value
=
v
.
default
field_value
=
v
.
default
,
)
for
(
k
,
v
)
in
self
.
_class_data
.
items
()
if
k
not
in
API_NOT_ALLOWED
]
...
...
@@ -78,7 +79,8 @@ class PydanticModelGenerator:
field
=
underscore
(
fields
[
"key"
]),
field_alias
=
fields
[
"key"
],
field_type
=
fields
[
"type"
],
field_value
=
fields
[
"default"
]))
field_value
=
fields
[
"default"
],
field_exclude
=
fields
[
"exclude"
]
if
"exclude"
in
fields
else
False
))
def
generate_model
(
self
):
"""
...
...
@@ -86,7 +88,7 @@ class PydanticModelGenerator:
from the json and overrides provided at initialization
"""
fields
=
{
d
.
field
:
(
d
.
field_type
,
Field
(
default
=
d
.
field_value
,
alias
=
d
.
field_alias
))
for
d
in
self
.
_model_def
d
.
field
:
(
d
.
field_type
,
Field
(
default
=
d
.
field_value
,
alias
=
d
.
field_alias
,
exclude
=
d
.
field_exclude
))
for
d
in
self
.
_model_def
}
DynamicModel
=
create_model
(
self
.
_model_name
,
**
fields
)
DynamicModel
.
__config__
.
allow_population_by_field_name
=
True
...
...
@@ -102,5 +104,5 @@ StableDiffusionTxt2ImgProcessingAPI = PydanticModelGenerator(
StableDiffusionImg2ImgProcessingAPI
=
PydanticModelGenerator
(
"StableDiffusionProcessingImg2Img"
,
StableDiffusionProcessingImg2Img
,
[{
"key"
:
"sampler_index"
,
"type"
:
str
,
"default"
:
"Euler"
},
{
"key"
:
"init_images"
,
"type"
:
list
,
"default"
:
None
},
{
"key"
:
"denoising_strength"
,
"type"
:
float
,
"default"
:
0.75
},
{
"key"
:
"mask"
,
"type"
:
str
,
"default"
:
None
}]
[{
"key"
:
"sampler_index"
,
"type"
:
str
,
"default"
:
"Euler"
},
{
"key"
:
"init_images"
,
"type"
:
list
,
"default"
:
None
},
{
"key"
:
"denoising_strength"
,
"type"
:
float
,
"default"
:
0.75
},
{
"key"
:
"mask"
,
"type"
:
str
,
"default"
:
None
}
,
{
"key"
:
"include_init_images"
,
"type"
:
bool
,
"default"
:
False
,
"exclude"
:
True
}
]
).
generate_model
()
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录