Files
gain/ui_fragments/tab0_data_processing.py
2025-07-22 13:39:46 +08:00

38 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ui_fragments/tab_data_processing.py
import streamlit as st
import callbacks
from project_model import Project # 引入 Project 以便進行型別註記
from utils.helpers import display_operation_status
@st.fragment
def render_tab(project: Project):
"""
負責顯示「資料處理 & AI 加註」Tab 的所有 UI 元件和邏輯。
"""
if "operation_status" in st.session_state:
display_operation_status()
# 根據 project.data 的狀態來決定顯示哪個 UI
if project.data:
# --- 狀態一:專案「已同步」---
# st.toast("✅ 專案資料已就緒。")
with st.container(border=True):
col1, col2 = st.columns([3, 1])
with col1:
st.subheader("專案資料與 AI 加註")
with col2:
st.button("🔄 從 Notion 同步更新", on_click=callbacks.callback_sync_notion)
with st.expander("預覽專案資料", expanded=False):
st.json(project.data)
st.divider()
st.subheader("AI 自動加註")
# ... (AI 加註的按鈕和邏輯) ...
st.button("執行 AI 翻譯與音標加註並寫回 Notion", on_click=callbacks.callback_add_zh_ipa)
else:
# --- 狀態二:專案「僅初始化」---
st.info(" 這個專案的框架已建立,請執行第一步來同步核心資料。")
st.button("🚀 步驟一:從 Notion 抓取專案資料", on_click=callbacks.callback_sync_notion, type="primary")
st.divider()
st.info("✍️ **人工檢查點**\n\n1. 請確保 `Notion` 中的內容是您想要的最終版本。\n2. 修改完成後,記得點擊上方的同步按鈕。")