Spaces:
Runtime error
Runtime error
Initial commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +0 -1
- 6362d0d231b95b212b19838f131bf733.jpg +0 -0
- __pycache__/database.cpython-310.pyc +0 -0
- __pycache__/database.cpython-38.pyc +0 -0
- __pycache__/generate_image_webui.cpython-310.pyc +0 -0
- __pycache__/generate_image_webui.cpython-38.pyc +0 -0
- database.py +41 -0
- generate_image_webui.py +75 -0
- image_read.py +27 -0
- images/checkpoint-e3_s178000.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png +3 -0
- images/checkpoint-e3_s178000.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png +3 -0
- images/checkpoint-e3_s178000.safetensors/2c63e58864bfa54dc23a8609b36322c4.png +3 -0
- images/checkpoint-e3_s178000.safetensors/366b46257c14096c36db92ddd6a76bdf.png +3 -0
- images/checkpoint-e3_s178000.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png +3 -0
- images/checkpoint-e3_s178000.safetensors/3d94ac65e75eb429fca1fb3473647e52.png +3 -0
- images/checkpoint-e3_s178000.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png +3 -0
- images/checkpoint-e3_s178000.safetensors/4ea939d42fb9d558a389f299ab9cb221.png +3 -0
- images/checkpoint-e3_s178000.safetensors/75d49b5d063e0e0648178a57ca4409ae.png +3 -0
- images/checkpoint-e3_s178000.safetensors/99554d0e65d4c16120056e43a945af7f.png +3 -0
- images/checkpoint-e3_s178000.safetensors/a4fc2834663fbec34ad163b77997f46b.png +3 -0
- images/checkpoint-e3_s178000.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png +3 -0
- images/checkpoint-e3_s178000.safetensors/a968c1543d369546277d7b87d6a2375f.png +3 -0
- images/checkpoint-e3_s178000.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png +3 -0
- images/checkpoint-e3_s178000.safetensors/b153c9e18832752a3e3fc1afefca0ace.png +3 -0
- images/checkpoint-e3_s178000.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png +3 -0
- images/checkpoint-e3_s178000.safetensors/c201d076b476604c5cd6abbc72035bae.png +3 -0
- images/checkpoint-e3_s178000.safetensors/ee70fcce134fb024e4121466dff844e5.png +3 -0
- images/checkpoint-e3_s178000.safetensors/fa277271ce293bd02a1acbef4025413e.png +3 -0
- images/checkpoint-e3_s178000.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png +3 -0
- images/checkpoint-e8_s253312.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png +3 -0
- images/checkpoint-e8_s253312.safetensors/2c63e58864bfa54dc23a8609b36322c4.png +3 -0
- images/checkpoint-e8_s253312.safetensors/366b46257c14096c36db92ddd6a76bdf.png +3 -0
- images/checkpoint-e8_s253312.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png +3 -0
- images/checkpoint-e8_s253312.safetensors/3d94ac65e75eb429fca1fb3473647e52.png +3 -0
- images/checkpoint-e8_s253312.safetensors/4a1ce410d430f11c606db83711320fa8.png +3 -0
- images/checkpoint-e8_s253312.safetensors/4ea939d42fb9d558a389f299ab9cb221.png +3 -0
- images/checkpoint-e8_s253312.safetensors/75d49b5d063e0e0648178a57ca4409ae.png +3 -0
- images/checkpoint-e8_s253312.safetensors/99554d0e65d4c16120056e43a945af7f.png +3 -0
- images/checkpoint-e8_s253312.safetensors/a4fc2834663fbec34ad163b77997f46b.png +3 -0
- images/checkpoint-e8_s253312.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png +3 -0
- images/checkpoint-e8_s253312.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png +3 -0
- images/checkpoint-e8_s253312.safetensors/b153c9e18832752a3e3fc1afefca0ace.png +3 -0
- images/checkpoint-e8_s253312.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png +3 -0
- images/checkpoint-e8_s253312.safetensors/e5a823186a04babb324069a485911133.png +3 -0
- images/checkpoint-e8_s253312.safetensors/ee70fcce134fb024e4121466dff844e5.png +3 -0
- images/checkpoint-e8_s253312.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png +3 -0
- images/noobaiXLNAIXL_epsilonPred075.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png +3 -0
- images/noobaiXLNAIXL_epsilonPred075.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png +3 -0
- images/noobaiXLNAIXL_epsilonPred075.safetensors/4a1ce410d430f11c606db83711320fa8.png +3 -0
- images/noobaiXLNAIXL_epsilonPred075.safetensors/a968c1543d369546277d7b87d6a2375f.png +3 -0
.gitattributes
CHANGED
@@ -33,5 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
-
.png filter=lfs diff=lfs merge=lfs -text
|
37 |
*.png filter=lfs diff=lfs merge=lfs -text
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
36 |
*.png filter=lfs diff=lfs merge=lfs -text
|
6362d0d231b95b212b19838f131bf733.jpg
ADDED
__pycache__/database.cpython-310.pyc
ADDED
Binary file (1.22 kB). View file
|
|
__pycache__/database.cpython-38.pyc
ADDED
Binary file (1.24 kB). View file
|
|
__pycache__/generate_image_webui.cpython-310.pyc
ADDED
Binary file (2.5 kB). View file
|
|
__pycache__/generate_image_webui.cpython-38.pyc
ADDED
Binary file (2.5 kB). View file
|
|
database.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sqlite3
|
2 |
+
import os
|
3 |
+
def init_database():
|
4 |
+
# 连接到 SQLite 数据库(如果数据库不存在,则会自动创建)
|
5 |
+
conn = sqlite3.connect('models.db')
|
6 |
+
|
7 |
+
# 创建一个游标对象
|
8 |
+
cursor = conn.cursor()
|
9 |
+
|
10 |
+
# 创建模型信息表
|
11 |
+
cursor.execute('''
|
12 |
+
CREATE TABLE IF NOT EXISTS models (
|
13 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
14 |
+
name TEXT NOT NULL,
|
15 |
+
draw_count INTEGER DEFAULT 0,
|
16 |
+
win_count INTEGER DEFAULT 0,
|
17 |
+
tie_count INTEGER DEFAULT 0,
|
18 |
+
total_score REAL DEFAULT NULL
|
19 |
+
)
|
20 |
+
''')
|
21 |
+
|
22 |
+
# 获取 images 文件夹下的子文件夹名
|
23 |
+
image_folder = 'images'
|
24 |
+
model_names = [name for name in os.listdir(image_folder) if os.path.isdir(os.path.join(image_folder, name))]
|
25 |
+
|
26 |
+
# 插入模型数据
|
27 |
+
for name in model_names:
|
28 |
+
cursor.execute('''
|
29 |
+
SELECT COUNT(*) FROM models WHERE name = ?
|
30 |
+
''', (name,))
|
31 |
+
if cursor.fetchone()[0] == 0:
|
32 |
+
cursor.execute('''
|
33 |
+
INSERT INTO models (name, draw_count, win_count, tie_count, total_score)
|
34 |
+
VALUES (?, 0, 0, 0, NULL)
|
35 |
+
''', (name,))
|
36 |
+
|
37 |
+
# 提交事务
|
38 |
+
conn.commit()
|
39 |
+
|
40 |
+
# 关闭连接
|
41 |
+
conn.close()
|
generate_image_webui.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import base64
|
5 |
+
import io
|
6 |
+
import cv2
|
7 |
+
from PIL import Image
|
8 |
+
import hashlib
|
9 |
+
from PIL import PngImagePlugin
|
10 |
+
|
11 |
+
model_names=["checkpoint-e8_s253312.safetensors","noobaiXLNAIXL_epsilonPred075.safetensors"]
|
12 |
+
|
13 |
+
# 自动在images文件夹下生成对应名字的子文件夹
|
14 |
+
for model_name in model_names:
|
15 |
+
model_folder = f'images/{model_name}'
|
16 |
+
if not os.path.exists(model_folder):
|
17 |
+
os.makedirs(model_folder)
|
18 |
+
|
19 |
+
def generate_filename(input_string):
|
20 |
+
# 使用 SHA-256 哈希函数
|
21 |
+
hash_object = hashlib.sha256(input_string.encode())
|
22 |
+
# 获取哈希值的十六进制表示
|
23 |
+
hex_dig = hash_object.hexdigest()
|
24 |
+
# 截取前 32 个字符作为文件名
|
25 |
+
filename = hex_dig[:32]
|
26 |
+
return filename
|
27 |
+
def generate_image_webui(url, prompt, model, steps=20, width=1024, height=1536, clip_skip=1):
|
28 |
+
set_model_payload={"sd_model_checkpoint": f"{model}"}
|
29 |
+
payload = {
|
30 |
+
"prompt": prompt,
|
31 |
+
"negative_prompt": "lowres, worst quality, bad quality, bad hands, very displeasing, extra digit, fewer digits, jpeg, pregnant, artifacts, signature, username, reference, mutated, lineup, manga, comic, disembodied, turnaround, 2koma, 4koma, monster, cropped, amputee, text, bad foreshortening, what, guro, logo, bad anatomy, bad perspective, bad proportions, artistic error, anatomical nonsense, amateur, out of frame, multiple views",
|
32 |
+
"steps": steps,
|
33 |
+
"width": width,
|
34 |
+
"height": height,
|
35 |
+
"cfg_scale": 7,
|
36 |
+
"sampler_index": "Euler a",
|
37 |
+
"override_settings": {
|
38 |
+
"CLIP_stop_at_last_layers": clip_skip
|
39 |
+
}
|
40 |
+
}
|
41 |
+
#设置模型名称
|
42 |
+
newurl=f"{url}/sdapi/v1/options"
|
43 |
+
setmodel = requests.post(url=newurl, json=set_model_payload)
|
44 |
+
print("模型已设置为", model)
|
45 |
+
#生成图像
|
46 |
+
filename = generate_filename(prompt)
|
47 |
+
newurl = f"{url}/sdapi/v1/txt2img"
|
48 |
+
payload["prompt"] = prompt
|
49 |
+
print(f"开始生成:{filename}")
|
50 |
+
response = requests.post(url=newurl, json=payload)
|
51 |
+
|
52 |
+
|
53 |
+
if response.status_code == 200:
|
54 |
+
print("Success")
|
55 |
+
r = response.json()
|
56 |
+
info = json.loads(r['info']) # 将 info 转换为字典
|
57 |
+
print(info['infotexts'][0])
|
58 |
+
image_data = base64.b64decode(r['images'][0])
|
59 |
+
image = Image.open(io.BytesIO(image_data))
|
60 |
+
pnginfo = PngImagePlugin.PngInfo()
|
61 |
+
pnginfo.add_text("parameters", info['infotexts'][0])
|
62 |
+
#如果已经存在同名文件,将新的文件名加上_1,_2等类似后缀
|
63 |
+
if os.path.exists(f'images/{model}/{filename}.png'):
|
64 |
+
i = 1
|
65 |
+
while os.path.exists(f'images/{model}/{filename}_{i}.png'):
|
66 |
+
i += 1
|
67 |
+
filename = f"{filename}_{i}"
|
68 |
+
image.save(f'images/{model}/{filename}.png', pnginfo=pnginfo)
|
69 |
+
print("图像文件已保存至", f'images/{model}/{filename}.png')
|
70 |
+
return image
|
71 |
+
else:
|
72 |
+
print(f"Error: {response.status_code}")
|
73 |
+
return None
|
74 |
+
|
75 |
+
|
image_read.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
from PIL.PngImagePlugin import PngImageFile
|
3 |
+
|
4 |
+
def get_png_parameters(file_path):
|
5 |
+
# 打开 PNG 文件
|
6 |
+
with Image.open(file_path) as img:
|
7 |
+
# 确保图像是 PNG 格式
|
8 |
+
if not isinstance(img, PngImageFile):
|
9 |
+
raise ValueError("文件不是 PNG 格式")
|
10 |
+
|
11 |
+
# 获取 PNG 文件的元数据
|
12 |
+
metadata = img.info
|
13 |
+
|
14 |
+
# 提取并返回 'parameters' 内容
|
15 |
+
parameters = metadata.get('parameters', None)
|
16 |
+
|
17 |
+
# 只保留 'parameters' 内容
|
18 |
+
if parameters:
|
19 |
+
parameters = parameters.split('Negative prompt:')[0].strip()
|
20 |
+
|
21 |
+
return parameters
|
22 |
+
|
23 |
+
# 示例使用
|
24 |
+
if __name__ == '__main__':
|
25 |
+
file_path = 'images/checkpoint-e8_s253312.safetensors/5d8e8e1c.png'
|
26 |
+
parameters = get_png_parameters(file_path)
|
27 |
+
print(parameters)
|
images/checkpoint-e3_s178000.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/2c63e58864bfa54dc23a8609b36322c4.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/366b46257c14096c36db92ddd6a76bdf.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/3d94ac65e75eb429fca1fb3473647e52.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/4ea939d42fb9d558a389f299ab9cb221.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/75d49b5d063e0e0648178a57ca4409ae.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/99554d0e65d4c16120056e43a945af7f.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/a4fc2834663fbec34ad163b77997f46b.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/a968c1543d369546277d7b87d6a2375f.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/b153c9e18832752a3e3fc1afefca0ace.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/c201d076b476604c5cd6abbc72035bae.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/ee70fcce134fb024e4121466dff844e5.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/fa277271ce293bd02a1acbef4025413e.png
ADDED
Git LFS Details
|
images/checkpoint-e3_s178000.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/2c63e58864bfa54dc23a8609b36322c4.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/366b46257c14096c36db92ddd6a76bdf.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/3d94ac65e75eb429fca1fb3473647e52.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/4a1ce410d430f11c606db83711320fa8.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/4ea939d42fb9d558a389f299ab9cb221.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/75d49b5d063e0e0648178a57ca4409ae.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/99554d0e65d4c16120056e43a945af7f.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/a4fc2834663fbec34ad163b77997f46b.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/b153c9e18832752a3e3fc1afefca0ace.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/e5a823186a04babb324069a485911133.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/ee70fcce134fb024e4121466dff844e5.png
ADDED
Git LFS Details
|
images/checkpoint-e8_s253312.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png
ADDED
Git LFS Details
|
images/noobaiXLNAIXL_epsilonPred075.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png
ADDED
Git LFS Details
|
images/noobaiXLNAIXL_epsilonPred075.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png
ADDED
Git LFS Details
|
images/noobaiXLNAIXL_epsilonPred075.safetensors/4a1ce410d430f11c606db83711320fa8.png
ADDED
Git LFS Details
|
images/noobaiXLNAIXL_epsilonPred075.safetensors/a968c1543d369546277d7b87d6a2375f.png
ADDED
Git LFS Details
|