Tuchuanhuhuhu commited on
Commit
e5adc30
1 Parent(s): ba32a82

feat: 将上传历史的组件从 File 改成UploadButton

Browse files
ChuanhuChatbot.py CHANGED
@@ -102,8 +102,8 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
102
  i18n("📝 Export as Markdown"), elem_id="gr-markdown-export-btn")
103
  with gr.Row():
104
  with gr.Column():
105
- downloadFile = gr.File(
106
- interactive=True, label=i18n("下载/上传历史记录"))
107
 
108
  with gr.Column(elem_id="chuanhu-menu-footer"):
109
  with gr.Row(elem_id="chuanhu-func-nav"):
@@ -662,8 +662,8 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
662
  _js='clearChatbot',
663
  )
664
  historySelectList.input(**load_history_from_file_args)
665
- downloadFile.change(upload_chat_history, [current_model, downloadFile, user_name], [
666
- saveFileName, systemPromptTxt, chatbot])
667
  historyDownloadBtn.click(None, [
668
  user_name, historySelectList], None, _js='(a,b)=>{return downloadHistory(a,b,".json");}')
669
  historyMarkdownDownloadBtn.click(None, [
 
102
  i18n("📝 Export as Markdown"), elem_id="gr-markdown-export-btn")
103
  with gr.Row():
104
  with gr.Column():
105
+ uploadFileBtn = gr.UploadButton(
106
+ interactive=True, label=i18n("Upload Chat History (.json)"), file_types=[".json"])
107
 
108
  with gr.Column(elem_id="chuanhu-menu-footer"):
109
  with gr.Row(elem_id="chuanhu-func-nav"):
 
662
  _js='clearChatbot',
663
  )
664
  historySelectList.input(**load_history_from_file_args)
665
+ uploadFileBtn.upload(upload_chat_history, [current_model, uploadFileBtn, user_name], [
666
+ saveFileName, systemPromptTxt, chatbot]).then(**refresh_history_args)
667
  historyDownloadBtn.click(None, [
668
  user_name, historySelectList], None, _js='(a,b)=>{return downloadHistory(a,b,".json");}')
669
  historyMarkdownDownloadBtn.click(None, [
modules/models/base_model.py CHANGED
@@ -10,6 +10,7 @@ import requests
10
  import urllib3
11
  import traceback
12
  import pathlib
 
13
 
14
  from tqdm import tqdm
15
  import colorama
@@ -686,7 +687,11 @@ class BaseLLMModel:
686
  logging.debug(f"{self.user_identifier} 加载对话历史中……")
687
  if new_history_file_path is not None:
688
  if type(new_history_file_path) != str:
689
- self.history_file_path = new_history_file_path.name
 
 
 
 
690
  else:
691
  self.history_file_path = new_history_file_path
692
  try:
 
10
  import urllib3
11
  import traceback
12
  import pathlib
13
+ import shutil
14
 
15
  from tqdm import tqdm
16
  import colorama
 
687
  logging.debug(f"{self.user_identifier} 加载对话历史中……")
688
  if new_history_file_path is not None:
689
  if type(new_history_file_path) != str:
690
+ # copy file from new_history_file_path.name to os.path.join(HISTORY_DIR, self.user_identifier)
691
+ new_history_file_path = new_history_file_path.name
692
+ shutil.copyfile(new_history_file_path, os.path.join(
693
+ HISTORY_DIR, self.user_identifier, os.path.basename(new_history_file_path)))
694
+ self.history_file_path = os.path.basename(new_history_file_path)
695
  else:
696
  self.history_file_path = new_history_file_path
697
  try: