Spaces:
Running
Running
Download components/Chatbot/demos/basic.py from modelscope/modelscope-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/modelscope/modelscope-studio/resolve/refs%2Fpr%2F1/components/Chatbot/demos/basic.py
- Command line
-
hf download hf://spaces/modelscope/modelscope-studio@refs/pr/1/components/Chatbot/demos/basic.py
-
curl -L -o basic.py https://huggingface.co/spaces/modelscope/modelscope-studio/resolve/refs%2Fpr%2F1/components/Chatbot/demos/basic.py
1.23 kB
| import os | |
| import time | |
| import gradio as gr | |
| import modelscope_studio as mgr | |
| conversation = [ | |
| [ | |
| None, | |
| { | |
| # The first message of bot closes the typewriter. | |
| "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() | |