From 4ff3c50cf3ef2e6d61957fab99ed6ae5500d3360 Mon Sep 17 00:00:00 2001 From: puke <1129090915@qq.com> Date: Wed, 10 Dec 2025 16:38:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=A7=E8=BE=B9=E6=A0=8F=E5=86=85=E7=BD=AEFA?= =?UTF-8?q?Q?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/components/faq.py | 96 +++++++++++++++++++++++++++++++++++++ web/i18n/locales/en_US.json | 5 +- web/i18n/locales/zh_CN.json | 5 +- web/pages/1_🎬_Home.py | 4 ++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 web/components/faq.py diff --git a/web/components/faq.py b/web/components/faq.py new file mode 100644 index 0000000..dbf6f78 --- /dev/null +++ b/web/components/faq.py @@ -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)" + ) diff --git a/web/i18n/locales/en_US.json b/web/i18n/locales/en_US.json index 35535a7..9b5d051 100644 --- a/web/i18n/locales/en_US.json +++ b/web/i18n/locales/en_US.json @@ -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?" } } \ No newline at end of file diff --git a/web/i18n/locales/zh_CN.json b/web/i18n/locales/zh_CN.json index 3c1feba..b2d3a16 100644 --- a/web/i18n/locales/zh_CN.json +++ b/web/i18n/locales/zh_CN.json @@ -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": "需要更多帮助?" } } \ No newline at end of file diff --git a/web/pages/1_🎬_Home.py b/web/pages/1_🎬_Home.py index 1b59bef..d3e1d04 100644 --- a/web/pages/1_🎬_Home.py +++ b/web/pages/1_🎬_Home.py @@ -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()