Spaces:
Running
Running
Download components/MultimodalInput/demos/with_chatbot.py from modelscope/modelscope-studio: direct link, hf CLI and curl.
- Browser
- Download file 851 Bytes
-
https://huggingface.co/spaces/modelscope/modelscope-studio/resolve/refs%2Fpr%2F1/components/MultimodalInput/demos/with_chatbot.py
- Command line
-
hf download hf://spaces/modelscope/modelscope-studio@refs/pr/1/components/MultimodalInput/demos/with_chatbot.py
-
curl -L -o with_chatbot.py https://huggingface.co/spaces/modelscope/modelscope-studio/resolve/refs%2Fpr%2F1/components/MultimodalInput/demos/with_chatbot.py
851 Bytes
| import time | |
| import gradio as gr | |
| import modelscope_studio as mgr | |
| def fn(input, chatbot): | |
| chatbot.append([{ | |
| "text": input.text, | |
| "files": input.files, | |
| }, None]) | |
| yield { | |
| user_input: mgr.MultimodalInput(interactive=False), | |
| user_chatbot: chatbot | |
| } | |
| time.sleep(2) | |
| chatbot[-1][1] = {"text": "Hello!"} | |
| yield {user_chatbot: chatbot} | |
| # Triggered when the typewriter is ending. | |
| def flushed(): | |
| return mgr.MultimodalInput(interactive=True) | |
| with gr.Blocks() as demo: | |
| user_chatbot = mgr.Chatbot() | |
| user_input = mgr.MultimodalInput() | |
| user_input.submit(fn=fn, | |
| inputs=[user_input, user_chatbot], | |
| outputs=[user_input, user_chatbot]) | |
| user_chatbot.flushed(fn=flushed, outputs=[user_input]) | |
| if __name__ == "__main__": | |
| demo.queue().launch() | |