souljoy commited on
Commit
d825122
1 Parent(s): 0d56748

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -2,17 +2,18 @@ import gradio as gr # 导入gradio包
2
  import random # 导入random包
3
 
4
 
5
- def respond(message, chat_history): # 定义一个respond函数,接收用户输入和历史对话
6
  bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"]) # 随机选择一个回复
7
  chat_history.append((message, bot_message)) # 将用户输入和回复拼接起来,添加到历史对话中
8
  return "", chat_history # 返回空字符串和拼接后的历史对话
9
 
10
 
11
  with gr.Blocks() as demo: # 创建一个demo
 
12
  chatbot = gr.Chatbot(label='历史对话') # 创建一个chatbot
13
  msg = gr.Textbox(label='输入消息,按回车发送') # 创建一个输入框
14
 
15
- msg.submit(respond, [msg, chatbot], [msg, chatbot]) # 设置输入框的回调函数
16
 
17
 
18
  if __name__ == "__main__":
 
2
  import random # 导入random包
3
 
4
 
5
+ def respond(message, chat_history,key): # 定义一个respond函数,接收用户输入和历史对话
6
  bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"]) # 随机选择一个回复
7
  chat_history.append((message, bot_message)) # 将用户输入和回复拼接起来,添加到历史对话中
8
  return "", chat_history # 返回空字符串和拼接后的历史对话
9
 
10
 
11
  with gr.Blocks() as demo: # 创建一个demo
12
+ key = gr.Textbox(label='输入你的OpenAI Key') # 创建一个输入框
13
  chatbot = gr.Chatbot(label='历史对话') # 创建一个chatbot
14
  msg = gr.Textbox(label='输入消息,按回车发送') # 创建一个输入框
15
 
16
+ msg.submit(respond, [msg, chatbot,key], [msg, chatbot]) # 设置输入框的回调函数
17
 
18
 
19
  if __name__ == "__main__":