leonsimon23 commited on
Commit
f11dc41
·
verified ·
1 Parent(s): 532d5ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -27,17 +27,20 @@ def ai_response(message, chat_history):
27
 
28
  return assistant_message, chat_history
29
 
30
- # 创建 Gradio Chat 界面
31
- with gr.Blocks() as demo:
32
- # 创建 Chat 组件
33
- chat_interface = gr.Chat()
34
-
35
- # 定义输入和输出
36
- message_input = gr.Textbox(label="请输入你的问题")
37
- output_message = gr.Chatbot()
 
 
 
38
 
39
- # 设置点击事件
40
- message_input.submit(ai_response, inputs=[message_input, chat_interface], outputs=[output_message, chat_interface])
41
 
42
  # 启动 Gradio 应用
 
43
  demo.launch()
 
27
 
28
  return assistant_message, chat_history
29
 
30
+ # 创建 Gradio 应用
31
+ def create_interface():
32
+ with gr.Blocks() as demo:
33
+ # 创建一个文本框用于输入消息
34
+ message_input = gr.Textbox(label="请输入你的问题")
35
+
36
+ # 创建一个聊天机器人输出组件,用于显示对话
37
+ chat_output = gr.Chatbot()
38
+
39
+ # 提交按钮,发送用户消息并获取AI回复
40
+ message_input.submit(ai_response, inputs=[message_input, chat_output], outputs=[chat_output])
41
 
42
+ return demo
 
43
 
44
  # 启动 Gradio 应用
45
+ demo = create_interface()
46
  demo.launch()