侧边栏内置FAQ
This commit is contained in:
96
web/components/faq.py
Normal file
96
web/components/faq.py
Normal file
@@ -0,0 +1,96 @@
|
||||
# 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.
|
||||
|
||||
"""
|
||||
FAQ component for displaying frequently asked questions
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import streamlit as st
|
||||
from loguru import logger
|
||||
|
||||
from web.i18n import get_language, tr
|
||||
|
||||
|
||||
def load_faq_content(language: str) -> Optional[str]:
|
||||
"""
|
||||
Load FAQ content based on current language
|
||||
|
||||
Args:
|
||||
language: Current language code (e.g., "zh_CN", "en_US")
|
||||
|
||||
Returns:
|
||||
FAQ content as markdown string, or None if file not found
|
||||
"""
|
||||
# Determine which FAQ file to load based on language
|
||||
# For Chinese (zh_CN), use FAQ_CN.md
|
||||
# For all other languages, use FAQ.md (English)
|
||||
project_root = Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
if language.startswith("zh"):
|
||||
faq_file = project_root / "docs" / "FAQ_CN.md"
|
||||
else:
|
||||
faq_file = project_root / "docs" / "FAQ.md"
|
||||
|
||||
try:
|
||||
if faq_file.exists():
|
||||
with open(faq_file, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
logger.debug(f"Loaded FAQ from: {faq_file}")
|
||||
return content
|
||||
else:
|
||||
logger.warning(f"FAQ file not found: {faq_file}")
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load FAQ file {faq_file}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def render_faq_sidebar():
|
||||
"""
|
||||
Render FAQ in the sidebar
|
||||
|
||||
This component displays frequently asked questions in the sidebar,
|
||||
allowing users to quickly find answers without leaving the main interface.
|
||||
"""
|
||||
with st.sidebar:
|
||||
# FAQ header with icon
|
||||
# st.markdown(f"### 🙋♀️ {tr('faq.title', fallback='FAQ')}")
|
||||
|
||||
# Get current language
|
||||
current_language = get_language()
|
||||
|
||||
# Load FAQ content
|
||||
faq_content = load_faq_content(current_language)
|
||||
|
||||
if faq_content:
|
||||
# Display FAQ in an expander, expanded by default
|
||||
with st.expander(tr('faq.expand_to_view', fallback='FAQ'), expanded=True):
|
||||
# Remove the first heading from FAQ content since we already show it above
|
||||
lines = faq_content.split('\n')
|
||||
# Skip the first line if it's a heading
|
||||
if lines and lines[0].startswith('#'):
|
||||
faq_content = '\n'.join(lines[1:])
|
||||
|
||||
# Display FAQ content
|
||||
st.markdown(faq_content, unsafe_allow_html=True)
|
||||
else:
|
||||
# Show error message if FAQ cannot be loaded
|
||||
st.warning(tr('faq.load_error', fallback='Failed to load FAQ content'))
|
||||
|
||||
# Add a link to GitHub issues for more help
|
||||
st.markdown(
|
||||
f"💡 {tr('faq.more_help', fallback='Need more help?')} "
|
||||
f"[GitHub Issues](https://github.com/AIDC-AI/Pixelle-Video/issues)"
|
||||
)
|
||||
@@ -380,6 +380,9 @@
|
||||
"asset_based.progress.analyzing_complete": "✅ Asset analysis complete ({count} total)",
|
||||
"asset_based.progress.generating_script": "📝 Generating video script...",
|
||||
"asset_based.progress.script_complete": "✅ Script generation complete",
|
||||
"asset_based.progress.concat_complete": "✅ Video concatenation complete"
|
||||
"asset_based.progress.concat_complete": "✅ Video concatenation complete",
|
||||
"faq.expand_to_view": "FAQ",
|
||||
"faq.load_error": "Failed to load FAQ content",
|
||||
"faq.more_help": "Need more help?"
|
||||
}
|
||||
}
|
||||
@@ -380,6 +380,9 @@
|
||||
"asset_based.progress.analyzing_complete": "✅ 素材分析完成(共 {count} 个)",
|
||||
"asset_based.progress.generating_script": "📝 正在生成视频脚本...",
|
||||
"asset_based.progress.script_complete": "✅ 脚本生成完成",
|
||||
"asset_based.progress.concat_complete": "✅ 视频合成完成"
|
||||
"asset_based.progress.concat_complete": "✅ 视频合成完成",
|
||||
"faq.expand_to_view": "常见问题",
|
||||
"faq.load_error": "无法加载常见问题内容",
|
||||
"faq.more_help": "需要更多帮助?"
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ from web.state.session import init_session_state, init_i18n, get_pixelle_video
|
||||
# Import components
|
||||
from web.components.header import render_header
|
||||
from web.components.settings import render_advanced_settings
|
||||
from web.components.faq import render_faq_sidebar
|
||||
|
||||
# Page config
|
||||
st.set_page_config(
|
||||
@@ -50,6 +51,9 @@ def main():
|
||||
# Render header (title + language selector)
|
||||
render_header()
|
||||
|
||||
# Render FAQ in sidebar
|
||||
render_faq_sidebar()
|
||||
|
||||
# Initialize Pixelle-Video
|
||||
pixelle_video = get_pixelle_video()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user