Upload run_abd.py
Browse files- run_abd.py +73 -0
run_abd.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#### huggingface-cli download svjack/Genshin-Impact-Portrait-with-Tags-Filtered-IID-Gender-SP --include "genshin_impact_ALBEDO_images_and_texts/*" --local-dir .
|
2 |
+
|
3 |
+
#### mv genshin_impact_ALBEDO_oil_painting_and_texts genshin_impact_ALBEDO_hidiffusion_images_and_texts
|
4 |
+
|
5 |
+
import os
|
6 |
+
from tqdm import tqdm
|
7 |
+
from gradio_client import Client, handle_file
|
8 |
+
from PIL import Image
|
9 |
+
from shutil import copy2
|
10 |
+
|
11 |
+
# 初始化客户端
|
12 |
+
client = Client("http://localhost:7860")
|
13 |
+
|
14 |
+
# 输入和输出文件夹路径
|
15 |
+
input_dir = "genshin_impact_ALBEDO_images_and_texts"
|
16 |
+
output_dir = "genshin_impact_ALBEDO_oil_painting_and_texts"
|
17 |
+
|
18 |
+
# 创建输出文件夹(如果不存在)
|
19 |
+
os.makedirs(output_dir, exist_ok=True)
|
20 |
+
|
21 |
+
# 获取所有.png文件
|
22 |
+
png_files = [f for f in os.listdir(input_dir) if f.endswith('.png')]
|
23 |
+
|
24 |
+
# 遍历每个.png文件
|
25 |
+
for png_file in tqdm(png_files, desc="Processing images"):
|
26 |
+
# 获取对应的.txt文件名
|
27 |
+
base_name = os.path.splitext(png_file)[0]
|
28 |
+
txt_file = base_name + ".txt"
|
29 |
+
|
30 |
+
# 检查.txt文件是否存在
|
31 |
+
txt_path = os.path.join(input_dir, txt_file)
|
32 |
+
if not os.path.exists(txt_path):
|
33 |
+
print(f"Warning: No corresponding .txt file found for {png_file}")
|
34 |
+
continue
|
35 |
+
|
36 |
+
# 读取.txt文件内容并修改prompt
|
37 |
+
with open(txt_path, 'r', encoding='utf-8') as f:
|
38 |
+
prompt = f.read().replace(
|
39 |
+
"In this digital anime-style drawing,",
|
40 |
+
"In this realistic personal drawing,"
|
41 |
+
)
|
42 |
+
|
43 |
+
# 调用API
|
44 |
+
result = client.predict(
|
45 |
+
input_image=handle_file(os.path.join(input_dir, png_file)),
|
46 |
+
prompt=prompt,
|
47 |
+
negative_prompt="blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
48 |
+
seed=2718545171199645000,
|
49 |
+
guidance_scale=8.5,
|
50 |
+
scale=2,
|
51 |
+
controlnet_conditioning_scale=0.5,
|
52 |
+
strength=1,
|
53 |
+
controlnet_start=0,
|
54 |
+
controlnet_end=1,
|
55 |
+
guassian_sigma=2,
|
56 |
+
intensity_threshold=3,
|
57 |
+
api_name="/predict"
|
58 |
+
)
|
59 |
+
|
60 |
+
# 获取生成的图像路径
|
61 |
+
generated_image_path = result[-1][1]
|
62 |
+
|
63 |
+
# 使用PIL打开图像并保存到输出文件夹
|
64 |
+
output_image_path = os.path.join(output_dir, png_file)
|
65 |
+
with Image.open(generated_image_path) as img:
|
66 |
+
img.save(output_image_path)
|
67 |
+
|
68 |
+
# 保存修改后的prompt到.txt文件
|
69 |
+
output_txt_path = os.path.join(output_dir, txt_file)
|
70 |
+
with open(output_txt_path, 'w', encoding='utf-8') as f:
|
71 |
+
f.write(prompt)
|
72 |
+
|
73 |
+
print("Processing completed!")
|