Files
dsProject/dsLightRag/Liblib/T3_WenShengTu_DefaultCheckPoint.py

79 lines
3.1 KiB
Python
Raw Normal View History

2025-09-04 11:20:11 +08:00
import json
2025-09-04 10:44:06 +08:00
from Liblib.LibLibGenerator import LibLibGenerator
2025-09-04 11:20:11 +08:00
from Config.Config import OBS_BUCKET, OBS_SERVER
2025-09-03 14:41:08 +08:00
2025-09-04 10:43:10 +08:00
if __name__ == '__main__':
2025-09-04 11:09:36 +08:00
# - Checkpoint默认为官方模型
"""
- Checkpoint默认为官方模型
- 可用模型范围基础算法F.1
- 支持additional network
"""
2025-09-04 10:08:26 +08:00
generate_params = {
2025-09-04 10:43:10 +08:00
"templateUuid": "6f7c4652458d4802969f8d089cf5b91f", # 参数模板ID F.1文生图
"generateParams": {
"prompt": "filmfotos, Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand",
"steps": 20, # 采样步数
"width": 768, # 宽
"height": 1024, # 高
"imgCount": 1, # 图片数量
"seed": -1, # 随机种子值,-1 表示随机
"restoreFaces": 0, # 面部修复0 关闭1 开启
# Lora添加最多5个不添加lora时请删除此结构体
"additionalNetwork": [
{
"modelId": "169505112cee468b95d5e4a5db0e5669", # LoRA的模型版本uuid
"weight": 1.0 # LoRA权重
}
]
}
2025-09-04 10:08:26 +08:00
}
2025-09-04 10:44:06 +08:00
liblib = LibLibGenerator()
2025-09-04 10:43:10 +08:00
# 调用生成接口
response = liblib.post_request(
"/api/generate/webui/text2img",
generate_params
)
2025-09-04 11:20:11 +08:00
print(f"API响应: {json.dumps(response, ensure_ascii=False, indent=2)}")
if response and "generateUuid" in response:
generate_uuid = response["generateUuid"]
print("✅ 图像生成任务已成功提交!")
print(f"生成UUID: {generate_uuid}")
print("开始轮询生成状态...")
# 每2秒探测一次生成状态直到完成
status_data = liblib.wait_for_generation_completion(
generate_uuid, interval=2
)
# 检查生成状态
if status_data and status_data.get("generateStatus") == 5:
print("🎉 图像生成完成!开始处理文件...")
# 提取图片URL
if status_data.get("images") and len(status_data["images"]) > 0:
image_url = status_data["images"][0]["imageUrl"]
# 下载并上传到OBS
obs_url = liblib.download_and_upload_to_obs(
image_url, generate_uuid
)
if obs_url:
print(f"✅ 文件处理完成OBS地址: {obs_url}")
file_url = f"https://{OBS_BUCKET}.{OBS_SERVER}/{obs_url}"
print(f"完整OBS URL: {file_url}")
else:
print("❌ 文件上传OBS失败")
else:
print("❌ 未找到生成的图片数据")
else:
error_msg = status_data.get('message', '未知错误') if status_data else '生成状态查询失败'
print(f"❌ 图像生成失败: {error_msg}")
else:
error_msg = response.get('message', '未知错误') if response else 'API无响应'
print(f"❌ 图像生成失败: {error_msg}")