Spaces:
Running
Running
Update bin_public/app/Chatbot.py
Browse files- bin_public/app/Chatbot.py +37 -26
bin_public/app/Chatbot.py
CHANGED
@@ -117,24 +117,31 @@ with gr.Blocks(css=customCSS) as demo:
|
|
117 |
with gr.Tab(label="保存/加载"):
|
118 |
with gr.Accordion(label="保存/加载对话历史记录", open=True):
|
119 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
with gr.Row():
|
121 |
with gr.Column(scale=6):
|
122 |
saveFileName = gr.Textbox(
|
123 |
-
show_label=True,
|
124 |
-
|
|
|
|
|
|
|
125 |
with gr.Column(scale=1):
|
126 |
saveHistoryBtn = gr.Button("💾 保存对话")
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
multiselect=False,
|
133 |
-
value=get_history_names(plain=True)[0])'''
|
134 |
-
#with gr.Column(scale=1):
|
135 |
-
#historyRefreshBtn = gr.Button("🔄 刷新")
|
136 |
-
# 加一个invisible button,用来清除文件,不加会无法清楚生成的文件
|
137 |
-
#fileRefreshBtn = gr.Button("🔄 文件刷新", visible=False)
|
138 |
|
139 |
gr.HTML("""
|
140 |
<div style="text-align: center; margin-top: 20px; margin-bottom: 20px;">
|
@@ -167,25 +174,29 @@ with gr.Blocks(css=customCSS) as demo:
|
|
167 |
temperature, use_streaming_checkbox, model_select_dropdown],
|
168 |
[chatbot, history, status_display, token_count], show_progress=True)
|
169 |
# History
|
170 |
-
saveHistoryBtn.click(
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
#historyRefreshBtn.click(get_history_names, None, [historyFileSelectDropdown])
|
176 |
-
|
177 |
-
#fileRefreshBtn.click(reset_file, inputs=chat_history_file, outputs=None)
|
178 |
-
|
179 |
-
'''historyFileSelectDropdown.change(
|
180 |
load_chat_history,
|
181 |
[historyFileSelectDropdown, systemPromptTxt, history, chatbot],
|
182 |
[saveFileName, systemPromptTxt, history, chatbot],
|
183 |
show_progress=True,
|
184 |
-
)
|
185 |
-
|
186 |
-
chat_history_file.change(
|
187 |
load_chat_history,
|
188 |
-
[
|
189 |
[saveFileName, systemPromptTxt, history, chatbot],
|
190 |
)
|
191 |
|
|
|
117 |
with gr.Tab(label="保存/加载"):
|
118 |
with gr.Accordion(label="保存/加载对话历史记录", open=True):
|
119 |
with gr.Column():
|
120 |
+
with gr.Row():
|
121 |
+
with gr.Column(scale=6):
|
122 |
+
historyFileSelectDropdown = gr.Dropdown(
|
123 |
+
label="从列表中加载对话",
|
124 |
+
choices=get_history_names(plain=True),
|
125 |
+
multiselect=False,
|
126 |
+
value=get_history_names(plain=True)[0],
|
127 |
+
visible=False
|
128 |
+
)
|
129 |
+
|
130 |
with gr.Row():
|
131 |
with gr.Column(scale=6):
|
132 |
saveFileName = gr.Textbox(
|
133 |
+
show_label=True,
|
134 |
+
placeholder=f"设置文件名: 默认为.json,可选为.md",
|
135 |
+
label="设置保存文件名",
|
136 |
+
value="对话历史记录",
|
137 |
+
).style(container=True)
|
138 |
with gr.Column(scale=1):
|
139 |
saveHistoryBtn = gr.Button("💾 保存对话")
|
140 |
+
exportMarkdownBtn = gr.Button("📝 导出为Markdown")
|
141 |
+
gr.Markdown("默认保存于history文件夹")
|
142 |
+
with gr.Row():
|
143 |
+
with gr.Column():
|
144 |
+
downloadFile = gr.File(interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
gr.HTML("""
|
147 |
<div style="text-align: center; margin-top: 20px; margin-bottom: 20px;">
|
|
|
174 |
temperature, use_streaming_checkbox, model_select_dropdown],
|
175 |
[chatbot, history, status_display, token_count], show_progress=True)
|
176 |
# History
|
177 |
+
saveHistoryBtn.click(
|
178 |
+
save_chat_history,
|
179 |
+
[saveFileName, systemPromptTxt, history, chatbot],
|
180 |
+
downloadFile,
|
181 |
+
show_progress=True,
|
182 |
+
)
|
183 |
+
saveHistoryBtn.click(get_history_names, None, [historyFileSelectDropdown])
|
184 |
+
exportMarkdownBtn.click(
|
185 |
+
export_markdown,
|
186 |
+
[saveFileName, systemPromptTxt, history, chatbot],
|
187 |
+
downloadFile,
|
188 |
+
show_progress=True,
|
189 |
+
)
|
190 |
#historyRefreshBtn.click(get_history_names, None, [historyFileSelectDropdown])
|
191 |
+
historyFileSelectDropdown.change(
|
|
|
|
|
|
|
192 |
load_chat_history,
|
193 |
[historyFileSelectDropdown, systemPromptTxt, history, chatbot],
|
194 |
[saveFileName, systemPromptTxt, history, chatbot],
|
195 |
show_progress=True,
|
196 |
+
)
|
197 |
+
downloadFile.change(
|
|
|
198 |
load_chat_history,
|
199 |
+
[downloadFile, systemPromptTxt, history, chatbot],
|
200 |
[saveFileName, systemPromptTxt, history, chatbot],
|
201 |
)
|
202 |
|