Spaces:
Running
Running
File size: 1,588 Bytes
5945dda |
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 47 48 49 50 51 52 53 54 55 |
import gradio as gr
import modelscope_studio.components.antdx as antdx
import modelscope_studio.components.base as ms
items = [
{
"label": 'Write a report',
"value": 'report'
},
{
"label": 'Draw a picture',
"value": 'draw'
},
{
"label": 'Check some knowledge',
"value": 'knowledge',
"extra": 'Extra Info',
},
]
def select_suggestion(e: gr.EventData):
return gr.update(value=e._data["payload"][0]), gr.update(open=False)
def change_sender(sender_value: str):
splitted_value = sender_value.split("/")
command = sender_value.split("/")[-1]
if len(splitted_value) > 1:
filtered_items = [
item for item in items
if item["label"].upper().find(command.upper()) != -1
and not command.startswith(item["value"])
]
if len(filtered_items) > 0:
return gr.update(open=True, items=filtered_items)
return gr.update(open=False)
with gr.Blocks() as demo:
with ms.Application():
with antdx.XProvider():
with antdx.Suggestion(open=False) as suggestion:
with ms.Slot("children"):
sender = antdx.Sender(
placeholder="Enter / to get suggestions")
sender.change(fn=change_sender,
inputs=[sender],
outputs=[suggestion])
suggestion.select(fn=select_suggestion,
outputs=[sender, suggestion])
if __name__ == "__main__":
demo.queue().launch()
|