diff --git a/dsLightRag/Liblib/LibLibGenerator.py b/dsLightRag/Liblib/LibLibGenerator.py index 48ff2dfe..3c3714b3 100644 --- a/dsLightRag/Liblib/LibLibGenerator.py +++ b/dsLightRag/Liblib/LibLibGenerator.py @@ -72,21 +72,6 @@ class LibLibGenerator: print(model_info) return None - def generate_text_to_image(self, template_uuid, generate_params): - # "templateUuid": self.default_params["templateUuid"], - # "generateParams": { - # "prompt": prompt, - # **self.default_params, - # "controlNet": self.build_control_net_params(reference_image_url, control_weight) - # } - """调用text2img接口生成图片""" - uri = "/api/generate/webui/text2img" - payload = { - "templateUuid": template_uuid, - "generateParams": generate_params - } - print(payload) - return self.post_request(uri, payload) def get_generation_status(self, generate_uuid): """查询生图任务状态和结果""" @@ -165,124 +150,4 @@ class LibLibGenerator: except Exception as e: print(f"处理图片时发生错误: {str(e)}") - return None - - def process_generation_task(self, generate_uuid, interval=2): - """ - 完整处理生成任务: 轮询状态 → 下载图片 → 上传OBS → 清理临时文件 - :param generate_uuid: 生成任务UUID - :param interval: 轮询间隔(秒) - :return: OBS路径或None - """ - try: - print(f"开始监控生成任务 {generate_uuid},每{interval}秒检查一次...") - - # 轮询等待生成完成 - status_data = self.wait_for_generation_completion(generate_uuid, interval) - 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 = self.download_and_upload_to_obs(image_url, generate_uuid) - return obs_path - else: - print("❌ 未找到图片数据") - return None - else: - print(f"❌ 生图未完成或失败,状态码: {status_data.get('generateStatus')}") - return None - except Exception as e: - print(f"处理生成任务时发生异常: {str(e)}") - return None - - def generate_image_with_obs(self, template_uuid, generate_params): - """ - 完整生图流程:生成图片 → 等待完成 → 上传OBS → 返回URL - :param template_uuid: 模板UUID - :param generate_params: 生成参数字典 - :return: OBS文件URL或None - """ - try: - # 调用生成接口 - response = self.generate_text_to_image(template_uuid, generate_params) - - if response and "generateUuid" in response: - generate_uuid = response["generateUuid"] - print("✅ 图像生成任务已成功提交!") - print(f"生成UUID: {generate_uuid}") - print("开始轮询生成状态...") - - # 等待生成完成 - 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_object_key = self.download_and_upload_to_obs(image_url, generate_uuid) - - if obs_object_key: - # 构建完整的OBS URL - import Config.Config - file_url = f"https://{Config.Config.OBS_BUCKET}.{Config.Config.OBS_SERVER}/{obs_object_key}" - print(f"✅ 文件处理完成,OBS地址: {file_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 - except Exception as e: - print(f"请求发生异常: {str(e)}") - 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 -} + return None \ No newline at end of file diff --git a/dsLightRag/Liblib/LibLibSamplingEnum.py b/dsLightRag/Liblib/LibLibSamplingEnum.py new file mode 100644 index 00000000..a743d5e2 --- /dev/null +++ b/dsLightRag/Liblib/LibLibSamplingEnum.py @@ -0,0 +1,32 @@ + +# 采样方法字典 - 包含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 +} diff --git a/dsLightRag/Liblib/__pycache__/LibLibGenerator.cpython-310.pyc b/dsLightRag/Liblib/__pycache__/LibLibGenerator.cpython-310.pyc index 3cce0c20..1f36d5b3 100644 Binary files a/dsLightRag/Liblib/__pycache__/LibLibGenerator.cpython-310.pyc and b/dsLightRag/Liblib/__pycache__/LibLibGenerator.cpython-310.pyc differ