Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from huggingface_hub import snapshot_download
|
| 2 |
from insightface.app import FaceAnalysis
|
| 3 |
import numpy as np
|
|
@@ -126,13 +163,17 @@ def calculate_similarity(image1, image2):
|
|
| 126 |
else:
|
| 127 |
return "无法检测到人脸或计算相似度"
|
| 128 |
|
|
|
|
|
|
|
|
|
|
| 129 |
# 创建Gradio界面
|
| 130 |
iface = gr.Interface(
|
| 131 |
fn=calculate_similarity,
|
| 132 |
inputs=[gr.Image(type="pil"), gr.Image(type="pil")],
|
| 133 |
outputs="text",
|
| 134 |
title="图片相似度计算",
|
| 135 |
-
description="上传两张图片,计算它们的相似度。"
|
|
|
|
| 136 |
)
|
| 137 |
|
| 138 |
# 启动Gradio应用
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from datasets import load_dataset
|
| 3 |
+
import uuid
|
| 4 |
+
|
| 5 |
+
# 定义保存路径
|
| 6 |
+
save_path = "./examples/xiangxiang_man"
|
| 7 |
+
|
| 8 |
+
# 清空目标路径(如果存在)
|
| 9 |
+
if os.path.exists(save_path):
|
| 10 |
+
for file_name in os.listdir(save_path):
|
| 11 |
+
file_path = os.path.join(save_path, file_name)
|
| 12 |
+
if os.path.isfile(file_path):
|
| 13 |
+
os.remove(file_path)
|
| 14 |
+
print(f"Cleared existing files in {save_path}")
|
| 15 |
+
else:
|
| 16 |
+
os.makedirs(save_path, exist_ok=True)
|
| 17 |
+
print(f"Created directory: {save_path}")
|
| 18 |
+
|
| 19 |
+
# 加载数据集
|
| 20 |
+
dataset = load_dataset("svjack/Prince_Xiang_iclight_v2")
|
| 21 |
+
|
| 22 |
+
# 遍历数据集并保存图片
|
| 23 |
+
for example in dataset["train"]:
|
| 24 |
+
# 获取图片数据
|
| 25 |
+
image = example["image"]
|
| 26 |
+
|
| 27 |
+
# 生成唯一的文件名(使用 uuid)
|
| 28 |
+
file_name = f"{uuid.uuid4()}.png"
|
| 29 |
+
file_path = os.path.join(save_path, file_name)
|
| 30 |
+
|
| 31 |
+
# 保存图片
|
| 32 |
+
image.save(file_path)
|
| 33 |
+
print(f"Saved {file_path}")
|
| 34 |
+
|
| 35 |
+
print("All images have been saved.")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
from huggingface_hub import snapshot_download
|
| 39 |
from insightface.app import FaceAnalysis
|
| 40 |
import numpy as np
|
|
|
|
| 163 |
else:
|
| 164 |
return "无法检测到人脸或计算相似度"
|
| 165 |
|
| 166 |
+
import pathlib
|
| 167 |
+
im_l = list(map(str ,pathlib.Path("./examples/xiangxiang_man").rglob("*.png")))
|
| 168 |
+
|
| 169 |
# 创建Gradio界面
|
| 170 |
iface = gr.Interface(
|
| 171 |
fn=calculate_similarity,
|
| 172 |
inputs=[gr.Image(type="pil"), gr.Image(type="pil")],
|
| 173 |
outputs="text",
|
| 174 |
title="图片相似度计算",
|
| 175 |
+
description="上传两张图片,计算它们的相似度。",
|
| 176 |
+
examples = [[im_l[0], im_l[1]], [im_l[1], im_l[2]]],
|
| 177 |
)
|
| 178 |
|
| 179 |
# 启动Gradio应用
|