fix: Make style extraction gracefully handle missing files and URL paths
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user