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