Spaces:
Running
Running
File size: 1,249 Bytes
630cbf4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import os
import time
import gradio as gr
import modelscope_gradio_components as mgr
conversation = [
[
None,
{
# bot 第一句话关闭打字机效果,直接输入内容
"text": "Hello I'm a chatbot",
"flushing": False
}
],
]
def submit(_input, _chatbot):
_chatbot.append([_input, None])
yield gr.update(interactive=False, value=None), _chatbot
time.sleep(2)
_chatbot[-1][1] = {"text": _input.text + '!'}
yield {
chatbot: _chatbot,
}
def flushed():
return gr.update(interactive=True)
with gr.Blocks() as demo:
chatbot = mgr.Chatbot(
value=conversation,
avatar_images=[
os.path.join(os.path.dirname(__file__), "../resources/user.jpeg"),
{
"name":
"bot",
"avatar":
os.path.join(os.path.dirname(__file__),
"../resources/bot.jpeg")
}
],
height=600,
)
input = mgr.MultimodalInput()
input.submit(fn=submit, inputs=[input, chatbot], outputs=[input, chatbot])
chatbot.flushed(fn=flushed, outputs=[input])
if __name__ == "__main__":
demo.queue().launch()
|