import gradio as gr with gr.Blocks() as demo: chatbot = gr.Chatbot() msg = gr.Textbox() clear = gr.Button("Clear") llm_chain, llm = init_chain(model, tokenizer) def user(user_message, history): return "", history + [[user_message, None]] def bot(history): print("Question: ", history[-1][0]) llm_chain.run(question=history[-1][0]) history[-1][1] = "" for character in llm.streamer: print(character) history[-1][1] += character yield history msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(bot, chatbot, chatbot) clear.click(lambda: None, None, chatbot, queue=False) demo.queue() demo.launch()