-
I'm calling the /view api endpoint for a promptid that I received through a post request to /prompt The call is taking 8 seconds for some reason. Why? Log (batch of four images):
I'm using this method: from datetime import datetime
def get_image(filename, subfolder, type):
# Construct the URL for the GET request
url = f"{BASE_COMFY_URL}/view"
pre_request_timestamp = datetime.now()
# Parameters to be sent with the request
params = {
"filename": filename,
"subfolder": subfolder,
"type": type
}
response = requests.get(url, params=params)
post_request_timestamp = datetime.now()
duration = post_request_timestamp - pre_request_timestamp
print(f"get_image duration: {duration}")
return response I tried calling through a REST client as well, took 8 seconds as well. Found this issue: #1971 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I don't seem to have this problem, when using either python, javascript, or csharp, with http:// and ws:// or https:// and wss://. But I am within my network. I can call history and view endpoints, parse the image as bytes, apply as texture2d, convert to RenderTexture, clean up memory and slam the image into vr, 2048x2048, in less than a second. Which all of that carries extra overhead. So, it has to be in your setup, either network, middle man if any, local or remote connection, disk speed, ram, or computer going in lower power mode. How many other things are you running at once, what's your setup. Without this, it's hard to compare why mine is fine, and yours is not. |
Beta Was this translation helpful? Give feedback.
-
If you're going to benchmark, you might consider benchmarking on the server side, when it receives a call, to when it sends. You can find it in server.py, Class PromptServer, in the init method: @routes.get("/view")
async def view_image(request):
if "filename" in request.rel_url.query:
filename = request.rel_url.query["filename"]
filename,output_dir = folder_paths.annotated_filepath(filename)
# validation for security: prevent accessing arbitrary path
if filename[0] == '/' or '..' in filename:
return web.Response(status=400)
if output_dir is None:
type = request.rel_url.query.get("type", "output")
output_dir = folder_paths.get_directory_by_type(type)
if output_dir is None:
return web.Response(status=400)
if "subfolder" in request.rel_url.query:
full_output_dir = os.path.join(output_dir, request.rel_url.query["subfolder"])
if os.path.commonpath((os.path.abspath(full_output_dir), output_dir)) != output_dir:
return web.Response(status=403)
output_dir = full_output_dir
filename = os.path.basename(filename)
file = os.path.join(output_dir, filename)
if os.path.isfile(file):
if 'preview' in request.rel_url.query:
with Image.open(file) as img:
preview_info = request.rel_url.query['preview'].split(';')
image_format = preview_info[0]
if image_format not in ['webp', 'jpeg'] or 'a' in request.rel_url.query.get('channel', ''):
image_format = 'webp'
quality = 90
if preview_info[-1].isdigit():
quality = int(preview_info[-1])
buffer = BytesIO()
if image_format in ['jpeg'] or request.rel_url.query.get('channel', '') == 'rgb':
img = img.convert("RGB")
img.save(buffer, format=image_format, quality=quality)
buffer.seek(0)
return web.Response(body=buffer.read(), content_type=f'image/{image_format}',
headers={"Content-Disposition": f"filename=\"{filename}\""})
if 'channel' not in request.rel_url.query:
channel = 'rgba'
else:
channel = request.rel_url.query["channel"]
if channel == 'rgb':
with Image.open(file) as img:
if img.mode == "RGBA":
r, g, b, a = img.split()
new_img = Image.merge('RGB', (r, g, b))
else:
new_img = img.convert("RGB")
buffer = BytesIO()
new_img.save(buffer, format='PNG')
buffer.seek(0)
return web.Response(body=buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""})
elif channel == 'a':
with Image.open(file) as img:
if img.mode == "RGBA":
_, _, _, a = img.split()
else:
a = Image.new('L', img.size, 255)
# alpha img
alpha_img = Image.new('RGBA', img.size)
alpha_img.putalpha(a)
alpha_buffer = BytesIO()
alpha_img.save(alpha_buffer, format='PNG')
alpha_buffer.seek(0)
return web.Response(body=alpha_buffer.read(), content_type='image/png',
headers={"Content-Disposition": f"filename=\"{filename}\""})
else:
return web.FileResponse(file, headers={"Content-Disposition": f"filename=\"{filename}\""})
return web.Response(status=404) |
Beta Was this translation helpful? Give feedback.
@nihiluis You want to bet, that when you make a network request to the endpoint, that it then has to make a network request to your drive to deliver it back to the main server, then to send it back to you. Using Colab is your issue, they are trying to block stable diffusion if you aren't doing pay to play.