chore: auto-commit (61 archivos)
- docs/capabilities/INDEX.md - docs/capabilities/comfyui.md - python/functions/browser/comfyui_export_workflow_ui.md - python/functions/browser/comfyui_export_workflow_ui.py - python/functions/browser/comfyui_load_workflow_ui.md - python/functions/browser/comfyui_load_workflow_ui.py - python/functions/browser/comfyui_queue_prompt_ui.md - python/functions/browser/comfyui_queue_prompt_ui.py - python/functions/browser/comfyui_refresh_nodes_ui.md - python/functions/browser/comfyui_refresh_nodes_ui.py - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""Descarga un PNG generado por ComfyUI via GET /view a disco local.
|
||||
|
||||
comfyui_wait_result devuelve solo metadata (node_id -> {images: [{filename,
|
||||
subfolder, type}]}); esta funcion baja el archivo real al disco local para
|
||||
poder abrirlo, mostrarlo o procesarlo.
|
||||
|
||||
Impura: red (HTTP GET) + escritura en disco. Solo stdlib (urllib, os).
|
||||
"""
|
||||
import os
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
|
||||
def comfyui_fetch_output_image(
|
||||
filename: str,
|
||||
*,
|
||||
subfolder: str = "",
|
||||
type_: str = "output",
|
||||
server: str = "127.0.0.1:8188",
|
||||
dest_dir: str = ".",
|
||||
timeout: float = 60.0,
|
||||
) -> dict:
|
||||
"""Baja una imagen del servidor ComfyUI a un directorio local.
|
||||
|
||||
Args:
|
||||
filename: nombre del archivo en el servidor (ej. "comfy_00001_.png"),
|
||||
tal como lo reporta comfyui_wait_result en outputs[node].images.
|
||||
subfolder: subcarpeta dentro de la carpeta del servidor (vacia por
|
||||
defecto). keyword-only.
|
||||
type_: tipo de carpeta del servidor: "output", "temp" o "input".
|
||||
keyword-only.
|
||||
server: host:port del servidor ComfyUI (sin esquema). keyword-only.
|
||||
dest_dir: directorio local donde guardar la imagen; se crea si no existe.
|
||||
keyword-only.
|
||||
timeout: timeout de la peticion HTTP en segundos. keyword-only.
|
||||
|
||||
Returns:
|
||||
dict {ok, path, size_bytes, error}. path = ruta local del PNG guardado;
|
||||
size_bytes = tamano descargado. Si falla, ok=False y error explica.
|
||||
"""
|
||||
qs = urllib.parse.urlencode(
|
||||
{"filename": filename, "subfolder": subfolder, "type": type_}
|
||||
)
|
||||
url = f"http://{server}/view?{qs}"
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=timeout) as resp:
|
||||
blob = resp.read()
|
||||
except urllib.error.HTTPError as exc:
|
||||
body = exc.read().decode(errors="replace")[:200]
|
||||
return {"ok": False, "path": "", "size_bytes": 0,
|
||||
"error": f"HTTP {exc.code} en {url}: {body}"}
|
||||
except urllib.error.URLError as exc:
|
||||
return {"ok": False, "path": "", "size_bytes": 0,
|
||||
"error": f"no se pudo conectar a {url}: {exc.reason}"}
|
||||
try:
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
out_path = os.path.join(dest_dir, os.path.basename(filename))
|
||||
with open(out_path, "wb") as f:
|
||||
f.write(blob)
|
||||
except OSError as exc:
|
||||
return {"ok": False, "path": "", "size_bytes": 0,
|
||||
"error": f"no se pudo escribir en {dest_dir!r}: {exc}"}
|
||||
return {"ok": True, "path": out_path, "size_bytes": len(blob), "error": ""}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import json
|
||||
|
||||
res = comfyui_fetch_output_image("comfy_00001_.png", dest_dir="/tmp")
|
||||
print(json.dumps(res, indent=2))
|
||||
Reference in New Issue
Block a user