router: Metadaten pro Bild speichern (Sidecar-JSON)
- prompt, seed, width, height, size, steps, guidance, quality, seconds, model, created - /images zeigt die Metadaten (falls vorhanden)
This commit is contained in:
1 parent
7c5bbe2ffb
commit
fdaaef98cc
1 file changed
+35
-4
@@ -473,7 +473,8 @@ def _restore_qwen(profile: str) -> None:
|
||||
|
||||
|
||||
def generate_image(prompt: str, width: int, height: int, steps: int,
|
||||
guidance: float, seed: int | None, n: int
|
||||
guidance: float, seed: int | None, n: int,
|
||||
quality: str = "standard"
|
||||
) -> tuple[list[str], str | None]:
|
||||
"""Orchestriert die Bildgenerierung inkl. Qwen-Hotswap.
|
||||
|
||||
@@ -532,6 +533,26 @@ def generate_image(prompt: str, width: int, height: int, steps: int,
|
||||
results.append(filename)
|
||||
img.last_image = filename
|
||||
img.last_seconds = resp.get("seconds")
|
||||
# Metadaten speichern (Sidecar-JSON).
|
||||
meta = {
|
||||
"prompt": prompt,
|
||||
"seed": seed,
|
||||
"width": width,
|
||||
"height": height,
|
||||
"size": f"{width}x{height}",
|
||||
"steps": steps,
|
||||
"guidance": guidance,
|
||||
"quality": quality,
|
||||
"seconds": resp.get("seconds"),
|
||||
"model": "FLUX.2-klein-base-4B",
|
||||
"created": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
}
|
||||
meta_path = os.path.join(IMAGE_DIR, filename[:-4] + ".json")
|
||||
try:
|
||||
with open(meta_path, "w", encoding="utf-8") as f:
|
||||
json.dump(meta, f, ensure_ascii=False, indent=2)
|
||||
except OSError as e:
|
||||
log.warning("Metadaten-Speicherung fehlgeschlagen: %s", e)
|
||||
log.info("Bild %d/%d: %s (%.1f s)", i + 1, n, filename,
|
||||
resp.get("seconds", 0))
|
||||
|
||||
@@ -759,7 +780,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.timeout = None
|
||||
try:
|
||||
results, warning = generate_image(
|
||||
prompt.strip(), width, height, steps, guidance, seed, n)
|
||||
prompt.strip(), width, height, steps, guidance, seed, n,
|
||||
quality)
|
||||
except (ValueError, RuntimeError) as e:
|
||||
self._send_error(503, str(e), "server_error", "image_generation_failed")
|
||||
return
|
||||
@@ -795,12 +817,21 @@ class Handler(BaseHTTPRequestHandler):
|
||||
st = os.stat(path)
|
||||
except OSError:
|
||||
continue
|
||||
entries.append({
|
||||
entry = {
|
||||
"name": name,
|
||||
"url": f"/images/{name}",
|
||||
"bytes": st.st_size,
|
||||
"modified": int(st.st_mtime),
|
||||
})
|
||||
}
|
||||
# Metadaten laden (Sidecar-JSON, falls vorhanden).
|
||||
meta_path = os.path.join(IMAGE_DIR, name[:-4] + ".json")
|
||||
if os.path.isfile(meta_path):
|
||||
try:
|
||||
with open(meta_path, encoding="utf-8") as f:
|
||||
entry["meta"] = json.load(f)
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
entries.append(entry)
|
||||
self._send_json(200, {"images": entries[:200]})
|
||||
|
||||
def _image_serve(self, name: str) -> None:
|
||||
|
||||
Reference in new issue
Block a user