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


def on_search(e: gr.EventData):
    text = e._data["payload"][0]
    domains = ["gmail.com", "163.com", "qq.com"]
    if not text or "@" in text:
        return gr.update(options=[])
    return gr.update(options=[{
        "value": f"{text}@{domain}",
        "label": f"{text}@{domain}"
    } for domain in domains])


with gr.Blocks() as demo:
    with ms.Application():
        with antd.ConfigProvider():
            auto_complete = antd.AutoComplete(placeholder="Typing here...",
                                              elem_style=dict(width=200))
            antd.Divider("Customize Input   Component")
            with antd.AutoComplete() as customize_auto_complete:
                with ms.Slot("children"):
                    antd.Input.Textarea(placeholder="Typing here...")
            auto_complete.search(on_search, outputs=[auto_complete])
            customize_auto_complete.search(on_search,
                                           outputs=[customize_auto_complete])

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