From b917ab6bf8c78c7d30c390eddecff7e72789153b Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Thu, 4 Sep 2025 11:27:59 +0800 Subject: [PATCH] 'commit' --- dsLightRag/Liblib/LibLibGenerator.py | 151 ++++++++++++++++++ .../Liblib/T3_WenShengTu_DefaultCheckPoint.py | 93 +++-------- .../Liblib/T4_WenShengTu_CustomCheckPoint.py | 65 ++++---- .../LibLibGenerator.cpython-310.pyc | Bin 4740 -> 7723 bytes 4 files changed, 204 insertions(+), 105 deletions(-) diff --git a/dsLightRag/Liblib/LibLibGenerator.py b/dsLightRag/Liblib/LibLibGenerator.py index 3c3714b3..cbb65bcc 100644 --- a/dsLightRag/Liblib/LibLibGenerator.py +++ b/dsLightRag/Liblib/LibLibGenerator.py @@ -150,4 +150,155 @@ class LibLibGenerator: except Exception as e: print(f"处理图片时发生错误: {str(e)}") + return None + + def generate_default_text_to_image(self, prompt, steps=20, width=768, height=1024, + img_count=1, seed=-1, restore_faces=0, + additional_network=None): + """ + 使用默认官方模型进行文生图 + - Checkpoint默认为官方模型 + - 可用模型范围:基础算法F.1 + - 支持additional network + """ + generate_params = { + "templateUuid": "6f7c4652458d4802969f8d089cf5b91f", # 参数模板ID F.1文生图 + "generateParams": { + "prompt": prompt, + "steps": steps, + "width": width, + "height": height, + "imgCount": img_count, + "seed": seed, + "restoreFaces": restore_faces + } + } + + # 添加additional network参数(如果有) + if additional_network: + generate_params["generateParams"]["additionalNetwork"] = additional_network + + # 调用生成接口 + response = self.post_request( + "/api/generate/webui/text2img", + generate_params + ) + + 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 = self.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 = self.download_and_upload_to_obs(image_url, generate_uuid) + + if obs_url: + print(f"✅ 文件处理完成,OBS地址: {obs_url}") + file_url = f"https://{Config.Config.OBS_BUCKET}.{Config.Config.OBS_SERVER}/{obs_url}" + return file_url + else: + print("❌ 文件上传OBS失败") + return None + else: + print("❌ 未找到生成的图片数据") + return None + else: + error_msg = status_data.get('message', '未知错误') if status_data else '生成状态查询失败' + print(f"❌ 图像生成失败: {error_msg}") + return None + else: + error_msg = response.get('message', '未知错误') if response else 'API无响应' + print(f"❌ 图像生成失败: {error_msg}") + return None + + + def generate_custom_checkpoint_text_to_image(self, template_uuid, checkpoint_id, + prompt="", negative_prompt="", steps=20, + sampler=15, cfg_scale=7, width=768, + height=1024, img_count=1, randn_source=0, + seed=-1, restore_faces=0, hi_res_fix_info=None): + """ + 使用自定义Checkpoint模型进行文生图 + """ + generate_params = { + "templateUuid": template_uuid, + "generateParams": { + "checkPointId": checkpoint_id, + "prompt": prompt, + "negativePrompt": negative_prompt, + "sampler": sampler, + "steps": steps, + "cfgScale": cfg_scale, + "width": width, + "height": height, + "imgCount": img_count, + "randnSource": randn_source, + "seed": seed, + "restoreFaces": restore_faces + } + } + + # 添加高分辨率修复参数(如果有) + if hi_res_fix_info: + generate_params["generateParams"]["hiResFixInfo"] = hi_res_fix_info + + # 调用生成接口 + response = self.post_request( + "/api/generate/webui/text2img", + generate_params + ) + + 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 = self.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 = self.download_and_upload_to_obs(image_url, generate_uuid) + + if obs_url: + print(f"✅ 文件处理完成,OBS地址: {obs_url}") + file_url = f"https://{Config.Config.OBS_BUCKET}.{Config.Config.OBS_SERVER}/{obs_url}" + return file_url + else: + print("❌ 文件上传OBS失败") + return None + else: + print("❌ 未找到生成的图片数据") + return None + else: + error_msg = status_data.get('message', '未知错误') if status_data else '生成状态查询失败' + print(f"❌ 图像生成失败: {error_msg}") + return None + else: + error_msg = response.get('message', '未知错误') if response else 'API无响应' + print(f"❌ 图像生成失败: {error_msg}") return None \ No newline at end of file diff --git a/dsLightRag/Liblib/T3_WenShengTu_DefaultCheckPoint.py b/dsLightRag/Liblib/T3_WenShengTu_DefaultCheckPoint.py index d005756c..f30081fb 100644 --- a/dsLightRag/Liblib/T3_WenShengTu_DefaultCheckPoint.py +++ b/dsLightRag/Liblib/T3_WenShengTu_DefaultCheckPoint.py @@ -1,78 +1,29 @@ -import json from Liblib.LibLibGenerator import LibLibGenerator -from Config.Config import OBS_BUCKET, OBS_SERVER if __name__ == '__main__': - # - Checkpoint默认为官方模型 - """ - - Checkpoint默认为官方模型 - - 可用模型范围:基础算法F.1 - - 支持additional network - """ - generate_params = { - "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权重 - } - ] - } - } - liblib = LibLibGenerator() - # 调用生成接口 - response = liblib.post_request( - "/api/generate/webui/text2img", - generate_params + + # 设置LoRA参数 + additional_network = [ + { + "modelId": "169505112cee468b95d5e4a5db0e5669", # LoRA的模型版本uuid + "weight": 1.0 # LoRA权重 + } + ] + + # 调用通用方法进行文生图 + result = liblib.generate_default_text_to_image( + prompt="filmfotos, Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand", + steps=20, + width=768, + height=1024, + img_count=1, + seed=-1, + restore_faces=0, + additional_network=additional_network ) - 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}") + if result: + print(f"🎉 生图任务完成!最终OBS地址: {result}") else: - error_msg = response.get('message', '未知错误') if response else 'API无响应' - print(f"❌ 图像生成失败: {error_msg}") + print("❌ 生图任务失败") diff --git a/dsLightRag/Liblib/T4_WenShengTu_CustomCheckPoint.py b/dsLightRag/Liblib/T4_WenShengTu_CustomCheckPoint.py index fa83d3c9..d9c029e7 100644 --- a/dsLightRag/Liblib/T4_WenShengTu_CustomCheckPoint.py +++ b/dsLightRag/Liblib/T4_WenShengTu_CustomCheckPoint.py @@ -1,39 +1,36 @@ from Liblib.LibLibGenerator import LibLibGenerator if __name__ == '__main__': - generate_params = { - "templateUuid": "e10adc3949ba59abbe56e057f20f883e", - "generateParams": { - "checkPointId": "0ea388c7eb854be3ba3c6f65aac6bfd3", # 底模 modelVersionUUID - "prompt": "Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand", # 选填 - "negativePrompt": "ng_deepnegative_v1_75t,(badhandv4:1.2),EasyNegative,(worst quality:2),", #选填 - "sampler": 15, # 采样方法 - "steps": 20, # 采样步数 - "cfgScale": 7, # 提示词引导系数 - "width": 768, # 宽 - "height": 1024, # 高 - "imgCount": 1, # 图片数量 - "randnSource": 0, # 随机种子生成器 0 cpu,1 Gpu - "seed": 2228967414, # 随机种子值,-1表示随机 - "restoreFaces": 0, # 面部修复,0关闭,1开启 - - # 高分辨率修复 - "hiResFixInfo": { - "hiresSteps": 20, # 高分辨率修复的重绘步数 - "hiresDenoisingStrength": 0.75, # 高分辨率修复的重绘幅度 - "upscaler": 10, # 放大算法模型枚举 - "resizedWidth": 1024, # 放大后的宽度 - "resizedHeight": 1536 # 放大后的高度 - } - } -} - liblib = LibLibGenerator() - - # 调用生成接口 - response = liblib.post_request( - "/api/generate/webui/text2img", - generate_params + + # 设置高分辨率修复参数 + hi_res_fix_info = { + "hiresSteps": 20, + "hiresDenoisingStrength": 0.75, + "upscaler": 10, + "resizedWidth": 1024, + "resizedHeight": 1536 + } + + # 调用自定义Checkpoint方法进行文生图 + result = liblib.generate_custom_checkpoint_text_to_image( + template_uuid="e10adc3949ba59abbe56e057f20f883e", + checkpoint_id="0ea388c7eb854be3ba3c6f65aac6bfd3", + prompt="Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand", + negative_prompt="ng_deepnegative_v1_75t,(badhandv4:1.2),EasyNegative,(worst quality:2),", + sampler=15, + steps=20, + cfg_scale=7, + width=768, + height=1024, + img_count=1, + randn_source=0, + seed=2228967414, + restore_faces=0, + hi_res_fix_info=hi_res_fix_info ) - # {'generateUuid': 'f16463d55e144214ae12d5177f8256fc'} - print(response) + + if result: + print(f"🎉 生图任务完成!最终OBS地址: {result}") + else: + print("❌ 生图任务失败") diff --git a/dsLightRag/Liblib/__pycache__/LibLibGenerator.cpython-310.pyc b/dsLightRag/Liblib/__pycache__/LibLibGenerator.cpython-310.pyc index 1f36d5b36940534d6cc6add64b234dc7f88621ef..2597bc0857ca1b8027c0cd8cb2cb9cef60e40934 100644 GIT binary patch delta 3263 zcmbtW-BTOa72jP6X(g?`_%ztT!c$MJ2jkeaT_BF*kJ_o54rNSeXEbfMvhE5NkVNmU zY?5A8xF)f|5Xb;_YH%>EJqhj%I3ac8ujCKNb6@tc!wPsxAHqXDt=n^UkqT~_K6F7p z-E;4`=bk+`kn#Jy96Wp754v3Y-wk}hcfD&IY~D%yBrwRwL=q&SK`!R; zRCuaAH6%i|ky_~YdcvM^tEYjyKF%zK`r^DykI<#Il7mv9We{mfVN1S??8;JTg62T_8f zLQY~5y~dnfuYq5=<%hi$b37f_T}&bswcI71RQBYZblf&cC1hF!3;H2f zH-n`h*8mI9VF*#p0>y<%jV^YJ-JWTVY_nQkXw_Qdu3V4>+cD8PT#{_J+B=GENbY?r zIoR(xA)34pX28A2BavTXbv4h5pkkx-0uf*amN8<5_<4`O4&nYmeSr zUAS#7yjQsPpzz_G`To__&!<=CMhe$1uT0LG)1Q_6_eM^3DT$tZUj~khJ#G2Zhnr_^ zay7>mA^1kXkxS^Yqbk%c7LJo}F~?Rr#iu(a?s+Qny3(&7fCbil;CH<3j5#rCKAdcc zoTewBV_q;MC9P$tBFD9asv0geO_a1wUxLB)Jpg~1c`E|dHZP4q*$Y?3mmfVchv&>c zeGF}Lc(yP$zWng^mya*5OW{h8p?NiFR}5o_TYiCGu44()B*AW#2x7Z+yz{Td&2LH%B7& z#N|(imml9k|Jxs}esZUEeOGaK=5Ar=GxN&5jkmfn2vu4cx?GsLR~TI|+$lx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