移除streamlit缓存; 优化并行逻辑;
This commit is contained in:
@@ -10,7 +10,7 @@ import httpx
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from reelforge.models.progress import ProgressEvent
|
from reelforge.models.progress import ProgressEvent
|
||||||
from reelforge.models.storyboard import StoryboardFrame, StoryboardConfig
|
from reelforge.models.storyboard import Storyboard, StoryboardFrame, StoryboardConfig
|
||||||
from reelforge.utils.os_util import get_temp_path
|
from reelforge.utils.os_util import get_temp_path
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ class StoryboardProcessorService:
|
|||||||
async def process_frame(
|
async def process_frame(
|
||||||
self,
|
self,
|
||||||
frame: StoryboardFrame,
|
frame: StoryboardFrame,
|
||||||
|
storyboard: 'Storyboard',
|
||||||
config: StoryboardConfig,
|
config: StoryboardConfig,
|
||||||
total_frames: int = 1,
|
total_frames: int = 1,
|
||||||
progress_callback: Optional[Callable[[ProgressEvent], None]] = None
|
progress_callback: Optional[Callable[[ProgressEvent], None]] = None
|
||||||
@@ -81,7 +82,7 @@ class StoryboardProcessorService:
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Step 3: Compose frame (add subtitle)
|
# Step 3: Compose frame (add subtitle)
|
||||||
await self._step_compose_frame(frame, config)
|
await self._step_compose_frame(frame, storyboard, config)
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
progress_callback(ProgressEvent(
|
progress_callback(ProgressEvent(
|
||||||
event_type="frame_step",
|
event_type="frame_step",
|
||||||
@@ -157,6 +158,7 @@ class StoryboardProcessorService:
|
|||||||
async def _step_compose_frame(
|
async def _step_compose_frame(
|
||||||
self,
|
self,
|
||||||
frame: StoryboardFrame,
|
frame: StoryboardFrame,
|
||||||
|
storyboard: 'Storyboard',
|
||||||
config: StoryboardConfig
|
config: StoryboardConfig
|
||||||
):
|
):
|
||||||
"""Step 3: Compose frame with subtitle"""
|
"""Step 3: Compose frame with subtitle"""
|
||||||
@@ -167,7 +169,7 @@ class StoryboardProcessorService:
|
|||||||
# Choose frame generator based on template config
|
# Choose frame generator based on template config
|
||||||
if config.frame_template:
|
if config.frame_template:
|
||||||
# Use HTML template
|
# Use HTML template
|
||||||
composed_path = await self._compose_frame_html(frame, config, output_path)
|
composed_path = await self._compose_frame_html(frame, storyboard, config, output_path)
|
||||||
else:
|
else:
|
||||||
# Use PIL (default)
|
# Use PIL (default)
|
||||||
composed_path = await self._compose_frame_pil(frame, config, output_path)
|
composed_path = await self._compose_frame_pil(frame, config, output_path)
|
||||||
@@ -194,6 +196,7 @@ class StoryboardProcessorService:
|
|||||||
async def _compose_frame_html(
|
async def _compose_frame_html(
|
||||||
self,
|
self,
|
||||||
frame: StoryboardFrame,
|
frame: StoryboardFrame,
|
||||||
|
storyboard: 'Storyboard',
|
||||||
config: StoryboardConfig,
|
config: StoryboardConfig,
|
||||||
output_path: str
|
output_path: str
|
||||||
) -> str:
|
) -> str:
|
||||||
@@ -215,8 +218,7 @@ class StoryboardProcessorService:
|
|||||||
f"Built-in templates: default.html, modern.html, neon.html"
|
f"Built-in templates: default.html, modern.html, neon.html"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get storyboard for content metadata
|
# Get content metadata from storyboard
|
||||||
storyboard = getattr(self.core, '_current_storyboard', None)
|
|
||||||
content_metadata = storyboard.content_metadata if storyboard else None
|
content_metadata = storyboard.content_metadata if storyboard else None
|
||||||
|
|
||||||
# Build ext data
|
# Build ext data
|
||||||
@@ -230,7 +232,7 @@ class StoryboardProcessorService:
|
|||||||
# Generate frame using HTML
|
# Generate frame using HTML
|
||||||
generator = HTMLFrameGenerator(str(template_path))
|
generator = HTMLFrameGenerator(str(template_path))
|
||||||
composed_path = await generator.generate_frame(
|
composed_path = await generator.generate_frame(
|
||||||
topic=storyboard.topic if storyboard else "",
|
topic=storyboard.topic,
|
||||||
text=frame.narration,
|
text=frame.narration,
|
||||||
image=frame.image_path,
|
image=frame.image_path,
|
||||||
ext=ext,
|
ext=ext,
|
||||||
|
|||||||
@@ -227,9 +227,6 @@ class VideoGeneratorService:
|
|||||||
created_at=datetime.now()
|
created_at=datetime.now()
|
||||||
)
|
)
|
||||||
|
|
||||||
# Store storyboard in core for access in storyboard processor
|
|
||||||
self.core._current_storyboard = storyboard
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# ========== Step 1: Generate/Split narrations ==========
|
# ========== Step 1: Generate/Split narrations ==========
|
||||||
if mode == "generate":
|
if mode == "generate":
|
||||||
@@ -330,6 +327,7 @@ class VideoGeneratorService:
|
|||||||
|
|
||||||
processed_frame = await self.core.storyboard_processor.process_frame(
|
processed_frame = await self.core.storyboard_processor.process_frame(
|
||||||
frame=frame,
|
frame=frame,
|
||||||
|
storyboard=storyboard,
|
||||||
config=config,
|
config=config,
|
||||||
total_frames=len(storyboard.frames),
|
total_frames=len(storyboard.frames),
|
||||||
progress_callback=frame_progress_callback
|
progress_callback=frame_progress_callback
|
||||||
|
|||||||
9
web.py
9
web.py
@@ -52,9 +52,8 @@ def safe_rerun():
|
|||||||
# Configuration & i18n Initialization
|
# Configuration & i18n Initialization
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
@st.cache_resource
|
|
||||||
def get_config_manager():
|
def get_config_manager():
|
||||||
"""Get ConfigManager instance (cached)"""
|
"""Get ConfigManager instance (no caching - always fresh)"""
|
||||||
manager = ConfigManager()
|
manager = ConfigManager()
|
||||||
manager.load_or_create_default()
|
manager.load_or_create_default()
|
||||||
return manager
|
return manager
|
||||||
@@ -109,12 +108,12 @@ def generate_style_preview_cached(prompt_prefix: str):
|
|||||||
# Initialize ReelForge
|
# Initialize ReelForge
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
@st.cache_resource
|
|
||||||
def get_reelforge():
|
def get_reelforge():
|
||||||
"""Get initialized ReelForge instance (cached)"""
|
"""Get initialized ReelForge instance (no caching - always fresh)"""
|
||||||
from reelforge.service import reelforge
|
from reelforge.service import ReelForgeCore
|
||||||
|
|
||||||
logger.info("Initializing ReelForge...")
|
logger.info("Initializing ReelForge...")
|
||||||
|
reelforge = ReelForgeCore()
|
||||||
run_async(reelforge.initialize())
|
run_async(reelforge.initialize())
|
||||||
logger.info("ReelForge initialized")
|
logger.info("ReelForge initialized")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user