This commit is contained in:
2025-09-04 08:49:37 +08:00
parent 1e359e8923
commit a0b2df76f4
5 changed files with 68 additions and 13 deletions

View File

@@ -23,7 +23,7 @@ class LibLibUtil:
timestamp = str(int(time.time() * 1000)) timestamp = str(int(time.time() * 1000))
signature_nonce = str(uuid.uuid4()) signature_nonce = str(uuid.uuid4())
content = '&'.join((uri, timestamp, signature_nonce)) content = '&'.join((uri, timestamp, signature_nonce))
digest = hmac.new(self.secret_key.encode(), content.encode(), sha1).digest() digest = hmac.new(self.secret_key.encode(), content.encode(), sha1).digest()
sign = base64.urlsafe_b64encode(digest).rstrip(b'=').decode() sign = base64.urlsafe_b64encode(digest).rstrip(b'=').decode()
return sign, timestamp, signature_nonce return sign, timestamp, signature_nonce
@@ -33,17 +33,17 @@ class LibLibUtil:
try: try:
sign, timestamp, signature_nonce = self.make_sign(uri) sign, timestamp, signature_nonce = self.make_sign(uri)
url = f'{self.base_url}{uri}?AccessKey={self.access_key}&Signature={sign}&Timestamp={timestamp}&SignatureNonce={signature_nonce}' url = f'{self.base_url}{uri}?AccessKey={self.access_key}&Signature={sign}&Timestamp={timestamp}&SignatureNonce={signature_nonce}'
headers = {'Content-Type': 'application/json'} headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=payload, headers=headers, timeout=self.timeout) response = requests.post(url, json=payload, headers=headers, timeout=self.timeout)
response.raise_for_status() response.raise_for_status()
response_data = response.json() response_data = response.json()
if response_data.get('code') == 0: if response_data.get('code') == 0:
return response_data.get('data') return response_data.get('data')
else: else:
print(f"API错误: {response_data.get('msg')}") print(f"API错误: {response_data.get('msg')}")
#print(response_data) # print(response_data)
return None return None
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print(f"请求异常: {str(e)}") print(f"请求异常: {str(e)}")
@@ -56,7 +56,7 @@ class LibLibUtil:
"""获取模型版本信息""" """获取模型版本信息"""
uri = "/api/model/version/get" uri = "/api/model/version/get"
payload = {"versionUuid": version_uuid} payload = {"versionUuid": version_uuid}
model_info = self.post_request(uri, payload) model_info = self.post_request(uri, payload)
if model_info: if model_info:
return { return {
@@ -114,11 +114,11 @@ class LibLibUtil:
return status_data return status_data
time.sleep(interval) time.sleep(interval)
print(f"生图任务超时({max_wait_time}秒)") print(f"生图任务超时({max_wait_time}秒)")
return None return None
def download_and_upload_to_obs(slef,image_url, generate_uuid): def download_and_upload_to_obs(slef, image_url, generate_uuid):
"""下载图片并上传到OBS""" """下载图片并上传到OBS"""
try: try:
# 1. 清理URL去除可能的引号和空格 # 1. 清理URL去除可能的引号和空格
@@ -167,7 +167,7 @@ class LibLibUtil:
""" """
try: try:
print(f"开始监控生成任务 {generate_uuid},每{interval}秒检查一次...") print(f"开始监控生成任务 {generate_uuid},每{interval}秒检查一次...")
# 轮询等待生成完成 # 轮询等待生成完成
status_data = self.wait_for_generation_completion(generate_uuid, interval) status_data = self.wait_for_generation_completion(generate_uuid, interval)
print(f"生图状态: {json.dumps(status_data, ensure_ascii=False, indent=2)}") print(f"生图状态: {json.dumps(status_data, ensure_ascii=False, indent=2)}")
@@ -189,3 +189,36 @@ class LibLibUtil:
except Exception as e: except Exception as e:
print(f"处理生成任务时发生异常: {str(e)}") print(f"处理生成任务时发生异常: {str(e)}")
return None return None
# 采样方法字典 - 包含28种采样方法及其枚举值和推荐度
SAMPLING_METHODS = {
"Euler a": 0,
"Euler": 1,
"LMS": 2,
"Heun": 3,
"DPM2": 4,
"DPM2 a": 5,
"DPM++ 2S a": 6,
"DPM++ 2M": 7,
"DPM++ SDE": 8,
"DPM fast": 9,
"DPM adaptive": 10,
"LMS Karras": 11,
"DPM2 Karras": 12,
"DPM2 a Karras": 13,
"DPM++ 2S a Karras": 14,
"DPM++ 2M Karras": 15,
"DPM++ SDE Karras": 16,
"DDIM": 17,
"PLMS": 18,
"UNIPC": 19,
"DPM++ 2M SDE Karras": 20,
"DPM++ 2M SDE EXPONENTIAL": 21,
"DPM++ 2M SDE Heun Karras": 24,
"DPM++ 2M SDE Heun Exponential": 25,
"DPM++ 3M SDE Karras": 27,
"DPM++ 3M SDE Exponential": 28,
"Restart": 29,
"LCM": 30
}

View File

@@ -1,4 +1,6 @@
import json import json
from Liblib.LibLibUtil import SAMPLING_METHODS
from PuLIDGenerator import PuLIDGenerator from PuLIDGenerator import PuLIDGenerator
# 加载配置文件 # 加载配置文件
@@ -7,11 +9,14 @@ with open('config.json', 'r', encoding='utf-8') as f:
if __name__ == "__main__": if __name__ == "__main__":
# 获取第一个模型的配置 # 获取第一个模型的配置
model_config = config["models"][0] model_config = config["models"][1]
# 通过枚举转换
print(f'使用采样方法: {model_config["sampler"]}')
model_config["sampler"] = SAMPLING_METHODS[model_config["sampler"]]
# 创建生成器实例 # 创建生成器实例
generator = PuLIDGenerator() generator = PuLIDGenerator()
# 使用配置参数 # 使用配置参数
generator.set_default_params( generator.set_default_params(
template_uuid=model_config["template_uuid"], template_uuid=model_config["template_uuid"],
@@ -19,13 +24,13 @@ if __name__ == "__main__":
width=model_config["width"], width=model_config["width"],
height=model_config["height"] height=model_config["height"]
) )
# 生成图像 # 生成图像
obs_url = generator.generate_image( obs_url = generator.generate_image(
prompt=model_config["prompt"], prompt=model_config["prompt"],
reference_image_url=model_config["reference_image_url"], reference_image_url=model_config["reference_image_url"],
control_weight=model_config["control_weight"] control_weight=model_config["control_weight"]
) )
if obs_url: if obs_url:
print(f"最终OBS地址: {obs_url}") print(f"最终OBS地址: {obs_url}")

Binary file not shown.

View File

@@ -6,9 +6,26 @@
"steps": 25, "steps": 25,
"width": 800, "width": 800,
"height": 1000, "height": 1000,
"cfgScale": 3.5,
"sampler": "Euler",
"seed": -1,
"prompt": "filmfotos, Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand", "prompt": "filmfotos, Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand",
"reference_image_url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/HuangWanQiao.jpg", "reference_image_url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/HuangWanQiao.jpg",
"control_weight": 0.8 "control_weight": 0.8
},
{
"name": "可铯AI—3d潮玩手办",
"template_uuid": "bc6863e816f44cb28062dda9ef616bca",
"steps": 30,
"width": 720,
"height": 1280,
"cfgScale": 3.5,
"sampler": "Euler",
"seed": -1,
"prompt": "3d,this image is a highly detailed,digital cgi rendering of a chibi-style character set against a blurred,domestic background,the centerpiece is a young,wide-eyed,anime-inspired girl with exaggeratedly large blue eyes,a small nose,and rosy cheeks,her dark,tousled hair is stylized with a large,red bow on the back and a few small stars clipped into her hair,enhancing a playful,whimsical appearance, the girl is dressed in a cozy,multicolored sweater that reads sweet in orange,featuring a rainbow stripe pattern underneath,suggestive of the brand cotton candy,she also wears red tights that extend up to mid-thigh,black shoes with thick soles,and is secured with black straps and a small belt-like accessory,the footwear is practical in design,resembling sturdy,athletic sneakers, the background is minimalist and softly blurred to ensure the chibi character stands out prominently,it hints at a cozy,modern room with light-colored wooden flooring and furniture,including a partial view of a bookshelf to the left and a large,beige wardrobe to the right,the overall atmosphere is serene and warm,with the cgi maintaining a soft,almost ethereal glow,contributing to the innocent,playful vibe of the image,",
"negative_prompt": "ng_deepnegative_v1_75t,(badhandv4:1.2),EasyNegative,(worst quality:2),",
"reference_image_url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/HuangWanQiao.jpg",
"control_weight": 0.8
} }
] ]
} }