youngtsai commited on
Commit
7377ef6
·
1 Parent(s): a094471
Files changed (1) hide show
  1. app.py +36 -37
app.py CHANGED
@@ -68,44 +68,43 @@ with gr.Blocks() as demo:
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("生成摘要")
106
- summary = gr.Textbox(label="摘要", interactive=False)
107
- with gr.Tab("其他功能"):
108
- gr.Markdown("此處可以添加更多功能卡片")
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  source_toggle.change(toggle_visibility, inputs=source_toggle, outputs=source_column)
111
  chat_toggle.change(toggle_visibility, inputs=chat_toggle, outputs=chat_column)
 
68
  chat_toggle = gr.Checkbox(label="顯示對話區域", value=True)
69
  feature_toggle = gr.Checkbox(label="顯示功能卡片", value=True)
70
 
71
+ with gr.Row():
72
+ with gr.Column(visible=True) as source_column:
73
+ gr.Markdown("### 來源選單")
74
+
75
+ file_list = gr.State([])
76
+
77
+ with gr.Tab("上傳檔案"):
78
+ upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
79
+ add_file_button = gr.Button("添加到來源列表")
80
+ add_file_button.click(add_to_file_list, inputs=[upload_file, file_list], outputs=[file_list, upload_file])
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ with gr.Tab("YouTube 連結"):
83
+ youtube_link = gr.Textbox(label="輸入 YouTube 連結")
84
+ add_youtube_button = gr.Button("添加到來源列表")
85
+ add_youtube_button.click(add_youtube_to_list, inputs=[youtube_link, file_list], outputs=[file_list, youtube_link])
86
+
87
+ file_display = gr.CheckboxGroup(label="已上傳的文件", interactive=True)
88
+
89
+ process_files_button = gr.Button("處理檔案")
90
+ rag_result = gr.Textbox(label="處理結果", interactive=False)
91
+
92
+ process_files_button.click(process_all_files, inputs=[file_list], outputs=[rag_result])
93
+ 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)
94
+
95
+ with gr.Column(visible=True) as chat_column:
96
+ gr.Markdown("### 對話區域")
97
+ chatbot = gr.Chatbot(label="聊天記錄", type="messages")
98
+ question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
99
+ ask_button = gr.Button("提問")
100
+
101
+ with gr.Column(visible=True) as feature_column:
102
+ gr.Markdown("### 功能卡片")
103
+ with gr.Tab("摘要生成"):
104
+ summary_button = gr.Button("生成摘要")
105
+ summary = gr.Textbox(label="摘要", interactive=False)
106
+ with gr.Tab("其他功能"):
107
+ gr.Markdown("此處可以添加更多功能卡片")
108
 
109
  source_toggle.change(toggle_visibility, inputs=source_toggle, outputs=source_column)
110
  chat_toggle.change(toggle_visibility, inputs=chat_toggle, outputs=chat_column)