feat(frontend): 添加了简单聊天机器人页面
This commit is contained in:
parent
051d1a7535
commit
e7cc03297b
@ -1,9 +1,28 @@
|
||||
import gradio as gr
|
||||
from global_var import model,tokenizer
|
||||
|
||||
def chat_page():
|
||||
with gr.Blocks() as demo:
|
||||
import random
|
||||
import time
|
||||
gr.Markdown("## 聊天")
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
pass
|
||||
chatbot = gr.Chatbot(type="messages")
|
||||
msg = gr.Textbox()
|
||||
clear = gr.Button("Clear")
|
||||
|
||||
def user(user_message, history: list):
|
||||
return "", history + [{"role": "user", "content": user_message}]
|
||||
|
||||
def bot(history: list):
|
||||
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
||||
history.append({"role": "assistant", "content": ""})
|
||||
for character in bot_message:
|
||||
history[-1]['content'] += character
|
||||
time.sleep(0.1)
|
||||
yield history
|
||||
|
||||
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
||||
bot, chatbot, chatbot
|
||||
)
|
||||
clear.click(lambda: None, None, chatbot, queue=False)
|
||||
return demo
|
Loading…
x
Reference in New Issue
Block a user