Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
07cd8f7
1
Parent(s):
cede152
新功能:默认加载模板文件;文件名和模板名按字母顺序排序
Browse files- ChuanhuChatbot.py +6 -4
ChuanhuChatbot.py
CHANGED
@@ -233,14 +233,16 @@ def get_file_names(dir, plain=False, filetype=".json"):
|
|
233 |
def get_history_names(plain=False):
|
234 |
return get_file_names(HISTORY_DIR, plain)
|
235 |
|
236 |
-
def load_template(filename,
|
237 |
lines = []
|
238 |
with open(os.path.join(TEMPLATES_DIR, filename), "r", encoding="utf8") as csvfile:
|
239 |
reader = csv.reader(csvfile)
|
240 |
lines = list(reader)
|
241 |
lines = lines[1:]
|
242 |
-
if
|
243 |
return sorted([row[0] for row in lines])
|
|
|
|
|
244 |
else:
|
245 |
return {row[0]:row[1] for row in lines}, gr.Dropdown.update(choices=sorted([row[0] for row in lines]))
|
246 |
|
@@ -305,7 +307,7 @@ with gr.Blocks(css=customCSS) as demo:
|
|
305 |
value=my_api_key, label="API Key", type="password", visible=not HIDE_MY_KEY).style(container=True)
|
306 |
chatbot = gr.Chatbot() # .style(color_map=("#1D51EE", "#585A5B"))
|
307 |
history = gr.State([])
|
308 |
-
promptTemplates = gr.State(
|
309 |
TRUECOMSTANT = gr.State(True)
|
310 |
FALSECONSTANT = gr.State(False)
|
311 |
topic = gr.State("未命名对话历史记录")
|
@@ -334,7 +336,7 @@ with gr.Blocks(css=customCSS) as demo:
|
|
334 |
templaeFileReadBtn = gr.Button("📂 读入模板")
|
335 |
with gr.Row():
|
336 |
with gr.Column(scale=6):
|
337 |
-
templateSelectDropdown = gr.Dropdown(label="从Prompt模板中加载", choices=load_template(get_template_names(plain=True)[0],
|
338 |
with gr.Column(scale=1):
|
339 |
templateApplyBtn = gr.Button("⬇️ 应用")
|
340 |
with gr.Accordion(label="保存/加载对话历史记录(在文本框中输入文件名,点击“保存对话”按钮,历史记录文件会被存储到Python文件旁边)", open=False):
|
|
|
233 |
def get_history_names(plain=False):
|
234 |
return get_file_names(HISTORY_DIR, plain)
|
235 |
|
236 |
+
def load_template(filename, mode=0):
|
237 |
lines = []
|
238 |
with open(os.path.join(TEMPLATES_DIR, filename), "r", encoding="utf8") as csvfile:
|
239 |
reader = csv.reader(csvfile)
|
240 |
lines = list(reader)
|
241 |
lines = lines[1:]
|
242 |
+
if mode == 1:
|
243 |
return sorted([row[0] for row in lines])
|
244 |
+
elif mode == 2:
|
245 |
+
return {row[0]:row[1] for row in lines}
|
246 |
else:
|
247 |
return {row[0]:row[1] for row in lines}, gr.Dropdown.update(choices=sorted([row[0] for row in lines]))
|
248 |
|
|
|
307 |
value=my_api_key, label="API Key", type="password", visible=not HIDE_MY_KEY).style(container=True)
|
308 |
chatbot = gr.Chatbot() # .style(color_map=("#1D51EE", "#585A5B"))
|
309 |
history = gr.State([])
|
310 |
+
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
311 |
TRUECOMSTANT = gr.State(True)
|
312 |
FALSECONSTANT = gr.State(False)
|
313 |
topic = gr.State("未命名对话历史记录")
|
|
|
336 |
templaeFileReadBtn = gr.Button("📂 读入模板")
|
337 |
with gr.Row():
|
338 |
with gr.Column(scale=6):
|
339 |
+
templateSelectDropdown = gr.Dropdown(label="从Prompt模板中加载", choices=load_template(get_template_names(plain=True)[0], mode=1), multiselect=False)
|
340 |
with gr.Column(scale=1):
|
341 |
templateApplyBtn = gr.Button("⬇️ 应用")
|
342 |
with gr.Accordion(label="保存/加载对话历史记录(在文本框中输入文件名,点击“保存对话”按钮,历史记录文件会被存储到Python文件旁边)", open=False):
|