Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,15 @@ def mock_sources():
|
|
20 |
# 假資料模擬來源列表
|
21 |
return ["來源一:時間的四則問題", "來源二:新文章"]
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def toggle_visibility(current_state):
|
24 |
return gr.update(visible=not current_state)
|
25 |
|
@@ -34,10 +43,19 @@ with gr.Blocks() as demo:
|
|
34 |
with gr.Row():
|
35 |
with gr.Column(visible=True) as source_column:
|
36 |
gr.Markdown("### 來源選單")
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
with gr.Column(visible=True) as chat_column:
|
43 |
gr.Markdown("### 對話區域")
|
|
|
20 |
# 假資料模擬來源列表
|
21 |
return ["來源一:時間的四則問題", "來源二:新文章"]
|
22 |
|
23 |
+
def add_to_file_list(file, file_list):
|
24 |
+
if file:
|
25 |
+
file_list.append(file.name)
|
26 |
+
return file_list
|
27 |
+
|
28 |
+
def process_selected_files(selected_files):
|
29 |
+
# 假資料模擬處理 RAG
|
30 |
+
return f"已處理的文件: {', '.join(selected_files)}"
|
31 |
+
|
32 |
def toggle_visibility(current_state):
|
33 |
return gr.update(visible=not current_state)
|
34 |
|
|
|
43 |
with gr.Row():
|
44 |
with gr.Column(visible=True) as source_column:
|
45 |
gr.Markdown("### 來源選單")
|
46 |
+
|
47 |
+
file_list = gr.State([])
|
48 |
+
|
49 |
upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
|
50 |
+
add_file_button = gr.Button("添加到來源列表")
|
51 |
+
file_display = gr.CheckboxGroup(label="已上傳的文件", interactive=True)
|
52 |
+
|
53 |
+
add_file_button.click(add_to_file_list, inputs=[upload_file, file_list], outputs=[file_display])
|
54 |
+
|
55 |
+
rag_button = gr.Button("處理選擇的文件")
|
56 |
+
rag_result = gr.Textbox(label="處理結果", interactive=False)
|
57 |
+
|
58 |
+
rag_button.click(process_selected_files, inputs=[file_display], outputs=[rag_result])
|
59 |
|
60 |
with gr.Column(visible=True) as chat_column:
|
61 |
gr.Markdown("### 對話區域")
|