优化jupscale

This commit is contained in:
jingrow 2025-05-20 20:13:09 +08:00
parent 5cfae7aafe
commit dee2929268

View File

@ -29,47 +29,26 @@ workflow_template = """
"inputs": {
"model_name": ""
},
"class_type": "UpscaleModelLoader",
"_meta": {
"title": "Load Upscale Model"
}
"class_type": "UpscaleModelLoader"
},
"14": {
"inputs": {
"upscale_model": [
"13",
0
],
"image": [
"15",
0
]
"upscale_model": ["13", 0],
"image": ["15", 0]
},
"class_type": "ImageUpscaleWithModel",
"_meta": {
"title": "Upscale Image (using Model)"
}
"class_type": "ImageUpscaleWithModel"
},
"15": {
"inputs": {
"url_or_path": ""
},
"class_type": "LoadImageFromUrlOrPath",
"_meta": {
"title": "LoadImageFromUrlOrPath"
}
"class_type": "LoadImageFromUrlOrPath"
},
"16": {
"inputs": {
"images": [
"14",
0
]
"images": ["14", 0]
},
"class_type": "SaveImageWebsocket",
"_meta": {
"title": "SaveImageWebsocket"
}
"class_type": "SaveImageWebsocket"
}
}
"""
@ -131,8 +110,7 @@ class ImageUpscaleService:
p = {"prompt": prompt, "client_id": client_id}
data = json.dumps(p).encode('utf-8')
req = urllib.request.Request(f"http://{comfyui_server_address}/prompt", data=data)
response = json.loads(urllib.request.urlopen(req).read())
return response
return json.loads(urllib.request.urlopen(req).read())
def get_images(self, ws: websocket.WebSocket, workflow: Dict, comfyui_server_address: str, client_id: str) -> Dict:
"""从 ComfyUI 获取生成的图像"""
@ -261,15 +239,8 @@ class ImageUpscaleService:
"""异步放大图像返回图片URL"""
try:
# 在这种情况下,我们需要手动运行同步生成器并收集结果
urls = []
# 在执行器中运行同步代码
def run_sync():
return list(self.upscale_image_sync(image_url, config))
# 获取所有URL
loop = asyncio.get_event_loop()
urls = await loop.run_in_executor(None, run_sync)
urls = await loop.run_in_executor(None, lambda: list(self.upscale_image_sync(image_url, config)))
# 逐个返回结果
for url in urls: