feat: Update regenerate_frame_image to use MediaService with RunningHub support

This commit is contained in:
empty
2026-01-06 18:11:19 +08:00
parent e29615a885
commit 4b86803692

View File

@@ -450,22 +450,19 @@ async def regenerate_frame_image(
raise HTTPException(status_code=400, detail="No image prompt available") raise HTTPException(status_code=400, detail="No image prompt available")
try: try:
# Import and use PixelleVideo core for image generation # Import and use PixelleVideo core services
from api.dependencies import get_pixelle_video from api.dependencies import get_pixelle_video
from pixelle_video.models.storyboard import StoryboardFrame, StoryboardConfig
pixelle_video = get_pixelle_video() pixelle_video = get_pixelle_video()
# Generate image using ComfyKit # Use MediaService to generate image via RunningHub workflow
result = await pixelle_video.comfy( result = await pixelle_video.image(
workflow="image_gen",
prompt=prompt, prompt=prompt,
task_id=storyboard_id, media_type="image",
) )
if result and result.get("images"): if result and result.url:
# Download and save image # Download and save image
image_url = result["images"][0]
import aiohttp import aiohttp
import os import os
@@ -473,17 +470,26 @@ async def regenerate_frame_image(
os.makedirs(output_dir, exist_ok=True) os.makedirs(output_dir, exist_ok=True)
image_path = f"{output_dir}/frame_{frame_index}_regenerated.png" image_path = f"{output_dir}/frame_{frame_index}_regenerated.png"
# Check if URL is remote or local
if result.url.startswith("http"):
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(image_url) as resp: async with session.get(result.url) as resp:
if resp.status == 200: if resp.status == 200:
with open(image_path, 'wb') as f: with open(image_path, 'wb') as f:
f.write(await resp.read()) f.write(await resp.read())
else:
# Local file, copy it
import shutil
if os.path.exists(result.url):
shutil.copy2(result.url, image_path)
else:
image_path = result.url
# Update frame # Update frame
target_frame["image_path"] = _path_to_url(image_path) target_frame["image_path"] = _path_to_url(image_path)
_storyboard_cache[storyboard_id] = storyboard _storyboard_cache[storyboard_id] = storyboard
logger.info(f"Regenerated image for frame {frame_id}") logger.info(f"Regenerated image for frame {frame_id} via RunningHub")
return RegenerateImageResponse( return RegenerateImageResponse(
image_path=target_frame["image_path"], image_path=target_frame["image_path"],