Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,9 @@ def mock_question_answer(question, history):
|
|
8 |
"文件的摘要是什麼?": "這份文件討論了如何利用人工智慧工具,提升企業的運營效率和決策速度。"
|
9 |
}
|
10 |
response = answers.get(question, "抱歉,我無法回答這個問題。請嘗試其他問題!")
|
11 |
-
history.append(
|
12 |
-
|
|
|
13 |
|
14 |
def mock_summary():
|
15 |
# 假資料模擬摘要
|
@@ -19,24 +20,27 @@ def mock_sources():
|
|
19 |
# 假資料模擬來源列表
|
20 |
return ["來源一:時間的四則問題", "來源二:新文章"]
|
21 |
|
|
|
|
|
|
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("# AI Notes Assistant")
|
24 |
|
25 |
with gr.Row():
|
26 |
-
with gr.Column() as source_column:
|
27 |
gr.Markdown("### 來源選單")
|
28 |
sources = gr.CheckboxGroup(
|
29 |
choices=mock_sources(), label="選取所有來源", interactive=True
|
30 |
)
|
31 |
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
|
32 |
|
33 |
-
with gr.Column() as chat_column:
|
34 |
gr.Markdown("### 對話區域")
|
35 |
-
chatbot = gr.Chatbot(label="聊天記錄")
|
36 |
question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
|
37 |
ask_button = gr.Button("提問")
|
38 |
|
39 |
-
with gr.Column() as feature_column:
|
40 |
gr.Markdown("### 功能卡片")
|
41 |
with gr.Tab("摘要生成"):
|
42 |
summary_button = gr.Button("生成摘要")
|
@@ -50,13 +54,13 @@ with gr.Blocks() as demo:
|
|
50 |
toggle_features = gr.Button("顯示/隱藏 功能卡片")
|
51 |
|
52 |
history = gr.State([])
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
toggle_sources.click(toggle_visibility, inputs=[source_column.visible], outputs=[source_column])
|
58 |
-
toggle_chat.click(toggle_visibility, inputs=[chat_column.visible], outputs=[chat_column])
|
59 |
-
toggle_features.click(toggle_visibility, inputs=[feature_column.visible], outputs=[feature_column])
|
60 |
|
61 |
ask_button.click(mock_question_answer, inputs=[question, history], outputs=[chatbot, chatbot])
|
62 |
summary_button.click(mock_summary, inputs=[], outputs=[summary])
|
|
|
8 |
"文件的摘要是什麼?": "這份文件討論了如何利用人工智慧工具,提升企業的運營效率和決策速度。"
|
9 |
}
|
10 |
response = answers.get(question, "抱歉,我無法回答這個問題。請嘗試其他問題!")
|
11 |
+
history.append({"role": "user", "content": question})
|
12 |
+
history.append({"role": "assistant", "content": response})
|
13 |
+
return history, ""
|
14 |
|
15 |
def mock_summary():
|
16 |
# 假資料模擬摘要
|
|
|
20 |
# 假資料模擬來源列表
|
21 |
return ["來源一:時間的四則問題", "來源二:新文章"]
|
22 |
|
23 |
+
def toggle_visibility(visible_state):
|
24 |
+
return not visible_state
|
25 |
+
|
26 |
with gr.Blocks() as demo:
|
27 |
gr.Markdown("# AI Notes Assistant")
|
28 |
|
29 |
with gr.Row():
|
30 |
+
with gr.Column(visible=True) as source_column:
|
31 |
gr.Markdown("### 來源選單")
|
32 |
sources = gr.CheckboxGroup(
|
33 |
choices=mock_sources(), label="選取所有來源", interactive=True
|
34 |
)
|
35 |
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
|
36 |
|
37 |
+
with gr.Column(visible=True) as chat_column:
|
38 |
gr.Markdown("### 對話區域")
|
39 |
+
chatbot = gr.Chatbot(label="聊天記錄", type="messages")
|
40 |
question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
|
41 |
ask_button = gr.Button("提問")
|
42 |
|
43 |
+
with gr.Column(visible=True) as feature_column:
|
44 |
gr.Markdown("### 功能卡片")
|
45 |
with gr.Tab("摘要生成"):
|
46 |
summary_button = gr.Button("生成摘要")
|
|
|
54 |
toggle_features = gr.Button("顯示/隱藏 功能卡片")
|
55 |
|
56 |
history = gr.State([])
|
57 |
+
source_visible = gr.State(True)
|
58 |
+
chat_visible = gr.State(True)
|
59 |
+
feature_visible = gr.State(True)
|
60 |
|
61 |
+
toggle_sources.click(toggle_visibility, inputs=source_visible, outputs=source_column.visible)
|
62 |
+
toggle_chat.click(toggle_visibility, inputs=chat_visible, outputs=chat_column.visible)
|
63 |
+
toggle_features.click(toggle_visibility, inputs=feature_visible, outputs=feature_column.visible)
|
|
|
|
|
|
|
64 |
|
65 |
ask_button.click(mock_question_answer, inputs=[question, history], outputs=[chatbot, chatbot])
|
66 |
summary_button.click(mock_summary, inputs=[], outputs=[summary])
|