youngtsai commited on
Commit
da05110
·
verified ·
1 Parent(s): ff365f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -20
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.Row(visible=True) as source_column:
63
- with gr.Tab("檔案來源"):
64
- file_list = gr.State([])
65
- with gr.Row():
 
 
66
  upload_file = gr.File(label="從電腦添加文件", file_types=[".txt", ".pdf", ".docx"])
67
  add_file_button = gr.Button("添加到來源列表")
68
- file_display = gr.CheckboxGroup(label="已上傳的文件", interactive=True)
69
- add_file_button.click(add_to_file_list, inputs=[upload_file, file_list], outputs=[file_display, upload_file])
70
- rag_button = gr.Button("處理選擇的文件")
71
- rag_result = gr.Textbox(label="處理結果", interactive=False)
72
- rag_button.click(process_selected_files, inputs=[file_display, file_list], outputs=[rag_result])
73
-
74
- with gr.Tab("YouTube來源"):
75
- gr.Markdown("### YouTube 播放清單")
76
- youtube_data = get_youtube_playlist()
77
- youtube_choices = format_youtube_choices(youtube_data)
78
- youtube_videos = gr.CheckboxGroup(choices=youtube_choices, label="可選擇的影片", interactive=True)
79
- process_videos_button = gr.Button("處理選擇的影片")
80
- video_result = gr.Textbox(label="影片處理結果", interactive=False)
81
- process_videos_button.click(process_selected_videos, inputs=[youtube_videos], outputs=[video_result])
 
82
 
83
 
84
- with gr.Row(visible=True) as chat_column:
85
  gr.Markdown("### 對話區域")
86
  chatbot = gr.Chatbot(label="聊天記錄", type="messages")
87
  question = gr.Textbox(label="輸入問題,例如:文件的核心觀點是什麼?")
88
  ask_button = gr.Button("提問")
89
 
90
- with gr.Row(visible=True) as feature_column:
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("生成摘要")