import gradio as gr class Human: def __init__(self): self.count = 0 print("init") def reset(self): self.count = 0 print("reset") def echo(self, message, history): self.count += 1 return "this round:"+str(self.count) h = Human() hs = gr.State(h) def output(message, history, s): r = s.echo(message, history) return r demo = gr.ChatInterface( fn=output, additional_inputs=[hs], retry_btn=None, undo_btn=None, submit_btn="发送", #clear_btn="再来一局", clear_btn=gr.ClearButton(hs), title="Echo Bot") demo.launch()