youngtsai commited on
Commit
e501f08
·
verified ·
1 Parent(s): b0bbdeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import os
3
  import shutil
 
4
 
5
  def mock_question_answer(question, history):
6
  # 假資料模擬回答
@@ -20,8 +21,9 @@ def mock_summary():
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 # 清空文件選擇框
@@ -32,7 +34,7 @@ def process_selected_files(selected_files, file_list):
32
  return f"已處理的文件: {', '.join(selected_paths)}"
33
 
34
  def toggle_visibility(current_state):
35
- return gr.update(visible=not current_state)
36
 
37
  with gr.Blocks() as demo:
38
  gr.Markdown("# AI Notes Assistant")
 
1
  import gradio as gr
2
  import os
3
  import shutil
4
+ import tempfile
5
 
6
  def mock_question_answer(question, history):
7
  # 假資料模擬回答
 
21
 
22
  def add_to_file_list(file, file_list):
23
  if file:
24
+ temp_dir = tempfile.gettempdir()
25
+ temp_path = os.path.join(temp_dir, os.path.basename(file.name))
26
+ shutil.copy(file.name, temp_path) # 將文件存儲到臨時目錄
27
  file_list.append(temp_path)
28
  display_list = [os.path.basename(path) for path in file_list]
29
  return gr.update(choices=display_list), None # 清空文件選擇框
 
34
  return f"已處理的文件: {', '.join(selected_paths)}"
35
 
36
  def toggle_visibility(current_state):
37
+ return gr.update(visible=not current_state), not current_state
38
 
39
  with gr.Blocks() as demo:
40
  gr.Markdown("# AI Notes Assistant")