File size: 1,145 Bytes
e841ba5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import modelscope_studio.components.antd as antd
import modelscope_studio.components.base as ms


def on_search(e: gr.EventData):
    prefix = e._data['payload'][1]
    if prefix == '@':
        return gr.update(options=[{
            "value": "modelscope",
            "label": "modelscope"
        }, {
            "value": "gradio",
            "label": "gradio"
        }, {
            "value": "ant design",
            "label": "ant design"
        }])
    elif prefix == '#':
        return gr.update(options=[{
            "value": "1.0",
            "label": "1.0"
        }, {
            "value": "2.0",
            "label": "2.0"
        }, {
            "value": "3.0",
            "label": "3.0"
        }])


with gr.Blocks() as demo:
    with ms.Application():
        with antd.ConfigProvider():
            mentions = antd.Mentions(
                elem_style=dict(width='100%'),
                prefix=['@', "#"],
                placeholder="input @ to mention people, # to mention tag")
            mentions.search(fn=on_search, outputs=[mentions])

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