diff --git a/.gitattributes b/.gitattributes index 284f4123210239b287335cf413d0f5274cf8c4cc..f6b1f326ca4ab7cf0c8798856f8fe0020ff82d58 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,5 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text -.png filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text diff --git a/6362d0d231b95b212b19838f131bf733.jpg b/6362d0d231b95b212b19838f131bf733.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2b33d3c5c1a392e90f37523981a0cd0437dd19d2 Binary files /dev/null and b/6362d0d231b95b212b19838f131bf733.jpg differ diff --git a/__pycache__/database.cpython-310.pyc b/__pycache__/database.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..63c573e5729e16bd0ff7b939a779905335d60884 Binary files /dev/null and b/__pycache__/database.cpython-310.pyc differ diff --git a/__pycache__/database.cpython-38.pyc b/__pycache__/database.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..755dfd530275934cf8b25840262752d5ace7d68f Binary files /dev/null and b/__pycache__/database.cpython-38.pyc differ diff --git a/__pycache__/generate_image_webui.cpython-310.pyc b/__pycache__/generate_image_webui.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..175f34f15ddbd0eedac3b03cb34a4466fa2aba40 Binary files /dev/null and b/__pycache__/generate_image_webui.cpython-310.pyc differ diff --git a/__pycache__/generate_image_webui.cpython-38.pyc b/__pycache__/generate_image_webui.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..32fe7dc8750909ceb4b5e9d8b2bcb60c20e07a45 Binary files /dev/null and b/__pycache__/generate_image_webui.cpython-38.pyc differ diff --git a/database.py b/database.py new file mode 100644 index 0000000000000000000000000000000000000000..7db266cebbb107a99f1062414d28909c7c25e82e --- /dev/null +++ b/database.py @@ -0,0 +1,41 @@ +import sqlite3 +import os +def init_database(): + # 连接到 SQLite 数据库(如果数据库不存在,则会自动创建) + conn = sqlite3.connect('models.db') + + # 创建一个游标对象 + cursor = conn.cursor() + + # 创建模型信息表 + cursor.execute(''' + CREATE TABLE IF NOT EXISTS models ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + draw_count INTEGER DEFAULT 0, + win_count INTEGER DEFAULT 0, + tie_count INTEGER DEFAULT 0, + total_score REAL DEFAULT NULL + ) + ''') + + # 获取 images 文件夹下的子文件夹名 + image_folder = 'images' + model_names = [name for name in os.listdir(image_folder) if os.path.isdir(os.path.join(image_folder, name))] + + # 插入模型数据 + for name in model_names: + cursor.execute(''' + SELECT COUNT(*) FROM models WHERE name = ? + ''', (name,)) + if cursor.fetchone()[0] == 0: + cursor.execute(''' + INSERT INTO models (name, draw_count, win_count, tie_count, total_score) + VALUES (?, 0, 0, 0, NULL) + ''', (name,)) + + # 提交事务 + conn.commit() + + # 关闭连接 + conn.close() diff --git a/generate_image_webui.py b/generate_image_webui.py new file mode 100644 index 0000000000000000000000000000000000000000..4b434c100d032be3c01d8151441387c55da236ad --- /dev/null +++ b/generate_image_webui.py @@ -0,0 +1,75 @@ +import requests +import json +import os +import base64 +import io +import cv2 +from PIL import Image +import hashlib +from PIL import PngImagePlugin + +model_names=["checkpoint-e8_s253312.safetensors","noobaiXLNAIXL_epsilonPred075.safetensors"] + +# 自动在images文件夹下生成对应名字的子文件夹 +for model_name in model_names: + model_folder = f'images/{model_name}' + if not os.path.exists(model_folder): + os.makedirs(model_folder) + +def generate_filename(input_string): + # 使用 SHA-256 哈希函数 + hash_object = hashlib.sha256(input_string.encode()) + # 获取哈希值的十六进制表示 + hex_dig = hash_object.hexdigest() + # 截取前 32 个字符作为文件名 + filename = hex_dig[:32] + return filename +def generate_image_webui(url, prompt, model, steps=20, width=1024, height=1536, clip_skip=1): + set_model_payload={"sd_model_checkpoint": f"{model}"} + payload = { + "prompt": prompt, + "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", + "steps": steps, + "width": width, + "height": height, + "cfg_scale": 7, + "sampler_index": "Euler a", + "override_settings": { + "CLIP_stop_at_last_layers": clip_skip + } + } + #设置模型名称 + newurl=f"{url}/sdapi/v1/options" + setmodel = requests.post(url=newurl, json=set_model_payload) + print("模型已设置为", model) + #生成图像 + filename = generate_filename(prompt) + newurl = f"{url}/sdapi/v1/txt2img" + payload["prompt"] = prompt + print(f"开始生成:{filename}") + response = requests.post(url=newurl, json=payload) + + + if response.status_code == 200: + print("Success") + r = response.json() + info = json.loads(r['info']) # 将 info 转换为字典 + print(info['infotexts'][0]) + image_data = base64.b64decode(r['images'][0]) + image = Image.open(io.BytesIO(image_data)) + pnginfo = PngImagePlugin.PngInfo() + pnginfo.add_text("parameters", info['infotexts'][0]) + #如果已经存在同名文件,将新的文件名加上_1,_2等类似后缀 + if os.path.exists(f'images/{model}/{filename}.png'): + i = 1 + while os.path.exists(f'images/{model}/{filename}_{i}.png'): + i += 1 + filename = f"{filename}_{i}" + image.save(f'images/{model}/{filename}.png', pnginfo=pnginfo) + print("图像文件已保存至", f'images/{model}/{filename}.png') + return image + else: + print(f"Error: {response.status_code}") + return None + + diff --git a/image_read.py b/image_read.py new file mode 100644 index 0000000000000000000000000000000000000000..b7d391e720619f85c05749f734918868420b70ec --- /dev/null +++ b/image_read.py @@ -0,0 +1,27 @@ +from PIL import Image +from PIL.PngImagePlugin import PngImageFile + +def get_png_parameters(file_path): + # 打开 PNG 文件 + with Image.open(file_path) as img: + # 确保图像是 PNG 格式 + if not isinstance(img, PngImageFile): + raise ValueError("文件不是 PNG 格式") + + # 获取 PNG 文件的元数据 + metadata = img.info + + # 提取并返回 'parameters' 内容 + parameters = metadata.get('parameters', None) + + # 只保留 'parameters' 内容 + if parameters: + parameters = parameters.split('Negative prompt:')[0].strip() + + return parameters + +# 示例使用 +if __name__ == '__main__': + file_path = 'images/checkpoint-e8_s253312.safetensors/5d8e8e1c.png' + parameters = get_png_parameters(file_path) + print(parameters) \ No newline at end of file diff --git a/images/checkpoint-e3_s178000.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png b/images/checkpoint-e3_s178000.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png new file mode 100644 index 0000000000000000000000000000000000000000..d948a4354f8247bc98743a9d2f2a2ba12853158f --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0992ad29592bad4ca1e8e62dfe85162827f1416cdd2eb41fc4f98158e500b1e2 +size 2083285 diff --git a/images/checkpoint-e3_s178000.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png b/images/checkpoint-e3_s178000.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png new file mode 100644 index 0000000000000000000000000000000000000000..68c6a93083b28e12d0d8c650b78a48ca2df4a9a0 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:051c6ad7209de2c07b42c21ca05487609c0f6f652d0dfb343affc8688b9e1076 +size 1778098 diff --git a/images/checkpoint-e3_s178000.safetensors/2c63e58864bfa54dc23a8609b36322c4.png b/images/checkpoint-e3_s178000.safetensors/2c63e58864bfa54dc23a8609b36322c4.png new file mode 100644 index 0000000000000000000000000000000000000000..ee2f5987b89078228630e34329516d3c41ad4c3e --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/2c63e58864bfa54dc23a8609b36322c4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2567413f3770f850994c9117d05a4f0f8852d04c362ee4643f3b38e8818a497b +size 1637881 diff --git a/images/checkpoint-e3_s178000.safetensors/366b46257c14096c36db92ddd6a76bdf.png b/images/checkpoint-e3_s178000.safetensors/366b46257c14096c36db92ddd6a76bdf.png new file mode 100644 index 0000000000000000000000000000000000000000..9f8b3927ee08a1b6afffa5585d53264277fde929 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/366b46257c14096c36db92ddd6a76bdf.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0790d27dd01bbb7179b3885d4e81e66583be854bf14aa49b9f4a33714f670bfa +size 2168559 diff --git a/images/checkpoint-e3_s178000.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png b/images/checkpoint-e3_s178000.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png new file mode 100644 index 0000000000000000000000000000000000000000..b40cd6fdba78000aec22ffd1d2b4cabdfa1d7589 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4359ad18b999597062c9fddca1e9a851b55bb9406d8bbbc9168d9175a84b1f9d +size 827504 diff --git a/images/checkpoint-e3_s178000.safetensors/3d94ac65e75eb429fca1fb3473647e52.png b/images/checkpoint-e3_s178000.safetensors/3d94ac65e75eb429fca1fb3473647e52.png new file mode 100644 index 0000000000000000000000000000000000000000..6301d1fc41343dfb1103246cb24a7f355a53fc63 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/3d94ac65e75eb429fca1fb3473647e52.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bf3b628731e53adffe0fa6145e5f52f6912636b9af70882ed44012f75ec5bf7 +size 2002076 diff --git a/images/checkpoint-e3_s178000.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png b/images/checkpoint-e3_s178000.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png new file mode 100644 index 0000000000000000000000000000000000000000..c890e0be713fcaabda046bf764c858f2ce60d8f3 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46115cc4524999ed6f94b9297f0ed3aa40cf18e5a5b52c2452ac3312f84c3398 +size 1792841 diff --git a/images/checkpoint-e3_s178000.safetensors/4ea939d42fb9d558a389f299ab9cb221.png b/images/checkpoint-e3_s178000.safetensors/4ea939d42fb9d558a389f299ab9cb221.png new file mode 100644 index 0000000000000000000000000000000000000000..09a3d9a1219dcbec0a6df50e727d934f63c2c567 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/4ea939d42fb9d558a389f299ab9cb221.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48fb48facbb641af67a06b9d74f5e0b299cf04ecf178dfbfc2162ecd3fa4e12e +size 1763319 diff --git a/images/checkpoint-e3_s178000.safetensors/75d49b5d063e0e0648178a57ca4409ae.png b/images/checkpoint-e3_s178000.safetensors/75d49b5d063e0e0648178a57ca4409ae.png new file mode 100644 index 0000000000000000000000000000000000000000..79020873df0d37f42db94a7ca31f3b2944dec7c3 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/75d49b5d063e0e0648178a57ca4409ae.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66b9a98ea05f19cab9deb9fee591c66956abcdc78c6bddb3e0390413fb3618b1 +size 2457830 diff --git a/images/checkpoint-e3_s178000.safetensors/99554d0e65d4c16120056e43a945af7f.png b/images/checkpoint-e3_s178000.safetensors/99554d0e65d4c16120056e43a945af7f.png new file mode 100644 index 0000000000000000000000000000000000000000..9f96cd54ad7eecfa5ac03de06a5d9865cce9379f --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/99554d0e65d4c16120056e43a945af7f.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff2f8b9bc4cda654b283a070f0aa2642909733f288c53b5f41c87b88e82361ab +size 863040 diff --git a/images/checkpoint-e3_s178000.safetensors/a4fc2834663fbec34ad163b77997f46b.png b/images/checkpoint-e3_s178000.safetensors/a4fc2834663fbec34ad163b77997f46b.png new file mode 100644 index 0000000000000000000000000000000000000000..20610befcdead635be9e4de21699c22bbb108983 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/a4fc2834663fbec34ad163b77997f46b.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6bcd196b2b11c0aa22960d429957943c8312b9a338151247076ca77fbf76efb0 +size 2478555 diff --git a/images/checkpoint-e3_s178000.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png b/images/checkpoint-e3_s178000.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png new file mode 100644 index 0000000000000000000000000000000000000000..4c3d367a384e704ac8cce5d16760c16af3bfa6ad --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46b68fb350bf40b5e48351e2ec3d597761863c666a37322229b0dd76fa3dba12 +size 1707888 diff --git a/images/checkpoint-e3_s178000.safetensors/a968c1543d369546277d7b87d6a2375f.png b/images/checkpoint-e3_s178000.safetensors/a968c1543d369546277d7b87d6a2375f.png new file mode 100644 index 0000000000000000000000000000000000000000..aa7045f459a73acafdd1815746e10f73c5cd7975 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/a968c1543d369546277d7b87d6a2375f.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d03d1b3e522fdb5f407181dda8366b6b6dd3e2355a5484cc0024a27bf37a8881 +size 1611242 diff --git a/images/checkpoint-e3_s178000.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png b/images/checkpoint-e3_s178000.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png new file mode 100644 index 0000000000000000000000000000000000000000..cf131f4ca29b20f0d7aca071ce4f59c16f5ef679 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ab85df8d4b5accf86c66be134523880b2b59b1228dc2c5e016e73acc83f9496 +size 2237913 diff --git a/images/checkpoint-e3_s178000.safetensors/b153c9e18832752a3e3fc1afefca0ace.png b/images/checkpoint-e3_s178000.safetensors/b153c9e18832752a3e3fc1afefca0ace.png new file mode 100644 index 0000000000000000000000000000000000000000..d65d8e045cf2952e146830c5cb1ab460aab77133 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/b153c9e18832752a3e3fc1afefca0ace.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15a4517e9b109c75787b92eb97e2d2f834f34c0f197f7be4711ca49f7b324ae8 +size 1732187 diff --git a/images/checkpoint-e3_s178000.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png b/images/checkpoint-e3_s178000.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png new file mode 100644 index 0000000000000000000000000000000000000000..669a0610fbe746d9f4a8c37dc9ae21df844311c2 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c1429120db455255ff9ac72b95a84f4608a0efe6ec709c27654b72e9b93c3d6 +size 1641188 diff --git a/images/checkpoint-e3_s178000.safetensors/c201d076b476604c5cd6abbc72035bae.png b/images/checkpoint-e3_s178000.safetensors/c201d076b476604c5cd6abbc72035bae.png new file mode 100644 index 0000000000000000000000000000000000000000..3488c6745c6743112427570f744ec3355ee73f72 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/c201d076b476604c5cd6abbc72035bae.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:322918eed417a62e362aacd2c20564a9a111b05b95fd341375692a3ff5f511e1 +size 974986 diff --git a/images/checkpoint-e3_s178000.safetensors/ee70fcce134fb024e4121466dff844e5.png b/images/checkpoint-e3_s178000.safetensors/ee70fcce134fb024e4121466dff844e5.png new file mode 100644 index 0000000000000000000000000000000000000000..7d27d27247540355c4b408d6430c0dbc367ead45 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/ee70fcce134fb024e4121466dff844e5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5868dd75865be60dd609b0a76d1f1f8e862a06de24b3fc12fe36ad330105691b +size 1686854 diff --git a/images/checkpoint-e3_s178000.safetensors/fa277271ce293bd02a1acbef4025413e.png b/images/checkpoint-e3_s178000.safetensors/fa277271ce293bd02a1acbef4025413e.png new file mode 100644 index 0000000000000000000000000000000000000000..9e93e8723551ff503c46b3f88f7d9a3ae3878651 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/fa277271ce293bd02a1acbef4025413e.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8b826b62349380aec2517d671b06fd4ced9a2bdb384c6d56f26d0eb8edbf8c4 +size 1965292 diff --git a/images/checkpoint-e3_s178000.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png b/images/checkpoint-e3_s178000.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png new file mode 100644 index 0000000000000000000000000000000000000000..fbdd182da5c0a9131b36afb671d919f343695ec9 --- /dev/null +++ b/images/checkpoint-e3_s178000.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1aab167d827a6f19cc2e68692f1648feefd8c986c779936b652291c5861a57b +size 1192567 diff --git a/images/checkpoint-e8_s253312.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png b/images/checkpoint-e8_s253312.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png new file mode 100644 index 0000000000000000000000000000000000000000..414471d2a959fb7dcadefa9b1b92572bb25db9a1 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/0035cb1cb75fc8b9f0c5817e38d6047d.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e6b90fb247121172d1bdddab567ec2d2c24d4e8045d2b239c849ba61e638fa0 +size 1998456 diff --git a/images/checkpoint-e8_s253312.safetensors/2c63e58864bfa54dc23a8609b36322c4.png b/images/checkpoint-e8_s253312.safetensors/2c63e58864bfa54dc23a8609b36322c4.png new file mode 100644 index 0000000000000000000000000000000000000000..8841ab0deaa2b71a44f628cc179362262ecc1c6c --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/2c63e58864bfa54dc23a8609b36322c4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:405738979daa281d6ac97e9ebece2d9a9da494f0deeaffe39762dd18a59d17fd +size 1558553 diff --git a/images/checkpoint-e8_s253312.safetensors/366b46257c14096c36db92ddd6a76bdf.png b/images/checkpoint-e8_s253312.safetensors/366b46257c14096c36db92ddd6a76bdf.png new file mode 100644 index 0000000000000000000000000000000000000000..2b28681ef2d59c27d59bb1f6489adee5bb6ffb4a --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/366b46257c14096c36db92ddd6a76bdf.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:990eb5c8ccefbad94c6a30b84263ac00f2a84668db7f5ebd8d17fe1cafb5b980 +size 2231643 diff --git a/images/checkpoint-e8_s253312.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png b/images/checkpoint-e8_s253312.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png new file mode 100644 index 0000000000000000000000000000000000000000..1965177e6e106ee0d675f75d5d2622b7bf637d3e --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/3a94fb5ad2289395ec93f3fd6fa8c3b5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b01b05686696a011306a51d7168e797baab33f2811554d25f45e794463293f3c +size 1164561 diff --git a/images/checkpoint-e8_s253312.safetensors/3d94ac65e75eb429fca1fb3473647e52.png b/images/checkpoint-e8_s253312.safetensors/3d94ac65e75eb429fca1fb3473647e52.png new file mode 100644 index 0000000000000000000000000000000000000000..c50ea09a4dae60d0c9314c5670607a540ba4b3cc --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/3d94ac65e75eb429fca1fb3473647e52.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:348f7e38f4c595bedb27e1de24ba617531a466df0c5b05893c58bc49dd6c1d1c +size 2065643 diff --git a/images/checkpoint-e8_s253312.safetensors/4a1ce410d430f11c606db83711320fa8.png b/images/checkpoint-e8_s253312.safetensors/4a1ce410d430f11c606db83711320fa8.png new file mode 100644 index 0000000000000000000000000000000000000000..4f6d407a590e534b7d05d1f5dafb894aa20d5d59 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/4a1ce410d430f11c606db83711320fa8.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6decec7b5f7665848b2e5bb6cf788c25d64a529d1c7e18d0bb9c61f68bcab0ac +size 1959615 diff --git a/images/checkpoint-e8_s253312.safetensors/4ea939d42fb9d558a389f299ab9cb221.png b/images/checkpoint-e8_s253312.safetensors/4ea939d42fb9d558a389f299ab9cb221.png new file mode 100644 index 0000000000000000000000000000000000000000..3d0fd6894af7862abe4094f5b6b15a88adaa8121 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/4ea939d42fb9d558a389f299ab9cb221.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:128b87849c3b50055ff7ac2924dae7d69dcdc6a2710f667840e92bfc6ca5a364 +size 1788264 diff --git a/images/checkpoint-e8_s253312.safetensors/75d49b5d063e0e0648178a57ca4409ae.png b/images/checkpoint-e8_s253312.safetensors/75d49b5d063e0e0648178a57ca4409ae.png new file mode 100644 index 0000000000000000000000000000000000000000..50c73d1c5e7a12d55f24990b1fe680547c73afc0 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/75d49b5d063e0e0648178a57ca4409ae.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62b55fe21f030835b452f38e992028ac4d74d7ca0a08f436dc6a73d577c815d7 +size 2365628 diff --git a/images/checkpoint-e8_s253312.safetensors/99554d0e65d4c16120056e43a945af7f.png b/images/checkpoint-e8_s253312.safetensors/99554d0e65d4c16120056e43a945af7f.png new file mode 100644 index 0000000000000000000000000000000000000000..0dd647d73cfc578b7c0fdeac8f6a2f747b77de5d --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/99554d0e65d4c16120056e43a945af7f.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77f96434c3b9632dfc2b5e7b6cb27bbee5aad43f9ca27ee8a8572c284a32222a +size 1140850 diff --git a/images/checkpoint-e8_s253312.safetensors/a4fc2834663fbec34ad163b77997f46b.png b/images/checkpoint-e8_s253312.safetensors/a4fc2834663fbec34ad163b77997f46b.png new file mode 100644 index 0000000000000000000000000000000000000000..d626c323436926a8016906da12b21323549beb0a --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/a4fc2834663fbec34ad163b77997f46b.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ae75a9b38641954acdcbd8c29c15bd795591aa44866a85991c11d5adb7385b7 +size 2667653 diff --git a/images/checkpoint-e8_s253312.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png b/images/checkpoint-e8_s253312.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png new file mode 100644 index 0000000000000000000000000000000000000000..59b6f960ca41dbfb9339fbf02c1ddff112ee3584 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/a761da8e3807e4f9a9257f6c420c9af1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee94bb610afe5aee743f5666ee2a7906fcecc17203494eaff3b88232975b769d +size 1709921 diff --git a/images/checkpoint-e8_s253312.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png b/images/checkpoint-e8_s253312.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png new file mode 100644 index 0000000000000000000000000000000000000000..c599efa16e5ceefd708fb4ed31bb709f7c13e93d --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/af7c0eadfbe94807cf22a04a4f31f7c2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8204b1fb3802b5b77c7b620dc3a622bf8d30653d9160699ddd2b3030ee916f5 +size 2328417 diff --git a/images/checkpoint-e8_s253312.safetensors/b153c9e18832752a3e3fc1afefca0ace.png b/images/checkpoint-e8_s253312.safetensors/b153c9e18832752a3e3fc1afefca0ace.png new file mode 100644 index 0000000000000000000000000000000000000000..378ff0ad9021eb3f344804454bbbeb8dabdd84f5 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/b153c9e18832752a3e3fc1afefca0ace.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2aa64c8a997e6c6382571dd840a946ce47fa02659aeca687b536e1e9e6233698 +size 1878383 diff --git a/images/checkpoint-e8_s253312.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png b/images/checkpoint-e8_s253312.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png new file mode 100644 index 0000000000000000000000000000000000000000..151e51c85540a0e6297e9c9c0aea006bbfb1cab1 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/b437aa8e9ce8d7528afd4c2d2909cf2c.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae44b4e11c3901be515de318ce65e72abcd683502fe818746539c5cc830d0e43 +size 1493656 diff --git a/images/checkpoint-e8_s253312.safetensors/e5a823186a04babb324069a485911133.png b/images/checkpoint-e8_s253312.safetensors/e5a823186a04babb324069a485911133.png new file mode 100644 index 0000000000000000000000000000000000000000..24fefc5c062293e6e6b7c34b3fd2bf78bb98a672 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/e5a823186a04babb324069a485911133.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f9e9ef1d15bd2f5c524a2230360d53deb2fb828f0a9d909b765023291c880fd +size 1837834 diff --git a/images/checkpoint-e8_s253312.safetensors/ee70fcce134fb024e4121466dff844e5.png b/images/checkpoint-e8_s253312.safetensors/ee70fcce134fb024e4121466dff844e5.png new file mode 100644 index 0000000000000000000000000000000000000000..061bf66ede4d0e9517f5e3bca1953d0737c74870 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/ee70fcce134fb024e4121466dff844e5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70025e82329fd0dbc69f9761a2c65c6aa622ffe62cd7abb777c5b1157a29c6e0 +size 1647781 diff --git a/images/checkpoint-e8_s253312.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png b/images/checkpoint-e8_s253312.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png new file mode 100644 index 0000000000000000000000000000000000000000..716a684d546183dbedd28bd708d3ccc526a5eb33 --- /dev/null +++ b/images/checkpoint-e8_s253312.safetensors/fb8e199c44cf51adb82fd3a26f86f035.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8f95d394ed1641bab1dbb2e99f5500476a55adfb61adcc93855ce93b3e09c28 +size 1259005 diff --git a/images/noobaiXLNAIXL_epsilonPred075.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png b/images/noobaiXLNAIXL_epsilonPred075.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png new file mode 100644 index 0000000000000000000000000000000000000000..130c3ebb37b4afd2347149cb3054aad12ef8d818 --- /dev/null +++ b/images/noobaiXLNAIXL_epsilonPred075.safetensors/1cebda45c6851907092a5eb1a7d8dd66.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3483ad95192f00f5a8c97a74d686622697c53e2a4104c027fbbaaa422111163 +size 1686535 diff --git a/images/noobaiXLNAIXL_epsilonPred075.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png b/images/noobaiXLNAIXL_epsilonPred075.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png new file mode 100644 index 0000000000000000000000000000000000000000..c8b63b72c6fea7d6034ca23d981d5baf755c106e --- /dev/null +++ b/images/noobaiXLNAIXL_epsilonPred075.safetensors/42f8b8b4ddfa6c47cb12a30f21d96251.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c25aaeac9436231b4dfc732414a69cf63a2f8e70b99e9a4b78526d0b317a043c +size 2049098 diff --git a/images/noobaiXLNAIXL_epsilonPred075.safetensors/4a1ce410d430f11c606db83711320fa8.png b/images/noobaiXLNAIXL_epsilonPred075.safetensors/4a1ce410d430f11c606db83711320fa8.png new file mode 100644 index 0000000000000000000000000000000000000000..346b23685d2618112e9d8e644e98de5b2d071f33 --- /dev/null +++ b/images/noobaiXLNAIXL_epsilonPred075.safetensors/4a1ce410d430f11c606db83711320fa8.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:066306971e892f6bd6465b9a8ff6a14b4a8dd8c86b8ebe47ab36546fb92d0065 +size 2039307 diff --git a/images/noobaiXLNAIXL_epsilonPred075.safetensors/a968c1543d369546277d7b87d6a2375f.png b/images/noobaiXLNAIXL_epsilonPred075.safetensors/a968c1543d369546277d7b87d6a2375f.png new file mode 100644 index 0000000000000000000000000000000000000000..a48525dd0b5e3b4eaf12dd187b2979ceddcfe17a --- /dev/null +++ b/images/noobaiXLNAIXL_epsilonPred075.safetensors/a968c1543d369546277d7b87d6a2375f.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c3e6c05133cc0133a4f1df9916b76453bce872ff1a861c6662a0effaf1528f1 +size 1570232 diff --git a/images/noobaiXLNAIXL_epsilonPred075.safetensors/e5a823186a04babb324069a485911133.png b/images/noobaiXLNAIXL_epsilonPred075.safetensors/e5a823186a04babb324069a485911133.png new file mode 100644 index 0000000000000000000000000000000000000000..51bb4fbb9c0765708056600da3a3f13daab9eb7c --- /dev/null +++ b/images/noobaiXLNAIXL_epsilonPred075.safetensors/e5a823186a04babb324069a485911133.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bcb9acf39b5854ce1b9752311913b11c2d0b49324771fc6c91ca7cf022420b94 +size 1977978 diff --git a/images/noobaiXLNAIXL_epsilonPred075.safetensors/fa277271ce293bd02a1acbef4025413e.png b/images/noobaiXLNAIXL_epsilonPred075.safetensors/fa277271ce293bd02a1acbef4025413e.png new file mode 100644 index 0000000000000000000000000000000000000000..889fca8473d8a9d2491203820d00bedefd4f6b9b --- /dev/null +++ b/images/noobaiXLNAIXL_epsilonPred075.safetensors/fa277271ce293bd02a1acbef4025413e.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2375ef02504cd8cd255507a5b935205beff4abab5224279544fa21fc9875a3ba +size 2024537 diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..66ce1b1abf2770d879cbaafdd633ec838dd495b1 --- /dev/null +++ b/main.py @@ -0,0 +1,295 @@ +import gradio as gr +import random +import sqlite3 +import os +import time +from PIL import Image +from PIL.PngImagePlugin import PngImageFile +from generate_image_webui import generate_image_webui +from database import init_database + +# 初始化数据库 +init_database() + +# 模型列表 +models = [name for name in os.listdir('images') if os.path.isdir(os.path.join('images', name))] + + +# 初始化数据库 +init_database() + +# 模型列表 +models = [name for name in os.listdir('images') if os.path.isdir(os.path.join('images', name))] + +# 提取图像中的 prompt + + +def get_png_parameters(file_path): + with Image.open(file_path) as img: + if not isinstance(img, PngImageFile): + raise ValueError("文件不是 PNG 格式") + metadata = img.info + parameters = metadata.get('parameters', None) + if parameters: + prompt = parameters.split('Negative prompt:')[0].strip() + return prompt + else: + return None + + +def generate_images(prompt, width, height): + selected_models = random.sample(models, 2) + model1, model2 = selected_models[0], selected_models[1] + image1 = generate_image_webui("http://192.168.31.142:7860", prompt, model1, width=width, height=height) + image2 = generate_image_webui("http://192.168.31.142:7860", prompt, model2, width=width, height=height) + return image1, image2, model1, model2 + + +def select_images_from_history(model1, model2): + image_folder1 = os.path.join('images', model1) + image_folder2 = os.path.join('images', model2) + filenames1 = set(f for f in os.listdir(image_folder1) if os.path.isfile(os.path.join(image_folder1, f))) + filenames2 = set(f for f in os.listdir(image_folder2) if os.path.isfile(os.path.join(image_folder2, f))) + common_filenames = filenames1.intersection(filenames2) + if not common_filenames: + return None, None, None, None, "没有找到可供比较的历史图像,请生成更多图像。", None + filename = random.choice(list(common_filenames)) + image1_path = os.path.join('images', model1, filename) + image2_path = os.path.join('images', model2, filename) + image1 = Image.open(image1_path) + image2 = Image.open(image2_path) + prompt = get_png_parameters(image1_path) + return image1, image2, model1, model2, "", prompt + + +def update_database(choice, model1, model2): + conn = sqlite3.connect('models.db') + cursor = conn.cursor() + if choice == "模型 1": + cursor.execute('UPDATE models SET draw_count = draw_count + 1, win_count = win_count + 1 WHERE name = ?', (model1,)) + cursor.execute('UPDATE models SET draw_count = draw_count + 1 WHERE name = ?', (model2,)) + elif choice == "模型 2": + cursor.execute('UPDATE models SET draw_count = draw_count + 1, win_count = win_count + 1 WHERE name = ?', (model2,)) + cursor.execute('UPDATE models SET draw_count = draw_count + 1 WHERE name = ?', (model1,)) + elif choice == "平局": + cursor.execute('UPDATE models SET draw_count = draw_count + 1, tie_count = tie_count + 1 WHERE name = ?', (model1,)) + cursor.execute('UPDATE models SET draw_count = draw_count + 1, tie_count = tie_count + 1 WHERE name = ?', (model2,)) + elif choice == "两个都很烂": + cursor.execute('UPDATE models SET draw_count = draw_count + 1 WHERE name = ?', (model1,)) + cursor.execute('UPDATE models SET draw_count = draw_count + 1 WHERE name = ?', (model2,)) + conn.commit() + conn.close() + if choice == "模型 1": + return f"您选择了{model1}生成的图像,另一张图像由{model2}生成。结果已记录,谢谢您的参与!" + elif choice == "模型 2": + return f"您选择了{model2}生成的图像,另一张图像由{model1}生成。结果已记录,谢谢您的参与!" + elif choice == "平局": + return f"您认为这两张图像都不错。他们分别由{model1}和{model2}生成。他们将都得到小幅加分。结果已记录,谢谢您的参与!" + elif choice == "两个都很烂": + return f"您认为这两张图像都很烂。他们分别由{model1}和{model2}生成。他们不会得到加分。结果已记录,谢谢您的参与!" + + +def get_rankings(): + conn = sqlite3.connect('models.db') + cursor = conn.cursor() + cursor.execute('SELECT name, draw_count, win_count, tie_count FROM models ORDER BY win_count DESC') + data = cursor.fetchall() + conn.close() + return data + + +# 创建 Gradio 界面 +with gr.Blocks() as demo: + gr.Markdown("# SDXL 模型盲测竞技场") + + with gr.Tab("历史对比"): + with gr.Column(): + refresh_btn = gr.Button("刷新图像") + prompt_display = gr.Markdown(value="", visible=True) + with gr.Row(): + image_output1_hist = gr.Image(label="模型 1", height=350, width=250) + image_output2_hist = gr.Image(label="模型 2", height=350, width=250) + result_hist = gr.Textbox(label="提示信息", interactive=False) + with gr.Row(): + choice_btn1_hist = gr.Button("我更喜欢模型 1") + choice_btn2_hist = gr.Button("我更喜欢模型 2") + tie_btn_hist = gr.Button("两个都不错") + bad_btn_hist = gr.Button("两个都很烂") # 新增按钮 + + # 用于保存模型名称,供更新数据库时使用 + model1_name_hist = gr.State() + model2_name_hist = gr.State() + rated_hist = gr.State(True) # 初始为 True,允许首次刷新 + last_refresh_hist = gr.State(0) # 记录上次刷新时间 + + # 修改后的 on_refresh 函数 + def on_refresh(rated, last_refresh, model1, model2): + current_time = time.time() + if current_time - last_refresh < 3: + return [gr.update(), gr.update(), gr.update(), gr.update(), "刷新过于频繁,只允许每三秒刷新一次。", gr.update(), last_refresh, rated] + if not rated: + return [gr.update(), gr.update(), gr.update(), gr.update(), "请先对当前图像进行评分。", gr.update(), last_refresh, rated] + if not model1 or not model2: + selected_models = random.sample(models, 2) + model1, model2 = selected_models[0], selected_models[1] + img1, img2, model1_new, model2_new, msg, prompt = select_images_from_history(model1, model2) + if prompt: + prompt_display_value = f"**提示词(Prompt):** {prompt}" + else: + prompt_display_value = "**未在元数据中找到有效提示词**" + return [img1, img2, model1_new, model2_new, msg, prompt_display_value, current_time, False] # 将 rated_hist 重置为 False + + # 修改 refresh_btn.click 的输出列表,添加 rated_hist + refresh_btn.click( + fn=on_refresh, + inputs=[rated_hist, last_refresh_hist, model1_name_hist, model2_name_hist], + outputs=[image_output1_hist, image_output2_hist, model1_name_hist, model2_name_hist, result_hist, prompt_display, last_refresh_hist, rated_hist] + ) + + # 确保“生成模式”中的类似逻辑正确 + # on_generate 函数已经正确设置 rated_gen 为 False,确保 on_choice_gen 正确设置为 True + + # 如果需要对“生成模式”中的状态进行类似的检查,也可以进行相应的修改 + + def on_choice(choice, model1, model2, already_rated): + if already_rated: + return "您已对当前图像进行评分,重复评分无效。", already_rated + msg = update_database(choice, model1, model2) + return msg, True # 设置 rated 状态为 True + + choice_btn1_hist.click( + fn=lambda m1, m2, ar: on_choice("模型 1", m1, m2, ar), + inputs=[model1_name_hist, model2_name_hist, rated_hist], + outputs=[result_hist, rated_hist] + ) + + choice_btn2_hist.click( + fn=lambda m1, m2, ar: on_choice("模型 2", m1, m2, ar), + inputs=[model1_name_hist, model2_name_hist, rated_hist], + outputs=[result_hist, rated_hist] + ) + + tie_btn_hist.click( + fn=lambda m1, m2, ar: on_choice("平局", m1, m2, ar), + inputs=[model1_name_hist, model2_name_hist, rated_hist], + outputs=[result_hist, rated_hist] + ) + + bad_btn_hist.click( + fn=lambda m1, m2, ar: on_choice("两个都很烂", m1, m2, ar), + inputs=[model1_name_hist, model2_name_hist, rated_hist], + outputs=[result_hist, rated_hist] + ) + + with gr.Tab("生成模式"): + with gr.Row(): + prompt_input = gr.Textbox(label="请输入提示词", scale=4) + with gr.Column(scale=1): + submit_btn = gr.Button("生成图像", size="sm", variant="primary") + with gr.Row(): + resolution = gr.Radio( + choices=["832x1216", "1024x1536"], + value="832x1216", + label="分辨率", + interactive=True + ) + orientation = gr.Radio( + choices=["竖图", "横图"], + value="竖图", + label="图像方向", + interactive=True + ) + + with gr.Row(): + image_output1_gen = gr.Image(label="模型 1", height=350, width=250) + image_output2_gen = gr.Image(label="模型 2", height=350, width=250) + + result_gen = gr.Textbox(label="提示信息", interactive=False) + + with gr.Row(): + choice_btn1_gen = gr.Button("我更喜欢模型 1") + choice_btn2_gen = gr.Button("我更喜欢模型 2") + tie_btn_gen = gr.Button("两个都不错") + bad_btn_gen = gr.Button("两个都很烂") # 新增按钮 + + # 用于保存模型名称,供更新数据库时使用 + model1_name_gen = gr.State() + model2_name_gen = gr.State() + rated_gen = gr.State(True) # 初始为 True,允许首次生成 + last_generate_gen = gr.State(0) # 记录上次生成时间 + + def on_generate(prompt, resolution, orientation, rated, last_generate): + current_time = time.time() + if current_time - last_generate < 20: + return [ + gr.update(), gr.update(), gr.update(), gr.update(), + "生成过于频繁,只允许每20秒生成一次。", + rated, last_generate + ] + if not rated: + return [ + gr.update(), gr.update(), gr.update(), gr.update(), + "请先对当前图像进行评分。", + rated, last_generate + ] + width, height = map(int, resolution.split('x')) + if orientation == "横图": + width, height = height, width + img1, img2, model1, model2 = generate_images(prompt, width, height) + return [ + img1, img2, model1, model2, + "", False, current_time # 重置 rated 状态为 False + ] + + def on_choice_gen(choice, model1, model2, already_rated): + if already_rated: + return "您已对当前图像进行评分,重复评分无效。", already_rated + msg = update_database(choice, model1, model2) + return msg, True # 设置 rated 状态为 True + + submit_btn.click( + fn=on_generate, + inputs=[prompt_input, resolution, orientation, rated_gen, last_generate_gen], + outputs=[ + image_output1_gen, image_output2_gen, + model1_name_gen, model2_name_gen, + result_gen, rated_gen, last_generate_gen + ] + ) + + choice_btn1_gen.click( + fn=lambda m1, m2, ar: on_choice_gen("模型 1", m1, m2, ar), + inputs=[model1_name_gen, model2_name_gen, rated_gen], + outputs=[result_gen, rated_gen] + ) + + choice_btn2_gen.click( + fn=lambda m1, m2, ar: on_choice_gen("模型 2", m1, m2, ar), + inputs=[model1_name_gen, model2_name_gen, rated_gen], + outputs=[result_gen, rated_gen] + ) + + tie_btn_gen.click( + fn=lambda m1, m2, ar: on_choice_gen("平局", m1, m2, ar), + inputs=[model1_name_gen, model2_name_gen, rated_gen], + outputs=[result_gen, rated_gen] + ) + + bad_btn_gen.click( + fn=lambda m1, m2, ar: on_choice_gen("两个都很烂", m1, m2, ar), + inputs=[model1_name_gen, model2_name_gen, rated_gen], + outputs=[result_gen, rated_gen] + ) + + with gr.Tab("查看当前评分排行"): + rankingsData = get_rankings() + rankings = gr.Dataframe(value=rankingsData, headers=["模型名称", "对战次数", "胜利次数", "平局次数"], interactive=False) + + def refresh_rankings(): + data = get_rankings() + return data + + refresh_btn_rank = gr.Button("刷新排行") + refresh_btn_rank.click(fn=refresh_rankings, outputs=rankings) + + demo.launch(server_name="0.0.0.0", server_port=7860) diff --git a/models.db b/models.db new file mode 100644 index 0000000000000000000000000000000000000000..2813b60298e9dbc8a6737a938efc8a3d7f320d45 Binary files /dev/null and b/models.db differ