Show SV metadata for postprocess results
This commit is contained in:
@@ -99,6 +99,25 @@ def post_result_path(filename: str, source: str, processor: str, params: dict[st
|
||||
return image_result_dir(filename) / "postprocess" / f"{_safe_slug(source)}__{_safe_slug(processor)}{suffix}.png"
|
||||
|
||||
|
||||
def post_metadata_path(output_path: Path) -> Path:
|
||||
return output_path.with_suffix(".json")
|
||||
|
||||
|
||||
def read_post_metadata(output_path: Path) -> dict[str, Any]:
|
||||
metadata_path = post_metadata_path(output_path)
|
||||
if not metadata_path.exists():
|
||||
return {}
|
||||
try:
|
||||
return json.loads(metadata_path.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def write_post_metadata(output_path: Path, payload: dict[str, Any]) -> None:
|
||||
metadata_path = post_metadata_path(output_path)
|
||||
metadata_path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def relpath(path: Path) -> str:
|
||||
return path.resolve().relative_to(ROOT).as_posix()
|
||||
|
||||
@@ -206,7 +225,20 @@ def get_results(filename: str) -> dict[str, Any]:
|
||||
post_dir = image_result_dir(filename) / "postprocess"
|
||||
if post_dir.exists():
|
||||
for path in sorted(post_dir.glob("*.png"), key=lambda p: p.name.lower()):
|
||||
post.append({"name": path.stem, "exists": True, "path": relpath(path)})
|
||||
metadata = read_post_metadata(path)
|
||||
post.append(
|
||||
{
|
||||
"name": path.stem,
|
||||
"exists": True,
|
||||
"path": relpath(path),
|
||||
"meta": metadata.get("meta", {}),
|
||||
"processor": metadata.get("processor", ""),
|
||||
"source": metadata.get("source", ""),
|
||||
"reference": metadata.get("reference", ""),
|
||||
"params": metadata.get("params", {}),
|
||||
"metadata_path": relpath(post_metadata_path(path)) if post_metadata_path(path).exists() else "",
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
"image": filename,
|
||||
@@ -249,6 +281,7 @@ def collect_download_items(filenames: list[str] | None = None, include_original:
|
||||
if post_dir.exists():
|
||||
for result in sorted(post_dir.glob("*.png"), key=lambda p: p.name.lower()):
|
||||
add_file(result, f"{folder}/postprocess/{result.name}")
|
||||
add_file(post_metadata_path(result), f"{folder}/postprocess/{post_metadata_path(result).name}")
|
||||
|
||||
return items
|
||||
|
||||
@@ -523,6 +556,19 @@ def run_postprocessors_for_source(
|
||||
proc_params = params.get(processor, params)
|
||||
output = post_result_path(filename, source_name, processor, proc_params)
|
||||
meta = run_postprocess(processor, source_path, output, reference_path=reference_path, params=proc_params)
|
||||
write_post_metadata(
|
||||
output,
|
||||
{
|
||||
"image": filename,
|
||||
"source": source_name,
|
||||
"processor": processor,
|
||||
"reference": reference_path.name,
|
||||
"params": proc_params,
|
||||
"meta": meta,
|
||||
"output": relpath(output),
|
||||
"created_at": time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
},
|
||||
)
|
||||
outputs.append(output)
|
||||
log(f"后处理完成 {source_name} / {processor}: {json.dumps(meta, ensure_ascii=False)}")
|
||||
return outputs
|
||||
|
||||
Reference in New Issue
Block a user