Stable Diffusion為秋葉大佬的繪世2.2.4
webUI api后臺(tái):http://127.0.0.1:7860/docs文章來源:http://www.zghlxwxcb.cn/news/detail-519400.html
數(shù)據(jù)獲取結(jié)果,python代碼在文章尾部
1girl: 0.9883618950843811, 98%
solo: 0.9468605518341064, 94%
horns: 0.9203381538391113, 92%
braid: 0.7536494731903076, 75%
brown_hair: 0.7361204624176025, 73%
sensitive: 0.7181869745254517, 71%
looking_at_viewer: 0.6558270454406738, 65%
long_hair: 0.6555134654045105, 65%
portrait: 0.5619801878929138, 56%
hair_ornament: 0.5276427268981934, 52%
lips: 0.5271897912025452, 52%
realistic: 0.47530364990234375, 47%
brown_eyes: 0.44382530450820923, 44%
fur_trim: 0.44058263301849365, 44%
red_hair: 0.4004508852958679, 40%
upper_body: 0.39194822311401367, 39%
mole: 0.35748565196990967, 35%
general: 0.2813188433647156, 28%
questionable: 0.004140794277191162, 0%
explicit: 0.0005668997764587402, 0%
使用/tagger/v1/interrogate,先使用get方法獲取model模組有十多個(gè),然后把json_data提交上去就可以了。記得把圖片轉(zhuǎn)碼為base64。本文章僅用于測(cè)試,請(qǐng)仔細(xì)閱讀api docs,model和threshold按照需求調(diào)整即可
文章來源地址http://www.zghlxwxcb.cn/news/detail-519400.html
import requests
import base64
from collections import OrderedDict
from PIL import Image
url = 'http://127.0.0.1:7860/tagger/v1/interrogate'
image_path = 'D:/code/image/6.jpg'
model = 'wd14-convnext'
threshold = 0.35
#確認(rèn)照片為上傳照片
image = Image.open(image_path)
image.show()
# 將圖片轉(zhuǎn)換為Base64字符串
with open(image_path, 'rb') as file:
image_data = file.read()
base64_image = base64.b64encode(image_data).decode('utf-8')
# 構(gòu)建請(qǐng)求體的JSON數(shù)據(jù)
data = {
"image": base64_image,
"model": model,
"threshold": threshold
}
# 發(fā)送POST請(qǐng)求
response = requests.post(url, json=data)
# 檢查響應(yīng)狀態(tài)碼
if response.status_code == 200:
json_data = response.json()
# 處理返回的JSON數(shù)據(jù)
caption_dict = json_data['caption']
sorted_items = sorted(caption_dict.items(), key=lambda x: x[1], reverse=True)
output = '\n'.join([f'{k}: {v}, {int(v * 100)}%' for k, v in sorted_items])
print(output)
else:
print('Error:', response.status_code)
print('Response body:', response.text)
到了這里,關(guān)于Stable Diffusion WebUI使用python調(diào)用WD 1.4標(biāo)簽器(tagger),獲取并處理標(biāo)簽tag權(quán)重的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!