Files
DumasNodes/library.py
T
chris.dumas 70d0672ee3 Squashed 'vendor/dumas_minimax_h3_refmod/' content from commit 517e8c4
git-subtree-dir: vendor/dumas_minimax_h3_refmod
git-subtree-split: 517e8c419a8584fbf69fceb487bc39d83e6a6ec8
2026-10-20 13:43:44 +00:00

48 lines
2.0 KiB
Python

"""Metadata-only library endpoint; no tensor allocation or VAE loading."""
from aiohttp import web
from .bundle import members
def library_entries(names, find_path, read_meta):
entries = []
for name in names():
try:
path = find_path(name)
meta = read_meta(path)
except (OSError, ValueError):
continue
if not isinstance(meta, dict):
continue
kind = meta.get("kind")
if kind == "bundle":
try:
refs = members(meta)
tokens = sum(int(ref["latent_t"]) * (2 if ref["kind"] == "audio" else
(int(ref["latent_h"]) // 2) * (int(ref["latent_w"]) // 2)) for ref in refs)
except (ValueError, KeyError, TypeError):
continue
entries.append({"name": name, "kind": "bundle", "path": path + ".safetensors",
"concept": "bundle", "description": "; ".join(
f"{ref.get('name', '')} ({ref['kind']})" for ref in refs),
"tokens": tokens, "shape": None, "config": ""})
continue
try:
t = int(meta.get("latent_t", 0))
h, w = int(meta.get("latent_h", 0)), int(meta.get("latent_w", 0))
except (TypeError, ValueError):
continue
tokens = t * 2 if kind == "audio" else t * (h // 2) * (w // 2)
entries.append({"name": name, "kind": kind, "path": path + ".safetensors",
"concept": meta.get("concept_type", "generic"),
"description": meta.get("description", ""),
"tokens": tokens or None, "shape": [t, h, w],
"config": meta.get("refmod_config", "")})
return entries
def register_routes(server, names, find_path, read_meta):
@server.routes.get("/refmods/library")
async def library(request):
return web.json_response(library_entries(names, find_path, read_meta))