File size: 3,115 Bytes
b55d531 9ddb9de b55d531 9ddb9de 7ed7122 b55d531 7461ece 48312c4 7ed7122 b55d531 f3231bf b55d531 7ed7122 7461ece 5d603eb 7461ece 7ed7122 7461ece 7ed7122 9ddb9de 7461ece 7ed7122 7461ece b55d531 48312c4 5737001 48312c4 5737001 48312c4 9ddb9de b55d531 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import gradio as gr
def mock_question_answer(question, history):
# 假資料模擬回答
answers = {
"文件的核心觀點是什麼?": "這份文件的核心觀點是關於人工智慧如何提升工作效率。",
"有哪些關鍵詞或數據?": "關鍵詞包括:人工智慧、工作效率、數據分析。",
"文件的摘要是什麼?": "這份文件討論了如何利用人工智慧工具,提升企業的運營效率和決策速度。"
}
response = answers.get(question, "抱歉,我無法回答這個問題。請嘗試其他問題!")
history.append({"role": "user", "content": question})
history.append({"role": "assistant", "content": response})
return history, ""
def mock_summary():
# 假資料模擬摘要
return "這份文件主要討論人工智慧在工作效率提升方面的應用,並提供了實際案例來說明其價值。"
def mock_sources():
# 假資料模擬來源列表
return ["來源一:時間的四則問題", "來源二:新文章"]
def toggle_visibility(current_state):
return gr.update(visible=not current_state)
with gr.Blocks() as demo:
gr.Markdown("# AI Notes Assistant")
with gr.Row():
toggle_sources = gr.Button("顯示/隱藏 來源選單")
toggle_chat = gr.Button("顯示/隱藏 對話區域")
toggle_features = gr.Button("顯示/隱藏 功能卡片")
with gr.Row():
with gr.Column(visible=True) as source_column:
gr.Markdown("### 來源選單")
sources = gr.CheckboxGroup(
choices=mock_sources(), label="選取所有來源", interactive=True
)
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
with gr.Column(visible=True) as chat_column:
gr.Markdown("### 對話區域")
chatbot = gr.Chatbot(label="聊天記錄", type="messages")
question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
ask_button = gr.Button("提問")
with gr.Column(visible=True) as feature_column:
gr.Markdown("### 功能卡片")
with gr.Tab("摘要生成"):
summary_button = gr.Button("生成摘要")
summary = gr.Textbox(label="摘要", interactive=False)
with gr.Tab("其他功能"):
gr.Markdown("此處可以添加更多功能卡片")
source_visible = gr.State(True)
chat_visible = gr.State(True)
feature_visible = gr.State(True)
toggle_sources.click(toggle_visibility, inputs=source_visible, outputs=[source_column, source_visible])
toggle_chat.click(toggle_visibility, inputs=chat_visible, outputs=[chat_column, chat_visible])
toggle_features.click(toggle_visibility, inputs=feature_visible, outputs=[feature_column, feature_visible])
history = gr.State([])
ask_button.click(mock_question_answer, inputs=[question, history], outputs=[chatbot, chatbot])
summary_button.click(mock_summary, inputs=[], outputs=[summary])
demo.launch()
|