From 0b8e0bf774a900594f0281eba4172d828897c8c2 Mon Sep 17 00:00:00 2001 From: Ashim Date: Tue, 21 Apr 2026 23:51:11 +0800 Subject: [PATCH] fix: auto-fallback from CodeFormer to GFPGAN in face enhancement (#87) When model is set to "auto", CodeFormer failure previously threw an error telling users to manually switch to GFPGAN. Now it falls back to GFPGAN automatically, matching the graceful degradation pattern already used in OCR. --- packages/ai/python/enhance_faces.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/ai/python/enhance_faces.py b/packages/ai/python/enhance_faces.py index c4731c9c..dabbbc70 100644 --- a/packages/ai/python/enhance_faces.py +++ b/packages/ai/python/enhance_faces.py @@ -317,12 +317,11 @@ def main(): model_used = "codeformer" except Exception as e: import traceback - print(f"[enhance-faces] CodeFormer failed: {e}", file=sys.stderr, flush=True) + print(f"[enhance-faces] CodeFormer failed, falling back to GFPGAN: {e}", file=sys.stderr, flush=True) traceback.print_exc(file=sys.stderr) - raise RuntimeError( - f"CodeFormer is not available: {e}. " - "Install the face-enhance feature or use model=gfpgan." - ) from e + emit_progress(50, "Falling back to GFPGAN") + enhanced = enhance_with_gfpgan(img_array, only_center_face) + model_used = "gfpgan" finally: # Restore stdout after ALL AI processing