Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -308,8 +308,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 308 |
新建 = gr.Button("➕ 新建", size="sm")
|
| 309 |
with gr.Row():
|
| 310 |
导入文件 = gr.File(label="导入JSON", file_types=[".json"])
|
| 311 |
-
|
| 312 |
-
|
| 313 |
导出文件 = gr.File(label="导出文件", interactive=False)
|
| 314 |
|
| 315 |
# ========= 逻辑 =========
|
|
@@ -337,7 +337,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 337 |
return "", hist + [[msg, None]]
|
| 338 |
|
| 339 |
def 机器人应答(hist, sys_prompt_state, max_len, temp, tp, tk, keep_rounds, ctx_limit, sid):
|
| 340 |
-
#
|
| 341 |
global 系统提示默认
|
| 342 |
系统提示默认 = sys_prompt_state
|
| 343 |
|
|
@@ -414,13 +414,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 414 |
return [], sid, gr.update(choices=历史管理.列表(), value=sid), 系统提示默认, gr.update(value=系统提示默认)
|
| 415 |
新建.click(新建会话, outputs=[聊天框, 会话ID, 会话列表, 系统提示状态, 系统提示框])
|
| 416 |
|
| 417 |
-
# 导入 /
|
| 418 |
-
def
|
| 419 |
历史管理.保存(hist, sid, {"system_prompt": 系统提示状态.value})
|
| 420 |
return 历史管理.路径(sid)
|
| 421 |
-
导出.click(导出, [聊天框, 会话ID], 导出文件)
|
| 422 |
|
| 423 |
-
def
|
| 424 |
if file is None:
|
| 425 |
return gr.update(), gr.update()
|
| 426 |
try:
|
|
@@ -433,7 +432,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 433 |
return h, sp
|
| 434 |
except Exception as e:
|
| 435 |
return gr.update(), gr.update(value=f"导入失败: {e}")
|
| 436 |
-
|
|
|
|
|
|
|
| 437 |
|
| 438 |
# 自动保存
|
| 439 |
聊天框.change(lambda h, sid, sp: 历史管理.保存(h, sid, {"system_prompt": sp}) if h else None,
|
|
|
|
| 308 |
新建 = gr.Button("➕ 新建", size="sm")
|
| 309 |
with gr.Row():
|
| 310 |
导入文件 = gr.File(label="导入JSON", file_types=[".json"])
|
| 311 |
+
导入按钮 = gr.Button("⬆️ 导入", size="sm")
|
| 312 |
+
导出按钮 = gr.Button("⬇️ 导出当前会话", size="sm")
|
| 313 |
导出文件 = gr.File(label="导出文件", interactive=False)
|
| 314 |
|
| 315 |
# ========= 逻辑 =========
|
|
|
|
| 337 |
return "", hist + [[msg, None]]
|
| 338 |
|
| 339 |
def 机器人应答(hist, sys_prompt_state, max_len, temp, tp, tk, keep_rounds, ctx_limit, sid):
|
| 340 |
+
# 将系统提示更新为当前设置
|
| 341 |
global 系统提示默认
|
| 342 |
系统提示默认 = sys_prompt_state
|
| 343 |
|
|
|
|
| 414 |
return [], sid, gr.update(choices=历史管理.列表(), value=sid), 系统提示默认, gr.update(value=系统提示默认)
|
| 415 |
新建.click(新建会话, outputs=[聊天框, 会话ID, 会话列表, 系统提示状态, 系统提示框])
|
| 416 |
|
| 417 |
+
# 导入 / 导出(最小修复:按钮与函数避免同名)
|
| 418 |
+
def 导出处理(hist, sid):
|
| 419 |
历史管理.保存(hist, sid, {"system_prompt": 系统提示状态.value})
|
| 420 |
return 历史管理.路径(sid)
|
|
|
|
| 421 |
|
| 422 |
+
def 导入处理(file, sid):
|
| 423 |
if file is None:
|
| 424 |
return gr.update(), gr.update()
|
| 425 |
try:
|
|
|
|
| 432 |
return h, sp
|
| 433 |
except Exception as e:
|
| 434 |
return gr.update(), gr.update(value=f"导入失败: {e}")
|
| 435 |
+
|
| 436 |
+
导出按钮.click(导出处理, [聊天框, 会话ID], 导出文件)
|
| 437 |
+
导入按钮.click(导入处理, [导入文件, 会话ID], [聊天框, 系统提示框])
|
| 438 |
|
| 439 |
# 自动保存
|
| 440 |
聊天框.change(lambda h, sid, sp: 历史管理.保存(h, sid, {"system_prompt": sp}) if h else None,
|