From ba96a598222dd1058f2918e00c4149c367f39d56 Mon Sep 17 00:00:00 2001 From: empty Date: Tue, 6 Jan 2026 17:44:39 +0800 Subject: [PATCH] fix: Make style extraction gracefully handle missing files and URL paths --- api/routers/quality.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/api/routers/quality.py b/api/routers/quality.py index 9881be5..6dc5e5f 100644 --- a/api/routers/quality.py +++ b/api/routers/quality.py @@ -230,11 +230,33 @@ async def extract_style( image_path: str = Body(..., embed=True, description="Reference image path") ): """Extract style anchor from reference image""" - from pixelle_video.services.quality.style_guard import StyleGuard - try: + # Convert URL to file path if needed + actual_path = image_path + if image_path.startswith("http"): + # Extract path from URL like http://localhost:8000/api/files/... + actual_path = image_path.replace("http://localhost:8000/api/files/", "output/") + + # Check if file exists + import os + if not os.path.exists(actual_path): + logger.warning(f"Image file not found: {actual_path}, using default style") + # Return default style instead of failing + style_schema = StyleAnchorSchema( + color_palette="vibrant", + art_style="digital illustration", + composition_style="centered", + texture="smooth", + lighting="soft natural light", + style_prefix="high quality, detailed, vibrant colors", + ) + _style_anchors[storyboard_id] = style_schema.model_dump() + return style_schema + + from pixelle_video.services.quality.style_guard import StyleGuard + style_guard = StyleGuard() - anchor = style_guard.extract_style_anchor(image_path) + anchor = style_guard.extract_style_anchor(actual_path) style_schema = StyleAnchorSchema( color_palette=anchor.color_palette, @@ -253,7 +275,17 @@ async def extract_style( except Exception as e: logger.error(f"Style extraction failed: {e}") - raise HTTPException(status_code=500, detail=str(e)) + # Return default style instead of failing + style_schema = StyleAnchorSchema( + color_palette="vibrant", + art_style="digital illustration", + composition_style="centered", + texture="smooth", + lighting="soft natural light", + style_prefix="high quality, detailed", + ) + _style_anchors[storyboard_id] = style_schema.model_dump() + return style_schema @router.get(