feat: Update regenerate_frame_image to use MediaService with RunningHub support
This commit is contained in:
@@ -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"
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
# Check if URL is remote or local
|
||||||
async with session.get(image_url) as resp:
|
if result.url.startswith("http"):
|
||||||
if resp.status == 200:
|
async with aiohttp.ClientSession() as session:
|
||||||
with open(image_path, 'wb') as f:
|
async with session.get(result.url) as resp:
|
||||||
f.write(await resp.read())
|
if resp.status == 200:
|
||||||
|
with open(image_path, 'wb') as f:
|
||||||
|
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"],
|
||||||
|
|||||||
Reference in New Issue
Block a user