diff --git a/dsLightRag/Liblib/LibLibUtil.py b/dsLightRag/Liblib/LibLibUtil.py index 15a8643a..fdbe6431 100644 --- a/dsLightRag/Liblib/LibLibUtil.py +++ b/dsLightRag/Liblib/LibLibUtil.py @@ -23,7 +23,7 @@ class LibLibUtil: timestamp = str(int(time.time() * 1000)) signature_nonce = str(uuid.uuid4()) content = '&'.join((uri, timestamp, signature_nonce)) - + digest = hmac.new(self.secret_key.encode(), content.encode(), sha1).digest() sign = base64.urlsafe_b64encode(digest).rstrip(b'=').decode() return sign, timestamp, signature_nonce @@ -33,17 +33,17 @@ class LibLibUtil: try: 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}' - + headers = {'Content-Type': 'application/json'} response = requests.post(url, json=payload, headers=headers, timeout=self.timeout) response.raise_for_status() - + response_data = response.json() if response_data.get('code') == 0: return response_data.get('data') else: print(f"API错误: {response_data.get('msg')}") - #print(response_data) + # print(response_data) return None except requests.exceptions.RequestException as e: print(f"请求异常: {str(e)}") @@ -56,7 +56,7 @@ class LibLibUtil: """获取模型版本信息""" uri = "/api/model/version/get" payload = {"versionUuid": version_uuid} - + model_info = self.post_request(uri, payload) if model_info: return { @@ -114,11 +114,11 @@ class LibLibUtil: return status_data time.sleep(interval) - + print(f"生图任务超时({max_wait_time}秒)") 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""" try: # 1. 清理URL(去除可能的引号和空格) @@ -167,7 +167,7 @@ class LibLibUtil: """ 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)}") @@ -189,3 +189,36 @@ class LibLibUtil: 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 +} diff --git a/dsLightRag/Liblib/T3.py b/dsLightRag/Liblib/T3.py index 4ea0b41b..6ee3c89c 100644 --- a/dsLightRag/Liblib/T3.py +++ b/dsLightRag/Liblib/T3.py @@ -1,4 +1,6 @@ import json + +from Liblib.LibLibUtil import SAMPLING_METHODS from PuLIDGenerator import PuLIDGenerator # 加载配置文件 @@ -7,11 +9,14 @@ with open('config.json', 'r', encoding='utf-8') as f: 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.set_default_params( template_uuid=model_config["template_uuid"], @@ -19,13 +24,13 @@ if __name__ == "__main__": width=model_config["width"], height=model_config["height"] ) - + # 生成图像 obs_url = generator.generate_image( prompt=model_config["prompt"], reference_image_url=model_config["reference_image_url"], control_weight=model_config["control_weight"] ) - + if obs_url: print(f"最终OBS地址: {obs_url}") diff --git a/dsLightRag/Liblib/__pycache__/LibLibUtil.cpython-310.pyc b/dsLightRag/Liblib/__pycache__/LibLibUtil.cpython-310.pyc index 919190d6..7f64bb9a 100644 Binary files a/dsLightRag/Liblib/__pycache__/LibLibUtil.cpython-310.pyc and b/dsLightRag/Liblib/__pycache__/LibLibUtil.cpython-310.pyc differ diff --git a/dsLightRag/Liblib/__pycache__/__init__.cpython-310.pyc b/dsLightRag/Liblib/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..4d8434d7 Binary files /dev/null and b/dsLightRag/Liblib/__pycache__/__init__.cpython-310.pyc differ diff --git a/dsLightRag/Liblib/config.json b/dsLightRag/Liblib/config.json index d057068e..47fae8f5 100644 --- a/dsLightRag/Liblib/config.json +++ b/dsLightRag/Liblib/config.json @@ -6,9 +6,26 @@ "steps": 25, "width": 800, "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", "reference_image_url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/HuangWanQiao.jpg", "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 } ] } \ No newline at end of file