File size: 1,906 Bytes
f18a2c3
 
 
 
 
 
 
 
 
 
 
 
 
5945dda
f18a2c3
5945dda
 
 
f18a2c3
 
 
 
 
 
5945dda
 
 
f18a2c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import modelscope_studio.components.antd as antd
import modelscope_studio.components.antdx as antdx
import modelscope_studio.components.base as ms

text = "Ant Design X love you! "


def repeat(state_value):
    if state_value["repeat"] < 5:
        state_value["repeat"] = state_value["repeat"] + 1
    else:
        state_value["repeat"] = 1
    repeat_value = state_value["repeat"]
    return gr.update(value=state_value), gr.update(
        value=f"Repeat {repeat_value} Times"), gr.update(
            content=text * repeat_value), gr.update(content=text *
                                                    repeat_value)


with gr.Blocks() as demo:
    state = gr.State({"repeat": 1})
    with ms.Application():
        with antdx.XProvider():
            antd.Typography.Paragraph(
                "Enable typing output by setting the typing prop. If the updated content is a subset of the previous content, it will continue to output, otherwise it will output again."
            )
            with antd.Flex(vertical=True, gap="small"):
                with antdx.Bubble(content=text,
                                  typing=dict(step=2, interval=50)) as bubble1:
                    with ms.Slot("avatar.icon"):
                        antd.Icon("UserOutlined")
                with antdx.Bubble(content=text,
                                  typing=dict(step=2, interval=50,
                                              suffix="💗")) as bubble2:
                    with ms.Slot("avatar.icon"):
                        antd.Icon("UserOutlined")
                btn = antd.Button("Repeat 1 Times",
                                  elem_style=dict(alignSelf="flex-end"))
                btn.click(fn=repeat,
                          inputs=[state],
                          outputs=[state, btn, bubble1, bubble2])

if __name__ == "__main__":
    demo.queue().launch()