import gradio as gr def greet(inp, messages): messages.append(inp) print(messages) return "Hello " + inp + "!" def clear_memory(messages): messages.clear() return "Memory cleaned." with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.pink)) as demo: stored_message = gr.State([]) with gr.Row(): with gr.Column(scale=2): text1 = gr.Textbox(lines=7, label="Prompt", scale=2) with gr.Row(): btn1 = gr.Button("Submit", scale=1) btn2 = gr.Button("Clear", scale=1) btn3 = gr.Button("Clean Memory", scale=2) with gr.Column(scale=2): out_text = gr.Text(lines=15, label="Output", scale=2) btn1.click(fn=greet, inputs=[text1, stored_message], outputs=out_text) btn2.click(lambda: [None, None], outputs=[text1, out_text]) btn3.click(fn=clear_memory, inputs=[stored_message], outputs=[out_text]) demo.launch()