Update app.py
Browse files
app.py
CHANGED
@@ -51,6 +51,15 @@ def process_selected_videos(selected_videos):
|
|
51 |
# 假資料模擬處理選擇的影片
|
52 |
return f"已選擇的影片: {', '.join(selected_videos)}"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
with gr.Blocks() as demo:
|
55 |
gr.Markdown("# AI Notes Assistant")
|
56 |
|
@@ -59,35 +68,38 @@ with gr.Blocks() as demo:
|
|
59 |
chat_toggle = gr.Checkbox(label="顯示對話區域", value=True)
|
60 |
feature_toggle = gr.Checkbox(label="顯示功能卡片", value=True)
|
61 |
|
62 |
-
with gr.
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
|
67 |
add_file_button = gr.Button("添加到來源列表")
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
gr.
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
|
83 |
|
84 |
-
with gr.
|
85 |
gr.Markdown("### 對話區域")
|
86 |
chatbot = gr.Chatbot(label="聊天記錄", type="messages")
|
87 |
question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
|
88 |
ask_button = gr.Button("提問")
|
89 |
|
90 |
-
with gr.
|
91 |
gr.Markdown("### 功能卡片")
|
92 |
with gr.Tab("摘要生成"):
|
93 |
summary_button = gr.Button("生成摘要")
|
|
|
51 |
# 假資料模擬處理選擇的影片
|
52 |
return f"已選擇的影片: {', '.join(selected_videos)}"
|
53 |
|
54 |
+
def add_youtube_to_list(youtube_link, file_list):
|
55 |
+
if youtube_link:
|
56 |
+
file_list.append(youtube_link)
|
57 |
+
display_list = [os.path.basename(path) if os.path.basename(path) else path for path in file_list]
|
58 |
+
return gr.update(choices=display_list), ""
|
59 |
+
|
60 |
+
def process_all_files(file_list):
|
61 |
+
return f"已處理的文件: {', '.join(file_list)}"
|
62 |
+
|
63 |
with gr.Blocks() as demo:
|
64 |
gr.Markdown("# AI Notes Assistant")
|
65 |
|
|
|
68 |
chat_toggle = gr.Checkbox(label="顯示對話區域", value=True)
|
69 |
feature_toggle = gr.Checkbox(label="顯示功能卡片", value=True)
|
70 |
|
71 |
+
with gr.Column(visible=True) as source_column:
|
72 |
+
gr.Markdown("### 來源選單")
|
73 |
+
|
74 |
+
file_list = gr.State([])
|
75 |
+
|
76 |
+
with gr.Tab("上傳檔案"):
|
77 |
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
|
78 |
add_file_button = gr.Button("添加到來源列表")
|
79 |
+
add_file_button.click(add_to_file_list, inputs=[upload_file, file_list], outputs=[file_list, upload_file])
|
80 |
+
|
81 |
+
with gr.Tab("YouTube 連結"):
|
82 |
+
youtube_link = gr.Textbox(label="輸入 YouTube 連結")
|
83 |
+
add_youtube_button = gr.Button("添加到來源列表")
|
84 |
+
add_youtube_button.click(add_youtube_to_list, inputs=[youtube_link, file_list], outputs=[file_list, youtube_link])
|
85 |
+
|
86 |
+
file_display = gr.CheckboxGroup(label="已上傳的文件", interactive=True)
|
87 |
+
|
88 |
+
process_files_button = gr.Button("處理檔案")
|
89 |
+
rag_result = gr.Textbox(label="處理結果", interactive=False)
|
90 |
+
|
91 |
+
process_files_button.click(process_all_files, inputs=[file_list], outputs=[rag_result])
|
92 |
+
file_list.change(lambda x: gr.update(choices = [os.path.basename(path) if os.path.basename(path) else path for path in x]), inputs=file_list, outputs=file_display)
|
93 |
+
|
94 |
|
95 |
|
96 |
+
with gr.Column(visible=True) as chat_column:
|
97 |
gr.Markdown("### 對話區域")
|
98 |
chatbot = gr.Chatbot(label="聊天記錄", type="messages")
|
99 |
question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
|
100 |
ask_button = gr.Button("提問")
|
101 |
|
102 |
+
with gr.Column(visible=True) as feature_column:
|
103 |
gr.Markdown("### 功能卡片")
|
104 |
with gr.Tab("摘要生成"):
|
105 |
summary_button = gr.Button("生成摘要")
|