import gradio as gr from transformers import pipeline # 加载预训练的对话模型 chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium") # 定义对话处理函数 def chat(input_text, history=[]): response = chatbot(input_text, history) history.append((input_text, response)) return history, history # 创建 Gradio 接口 iface = gr.Interface( fn=chat, inputs=["text", "state"], outputs=["chatbot", "state"], live=True, title="Chatbot", description="A simple chatbot using DialoGPT" ) # 启动 Gradio 应用 iface.launch()