2025-09-03 15:32:20 +08:00
|
|
|
|
import json
|
|
|
|
|
import requests
|
|
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
from LiblibUtil import LiblibUtil
|
|
|
|
|
from Util.ObsUtil import ObsUploader # 导入OBS上传工具
|
2025-09-03 14:41:08 +08:00
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2025-09-03 14:44:19 +08:00
|
|
|
|
liblib = LiblibUtil()
|
2025-09-03 15:32:20 +08:00
|
|
|
|
print("===== 测试查询生图结果并上传OBS =====")
|
|
|
|
|
test_generate_uuid = "df9bd6e03a204542b1daaba2f17c42e6"
|
|
|
|
|
|
2025-09-03 14:41:08 +08:00
|
|
|
|
if test_generate_uuid:
|
2025-09-03 15:32:20 +08:00
|
|
|
|
# 等待任务完成
|
|
|
|
|
status_data = liblib.wait_for_generation_completion(test_generate_uuid)
|
|
|
|
|
print(f"生图状态: {json.dumps(status_data, ensure_ascii=False, indent=2)}")
|
|
|
|
|
|
|
|
|
|
# 检查生成状态是否为5(完成)
|
|
|
|
|
if status_data and status_data.get('generateStatus') == 5:
|
|
|
|
|
# 提取图片URL
|
|
|
|
|
if status_data.get('images') and len(status_data['images']) > 0:
|
|
|
|
|
image_url = status_data['images'][0]['imageUrl']
|
|
|
|
|
# 下载并上传到OBS
|
|
|
|
|
# 使用实例调用而非类调用
|
|
|
|
|
obs_path = liblib.download_and_upload_to_obs(image_url, test_generate_uuid)
|
|
|
|
|
if obs_path:
|
|
|
|
|
print(f"\n最终OBS路径: {obs_path}")
|
|
|
|
|
else:
|
|
|
|
|
print("❌ 未找到图片数据")
|
2025-09-03 14:41:08 +08:00
|
|
|
|
else:
|
2025-09-03 15:32:20 +08:00
|
|
|
|
print(f"❌ 生图未完成或失败,状态码: {status_data.get('generateStatus')}")
|
2025-09-03 14:41:08 +08:00
|
|
|
|
else:
|
|
|
|
|
print("请先设置有效的生图任务UUID")
|