重构pipeline的UI架构,支持后续pipeline的动态拓展
This commit is contained in:
35
web/pipelines/__init__.py
Normal file
35
web/pipelines/__init__.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Copyright (C) 2025 AIDC-AI
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Pipeline UI Package
|
||||
|
||||
Exports registry functions and automatically registers available pipelines.
|
||||
"""
|
||||
|
||||
from web.pipelines.base import (
|
||||
PipelineUI,
|
||||
register_pipeline_ui,
|
||||
get_pipeline_ui,
|
||||
get_all_pipeline_uis
|
||||
)
|
||||
|
||||
# Import all pipeline UI modules to ensure they register themselves
|
||||
from web.pipelines import standard
|
||||
from web.pipelines import demo
|
||||
|
||||
__all__ = [
|
||||
"PipelineUI",
|
||||
"register_pipeline_ui",
|
||||
"get_pipeline_ui",
|
||||
"get_all_pipeline_uis"
|
||||
]
|
||||
57
web/pipelines/base.py
Normal file
57
web/pipelines/base.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# Copyright (C) 2025 AIDC-AI
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Pipeline UI Base & Registry
|
||||
|
||||
Defines the PipelineUI protocol and the registration mechanism.
|
||||
"""
|
||||
|
||||
from typing import Dict, Any, List, Type
|
||||
|
||||
class PipelineUI:
|
||||
"""
|
||||
Base class for Pipeline UI plugins.
|
||||
|
||||
Each pipeline should implement a subclass to define its own full-page UI.
|
||||
"""
|
||||
name: str = "base"
|
||||
display_name: str = "Base Pipeline"
|
||||
icon: str = "🔌"
|
||||
description: str = ""
|
||||
|
||||
def render(self, pixelle_video: Any):
|
||||
"""
|
||||
Render the full page content for this pipeline (below settings).
|
||||
|
||||
Args:
|
||||
pixelle_video: The initialized PixelleVideoCore instance.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
# ==================== Registry ====================
|
||||
|
||||
_pipeline_uis: Dict[str, PipelineUI] = {}
|
||||
|
||||
def register_pipeline_ui(ui_class: Type[PipelineUI]):
|
||||
"""Register a pipeline UI class"""
|
||||
instance = ui_class()
|
||||
_pipeline_uis[instance.name] = instance
|
||||
|
||||
def get_pipeline_ui(name: str) -> PipelineUI:
|
||||
"""Get a pipeline UI instance by name"""
|
||||
return _pipeline_uis.get(name)
|
||||
|
||||
def get_all_pipeline_uis() -> List[PipelineUI]:
|
||||
"""Get all registered pipeline UI instances"""
|
||||
return list(_pipeline_uis.values())
|
||||
69
web/pipelines/demo.py
Normal file
69
web/pipelines/demo.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# Copyright (C) 2025 AIDC-AI
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Demo Pipeline UI
|
||||
|
||||
Implements a custom layout for the Demo Pipeline.
|
||||
"""
|
||||
|
||||
import streamlit as st
|
||||
from typing import Any
|
||||
from web.i18n import tr
|
||||
|
||||
from web.pipelines.base import PipelineUI, register_pipeline_ui
|
||||
|
||||
|
||||
class DemoPipelineUI(PipelineUI):
|
||||
"""
|
||||
Demo UI to verify the full-page plugin system.
|
||||
Uses a completely different layout (2 columns).
|
||||
"""
|
||||
name = "demo"
|
||||
icon = "✨"
|
||||
|
||||
@property
|
||||
def display_name(self):
|
||||
return tr("pipeline.demo.name")
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return tr("pipeline.demo.description")
|
||||
|
||||
def render(self, pixelle_video: Any):
|
||||
st.markdown("### ✨ Demo Pipeline Custom Layout")
|
||||
st.info("This pipeline uses a custom 2-column layout, demonstrating full UI control.")
|
||||
|
||||
col1, col2 = st.columns([2, 1])
|
||||
|
||||
with col1:
|
||||
with st.container(border=True):
|
||||
st.subheader("1. Input")
|
||||
topic = st.text_input("Enter Topic", placeholder="e.g. AI News")
|
||||
mood = st.selectbox("Mood", ["Happy", "Serious", "Funny"])
|
||||
|
||||
st.markdown("---")
|
||||
st.subheader("2. Settings")
|
||||
# Simplified settings for demo
|
||||
n_scenes = st.slider("Scenes", 3, 10, 5)
|
||||
|
||||
with col2:
|
||||
with st.container(border=True):
|
||||
st.subheader("3. Generate")
|
||||
if st.button("🚀 Generate Demo Video", type="primary", use_container_width=True):
|
||||
# Mock generation logic or call backend
|
||||
st.success(f"Generating video for '{topic}' ({mood}) with {n_scenes} scenes...")
|
||||
st.balloons()
|
||||
|
||||
|
||||
# Register self
|
||||
register_pipeline_ui(DemoPipelineUI)
|
||||
84
web/pipelines/standard.py
Normal file
84
web/pipelines/standard.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# Copyright (C) 2025 AIDC-AI
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""
|
||||
Standard Pipeline UI
|
||||
|
||||
Implements the classic 3-column layout for the Standard Pipeline.
|
||||
"""
|
||||
|
||||
import streamlit as st
|
||||
from typing import Any
|
||||
from web.i18n import tr
|
||||
|
||||
from web.pipelines.base import PipelineUI, register_pipeline_ui
|
||||
|
||||
# Import components
|
||||
from web.components.content_input import render_content_input, render_bgm_section, render_version_info
|
||||
from web.components.style_config import render_style_config
|
||||
from web.components.output_preview import render_output_preview
|
||||
|
||||
|
||||
class StandardPipelineUI(PipelineUI):
|
||||
"""
|
||||
UI for the Standard Video Generation Pipeline.
|
||||
Implements the classic 3-column layout.
|
||||
"""
|
||||
name = "standard"
|
||||
icon = "🎬"
|
||||
|
||||
@property
|
||||
def display_name(self):
|
||||
return tr("pipeline.standard.name")
|
||||
|
||||
def render(self, pixelle_video: Any):
|
||||
# Three-column layout
|
||||
left_col, middle_col, right_col = st.columns([1, 1, 1])
|
||||
|
||||
# ====================================================================
|
||||
# Left Column: Content Input & BGM
|
||||
# ====================================================================
|
||||
with left_col:
|
||||
# Content input (mode, text, title, n_scenes)
|
||||
content_params = render_content_input()
|
||||
|
||||
# BGM selection (bgm_path, bgm_volume)
|
||||
bgm_params = render_bgm_section()
|
||||
|
||||
# Version info & GitHub link
|
||||
render_version_info()
|
||||
|
||||
# ====================================================================
|
||||
# Middle Column: Style Configuration
|
||||
# ====================================================================
|
||||
with middle_col:
|
||||
# Style configuration (TTS, template, workflow, etc.)
|
||||
style_params = render_style_config(pixelle_video)
|
||||
|
||||
# ====================================================================
|
||||
# Right Column: Output Preview
|
||||
# ====================================================================
|
||||
with right_col:
|
||||
# Combine all parameters
|
||||
video_params = {
|
||||
"pipeline": self.name,
|
||||
**content_params,
|
||||
**bgm_params,
|
||||
**style_params
|
||||
}
|
||||
|
||||
# Render output preview (generate button, progress, video preview)
|
||||
render_output_preview(pixelle_video, video_params)
|
||||
|
||||
|
||||
# Register self
|
||||
register_pipeline_ui(StandardPipelineUI)
|
||||
Reference in New Issue
Block a user