youngtsai commited on
Commit
b0bbdeb
Β·
verified Β·
1 Parent(s): 5e5253c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import gradio as gr
 
 
2
 
3
  def mock_question_answer(question, history):
4
  # ε‡θ³‡ζ–™ζ¨‘ζ“¬ε›žη­”
@@ -18,12 +20,16 @@ def mock_summary():
18
 
19
  def add_to_file_list(file, file_list):
20
  if file:
21
- file_list.append(file.name)
22
- return file_list, None # 清空文仢選擇摆
23
-
24
- def process_selected_files(selected_files):
 
 
 
 
25
  # 假資料樑擬處理 RAG
26
- return f"ε·²θ™•η†ηš„ζ–‡δ»Ά: {', '.join(selected_files)}"
27
 
28
  def toggle_visibility(current_state):
29
  return gr.update(visible=not current_state)
@@ -51,7 +57,7 @@ with gr.Blocks() as demo:
51
  rag_button = gr.Button("θ™•η†ιΈζ“‡ηš„ζ–‡δ»Ά")
52
  rag_result = gr.Textbox(label="θ™•η†η΅ζžœ", interactive=False)
53
 
54
- rag_button.click(process_selected_files, inputs=[file_display], outputs=[rag_result])
55
 
56
  with gr.Column(visible=True) as chat_column:
57
  gr.Markdown("### ε°θ©±ε€εŸŸ")
 
1
  import gradio as gr
2
+ import os
3
+ import shutil
4
 
5
  def mock_question_answer(question, history):
6
  # ε‡θ³‡ζ–™ζ¨‘ζ“¬ε›žη­”
 
20
 
21
  def add_to_file_list(file, file_list):
22
  if file:
23
+ temp_path = f"/tmp/{file.name}"
24
+ shutil.copy(file.name, temp_path) # ε°‡ζ–‡δ»Άε­˜ε„²εˆ° /tmp
25
+ file_list.append(temp_path)
26
+ display_list = [os.path.basename(path) for path in file_list]
27
+ return gr.update(choices=display_list), None # 清空文仢選擇摆
28
+
29
+ def process_selected_files(selected_files, file_list):
30
+ selected_paths = [path for path in file_list if os.path.basename(path) in selected_files]
31
  # 假資料樑擬處理 RAG
32
+ return f"ε·²θ™•η†ηš„ζ–‡δ»Ά: {', '.join(selected_paths)}"
33
 
34
  def toggle_visibility(current_state):
35
  return gr.update(visible=not current_state)
 
57
  rag_button = gr.Button("θ™•η†ιΈζ“‡ηš„ζ–‡δ»Ά")
58
  rag_result = gr.Textbox(label="θ™•η†η΅ζžœ", interactive=False)
59
 
60
+ rag_button.click(process_selected_files, inputs=[file_display, file_list], outputs=[rag_result])
61
 
62
  with gr.Column(visible=True) as chat_column:
63
  gr.Markdown("### ε°θ©±ε€εŸŸ")