Spaces:
Sleeping
Sleeping
JohnSmith9982
commited on
Commit
•
c5e5944
1
Parent(s):
677701d
Update app.py
Browse files
app.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 |
|
@@ -306,7 +308,7 @@ with gr.Blocks(css=customCSS) as demo:
|
|
306 |
value=my_api_key, label="API Key", type="password", visible=not HIDE_MY_KEY).style(container=True)
|
307 |
chatbot = gr.Chatbot() # .style(color_map=("#1D51EE", "#585A5B"))
|
308 |
history = gr.State([])
|
309 |
-
promptTemplates = gr.State(
|
310 |
TRUECOMSTANT = gr.State(True)
|
311 |
FALSECONSTANT = gr.State(False)
|
312 |
topic = gr.State("未命名对话历史记录")
|
@@ -335,7 +337,7 @@ with gr.Blocks(css=customCSS) as demo:
|
|
335 |
templaeFileReadBtn = gr.Button("📂 读入模板")
|
336 |
with gr.Row():
|
337 |
with gr.Column(scale=6):
|
338 |
-
templateSelectDropdown = gr.Dropdown(label="从Prompt模板中加载", choices=load_template(get_template_names(plain=True)[0],
|
339 |
with gr.Column(scale=1):
|
340 |
templateApplyBtn = gr.Button("⬇️ 应用")
|
341 |
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 |
|
|
|
308 |
value=my_api_key, label="API Key", type="password", visible=not HIDE_MY_KEY).style(container=True)
|
309 |
chatbot = gr.Chatbot() # .style(color_map=("#1D51EE", "#585A5B"))
|
310 |
history = gr.State([])
|
311 |
+
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
312 |
TRUECOMSTANT = gr.State(True)
|
313 |
FALSECONSTANT = gr.State(False)
|
314 |
topic = gr.State("未命名对话历史记录")
|
|
|
337 |
templaeFileReadBtn = gr.Button("📂 读入模板")
|
338 |
with gr.Row():
|
339 |
with gr.Column(scale=6):
|
340 |
+
templateSelectDropdown = gr.Dropdown(label="从Prompt模板中加载", choices=load_template(get_template_names(plain=True)[0], mode=1), multiselect=False)
|
341 |
with gr.Column(scale=1):
|
342 |
templateApplyBtn = gr.Button("⬇️ 应用")
|
343 |
with gr.Accordion(label="保存/加载对话历史记录(在文本框中输入文件名,点击“保存对话”按钮,历史记录文件会被存储到Python文件旁边)", open=False):
|