import random import gradio as gr def chat(message, history): history = history or [] message = message.lower() if message.startswith("how many"): response = random.randint(1, 10) elif message.startswith("how"): response = random.choice(["Great", "Good", "Okay", "Bad"]) elif message.startswith("where"): response = random.choice(["Here", "There", "Somewhere"]) else: response = "I don't know" history.append((message, response)) return history, history #设置一个对话窗 chatbot = gr.Chatbot().style(color_map=("green", "pink")) demo = gr.Interface( chat, # 添加state组件 ["text", "state"], [chatbot, "state"], # 设置没有保存数据的按钮 allow_flagging="never", ) demo.launch(share=True, server_name='0.0.0.0')
标签:gr,gradio,random,message,response,history From: https://www.cnblogs.com/ah-firelove/p/17664418.html