Skip to content

Commit

Permalink
feat: 限制文件上传的类型,优化体验 #938
Browse files Browse the repository at this point in the history
  • Loading branch information
GaiZhenbiao committed Nov 17, 2023
1 parent 2e8e7da commit cd2e998
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ChuanhuChatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def create_new_model():
use_websearch_checkbox = gr.Checkbox(label=i18n(
"使用在线搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
index_files = gr.Files(label=i18n(
"上传"), type="file", elem_id="upload-index-file")
"上传"), type="file", file_types=[".pdf", ".docx", ".pptx", ".epub", ".xlsx", ".txt", "text", "image"], elem_id="upload-index-file")
two_column = gr.Checkbox(label=i18n(
"双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
summarize_btn = gr.Button(i18n("总结"))
Expand Down Expand Up @@ -645,6 +645,8 @@ def create_greeting(request: gr.Request):
current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model")
model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [
like_dislike_area], show_progress=False)
# model_select_dropdown.change(
# toggle_file_type, [model_select_dropdown], [index_files], show_progress=False)
lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider,
top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True)

Expand Down
9 changes: 9 additions & 0 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,15 @@ def toggle_like_btn_visibility(selected_model_name):
else:
return gr.update(visible=False)

def get_corresponding_file_type_by_model_name(selected_model_name):
if selected_model_name in ["xmchat", "GPT4 Vision"]:
return ["image"]
else:
return [".pdf", ".docx", ".pptx", ".epub", ".xlsx", ".txt", "text"]

# def toggle_file_type(selected_model_name):
# return gr.Files.update(file_types=get_corresponding_file_type_by_model_name(selected_model_name))

def new_auto_history_filename(username):
latest_file = get_first_history_name(username)
if latest_file:
Expand Down

0 comments on commit cd2e998

Please sign in to comment.