Spaces:
Running
Running
File size: 1,291 Bytes
630cbf4 |
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 |
import json
import gradio as gr
import modelscope_gradio_components as mgr
# label 为对用户展示值,value 为实际选择值
options = [{"label": "A", "value": "a"}, "b", "c"]
conversation = [[
None, f"""
Single Select: <select-box options='{json.dumps(options)}' select-once></select-box>
Multiple Select:<select-box type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
Vertical Direction:
<select-box direction="vertical" type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
Card Shape:
<select-box shape="card" options='{json.dumps(options)}' select-once equal-height></select-box>
<select-box shape="card" columns="2" options='{json.dumps(options)}' select-once equal-height></select-box>
<select-box shape="card" direction="vertical" options='{json.dumps(options)}' select-once equal-height></select-box>
"""
]]
# 必须使用 gr.EventData 显示标注
def fn(data: gr.EventData):
print(data._data)
with gr.Blocks() as demo:
chatbot = mgr.Chatbot(
value=conversation,
flushing=False,
height=600,
)
# 所有自定义标签都会触发 custom 事件
chatbot.custom(fn=fn)
if __name__ == "__main__":
demo.queue().launch()
|