Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
cd2e998
1
Parent(s):
2e8e7da
feat: 限制文件上传的类型,优化体验 #938
Browse files- ChuanhuChatbot.py +3 -1
- modules/utils.py +9 -0
ChuanhuChatbot.py
CHANGED
@@ -236,7 +236,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
236 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
237 |
"使用在线搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
|
238 |
index_files = gr.Files(label=i18n(
|
239 |
-
"上传"), type="file", elem_id="upload-index-file")
|
240 |
two_column = gr.Checkbox(label=i18n(
|
241 |
"双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
|
242 |
summarize_btn = gr.Button(i18n("总结"))
|
@@ -645,6 +645,8 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
645 |
current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model")
|
646 |
model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [
|
647 |
like_dislike_area], show_progress=False)
|
|
|
|
|
648 |
lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider,
|
649 |
top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True)
|
650 |
|
|
|
236 |
use_websearch_checkbox = gr.Checkbox(label=i18n(
|
237 |
"使用在线搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb", visible=False)
|
238 |
index_files = gr.Files(label=i18n(
|
239 |
+
"上传"), type="file", file_types=[".pdf", ".docx", ".pptx", ".epub", ".xlsx", ".txt", "text", "image"], elem_id="upload-index-file")
|
240 |
two_column = gr.Checkbox(label=i18n(
|
241 |
"双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
|
242 |
summarize_btn = gr.Button(i18n("总结"))
|
|
|
645 |
current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model")
|
646 |
model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [
|
647 |
like_dislike_area], show_progress=False)
|
648 |
+
# model_select_dropdown.change(
|
649 |
+
# toggle_file_type, [model_select_dropdown], [index_files], show_progress=False)
|
650 |
lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider,
|
651 |
top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True)
|
652 |
|
modules/utils.py
CHANGED
@@ -661,6 +661,15 @@ def toggle_like_btn_visibility(selected_model_name):
|
|
661 |
else:
|
662 |
return gr.update(visible=False)
|
663 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
664 |
def new_auto_history_filename(username):
|
665 |
latest_file = get_first_history_name(username)
|
666 |
if latest_file:
|
|
|
661 |
else:
|
662 |
return gr.update(visible=False)
|
663 |
|
664 |
+
def get_corresponding_file_type_by_model_name(selected_model_name):
|
665 |
+
if selected_model_name in ["xmchat", "GPT4 Vision"]:
|
666 |
+
return ["image"]
|
667 |
+
else:
|
668 |
+
return [".pdf", ".docx", ".pptx", ".epub", ".xlsx", ".txt", "text"]
|
669 |
+
|
670 |
+
# def toggle_file_type(selected_model_name):
|
671 |
+
# return gr.Files.update(file_types=get_corresponding_file_type_by_model_name(selected_model_name))
|
672 |
+
|
673 |
def new_auto_history_filename(username):
|
674 |
latest_file = get_first_history_name(username)
|
675 |
if latest_file:
|