Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
b0b90dc0
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1743
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
b0b90dc0
编写于
3月 24, 2024
作者:
A
AUTOMATIC1111
提交者:
GitHub
3月 24, 2024
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15319 from catboxanon/feat/ssmd_cover_images
Support cover images embedded in safetensors metadata
上级
9aa9e980
c4402500
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
2 deletion
+43
-2
extensions-builtin/Lora/network.py
extensions-builtin/Lora/network.py
+0
-1
extensions-builtin/Lora/ui_extra_networks_lora.py
extensions-builtin/Lora/ui_extra_networks_lora.py
+1
-1
modules/ui_extra_networks.py
modules/ui_extra_networks.py
+42
-0
未找到文件。
extensions-builtin/Lora/network.py
浏览文件 @
b0b90dc0
...
...
@@ -29,7 +29,6 @@ class NetworkOnDisk:
def
read_metadata
():
metadata
=
sd_models
.
read_metadata_from_safetensors
(
filename
)
metadata
.
pop
(
'ssmd_cover_images'
,
None
)
# those are cover images, and they are too big to display in UI as text
return
metadata
...
...
extensions-builtin/Lora/ui_extra_networks_lora.py
浏览文件 @
b0b90dc0
...
...
@@ -31,7 +31,7 @@ class ExtraNetworksPageLora(ui_extra_networks.ExtraNetworksPage):
"name"
:
name
,
"filename"
:
lora_on_disk
.
filename
,
"shorthash"
:
lora_on_disk
.
shorthash
,
"preview"
:
self
.
find_preview
(
path
),
"preview"
:
self
.
find_preview
(
path
)
or
self
.
find_embedded_preview
(
path
,
name
,
lora_on_disk
.
metadata
)
,
"description"
:
self
.
find_description
(
path
),
"search_terms"
:
search_terms
,
"local_preview"
:
f
"
{
path
}
.
{
shared
.
opts
.
samples_format
}
"
,
...
...
modules/ui_extra_networks.py
浏览文件 @
b0b90dc0
import
functools
import
os.path
import
urllib.parse
from
base64
import
b64decode
from
io
import
BytesIO
from
pathlib
import
Path
from
typing
import
Optional
,
Union
from
dataclasses
import
dataclass
...
...
@@ -11,6 +13,7 @@ import gradio as gr
import
json
import
html
from
fastapi.exceptions
import
HTTPException
from
PIL
import
Image
from
modules.infotext_utils
import
image_from_url_text
...
...
@@ -108,6 +111,31 @@ def fetch_file(filename: str = ""):
return
FileResponse
(
filename
,
headers
=
{
"Accept-Ranges"
:
"bytes"
})
def
fetch_cover_images
(
page
:
str
=
""
,
item
:
str
=
""
,
index
:
int
=
0
):
from
starlette.responses
import
Response
page
=
next
(
iter
([
x
for
x
in
extra_pages
if
x
.
name
==
page
]),
None
)
if
page
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"File not found"
)
metadata
=
page
.
metadata
.
get
(
item
)
if
metadata
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"File not found"
)
cover_images
=
json
.
loads
(
metadata
.
get
(
'ssmd_cover_images'
,
{}))
image
=
cover_images
[
index
]
if
index
<
len
(
cover_images
)
else
None
if
not
image
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"File not found"
)
try
:
image
=
Image
.
open
(
BytesIO
(
b64decode
(
image
)))
buffer
=
BytesIO
()
image
.
save
(
buffer
,
format
=
image
.
format
)
return
Response
(
content
=
buffer
.
getvalue
(),
media_type
=
image
.
get_format_mimetype
())
except
Exception
as
err
:
raise
ValueError
(
f
"File cannot be fetched:
{
item
}
. Failed to load cover image."
)
from
err
def
get_metadata
(
page
:
str
=
""
,
item
:
str
=
""
):
from
starlette.responses
import
JSONResponse
...
...
@@ -119,6 +147,8 @@ def get_metadata(page: str = "", item: str = ""):
if
metadata
is
None
:
return
JSONResponse
({})
metadata
=
{
i
:
metadata
[
i
]
for
i
in
metadata
if
i
!=
'ssmd_cover_images'
}
# those are cover images, and they are too big to display in UI as text
return
JSONResponse
({
"metadata"
:
json
.
dumps
(
metadata
,
indent
=
4
,
ensure_ascii
=
False
)})
...
...
@@ -142,6 +172,7 @@ def get_single_card(page: str = "", tabname: str = "", name: str = ""):
def
add_pages_to_demo
(
app
):
app
.
add_api_route
(
"/sd_extra_networks/thumb"
,
fetch_file
,
methods
=
[
"GET"
])
app
.
add_api_route
(
"/sd_extra_networks/cover-images"
,
fetch_cover_images
,
methods
=
[
"GET"
])
app
.
add_api_route
(
"/sd_extra_networks/metadata"
,
get_metadata
,
methods
=
[
"GET"
])
app
.
add_api_route
(
"/sd_extra_networks/get-single-card"
,
get_single_card
,
methods
=
[
"GET"
])
...
...
@@ -626,6 +657,17 @@ class ExtraNetworksPage:
return
None
def
find_embedded_preview
(
self
,
path
,
name
,
metadata
):
"""
Find if embedded preview exists in safetensors metadata and return endpoint for it.
"""
file
=
f
"
{
path
}
.safetensors"
if
self
.
lister
.
exists
(
file
)
and
'ssmd_cover_images'
in
metadata
and
len
(
list
(
filter
(
None
,
json
.
loads
(
metadata
[
'ssmd_cover_images'
]))))
>
0
:
return
f
"./sd_extra_networks/cover-images?page=
{
self
.
extra_networks_tabname
}
&item=
{
name
}
"
return
None
def
find_description
(
self
,
path
):
"""
Find and read a description file for a given path (without extension).
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录