upgrade gradio

这个提交包含在:
binary-husky
2024-12-07 15:59:30 +08:00
父节点 a88b119bf0
当前提交 e9a7f9439f
共有 8 个文件被更改,包括 255 次插入129 次删除

查看文件

@@ -77,16 +77,28 @@ def make_history_cache():
# 定义 后端statehistory、前端history_cache、后端setterhistory_cache_update三兄弟
import gradio as gr
# 定义history的后端state
history = gr.State([])
# 定义history的一个孪生的前端存储区隐藏
history_cache = gr.Textbox(visible=False, elem_id="history_cache")
# 定义history_cache->history的更新方法隐藏。在触发这个按钮时,会先执行js代码更新history_cache,然后再执行python代码更新history
def process_history_cache(history_cache):
return json.loads(history_cache)
# 另一种更简单的setter方法
history_cache_update = gr.Button("", elem_id="elem_update_history", visible=False).click(
process_history_cache, inputs=[history_cache], outputs=[history])
return history, history_cache, history_cache_update
# history = gr.State([])
history = gr.Textbox(visible=False, elem_id="history-ng")
# # 定义history的一个孪生的前端存储区隐藏
# history_cache = gr.Textbox(visible=False, elem_id="history_cache")
# # 定义history_cache->history的更新方法隐藏。在触发这个按钮时,会先执行js代码更新history_cache,然后再执行python代码更新history
# def process_history_cache(history_cache):
# return json.loads(history_cache)
# # 另一种更简单的setter方法
# history_cache_update = gr.Button("", elem_id="elem_update_history", visible=False).click(
# process_history_cache, inputs=[history_cache], outputs=[history])
# # save history to history_cache
# def process_history_cache(history_cache):
# return json.dumps(history_cache)
# # 定义history->history_cache的更新方法隐藏
# def sync_history_cache(history):
# print("sync_history_cache", history)
# return json.dumps(history)
# # history.change(sync_history_cache, inputs=[history], outputs=[history_cache])
# # history_cache_sync = gr.Button("", elem_id="elem_sync_history", visible=False).click(
# # lambda history: (json.dumps(history)), inputs=[history_cache], outputs=[history])
return history, None, None