Spaces:
Running
Running
File size: 3,441 Bytes
6c3eb98 5945dda 6c3eb98 5945dda 6c3eb98 |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
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
def toggle_open(state_value, attachments_value):
state_value["open"] = not state_value["open"]
return gr.update(open=state_value["open"]), gr.update(
dot=len(attachments_value) > 0 and not state_value["open"]), gr.update(
value=state_value)
def submit(sender_value, attachments_value):
print(sender_value, attachments_value)
return gr.update(value=None), gr.update(value=None), gr.update(dot=False)
with gr.Blocks() as demo:
state = gr.State({"open": False})
with ms.Application():
with antdx.XProvider():
antd.Typography.Paragraph(
"Work with Sender.Header to insert file into the conversation."
)
with antdx.Sender() as sender:
with ms.Slot("prefix"):
with antd.Badge(dot=False) as prefix_badge:
with antd.Button(value=None) as prefix_button:
with ms.Slot("icon"):
antd.Icon("LinkOutlined")
with ms.Slot("header"):
with antdx.Sender.Header(title="Attachments",
open=False,
styles={
"content": {
"padding": 0,
},
}) as sender_header:
with antdx.Attachments() as attachments:
with ms.Slot(
"placeholder.title",
params_mapping=
"""(type) => type === 'drop' ? 'Drop file here' : 'Upload files'"""
):
ms.Span()
with ms.Slot(
"placeholder.description",
params_mapping=
"(type) => ({ style: { display: type === 'drop'? 'none' : undefined } })"
):
ms.Span(
"Click or drag files to this area to upload"
)
with ms.Slot(
"placeholder.icon",
params_mapping=
"(type) => ({ style: { display: type === 'drop'? 'none' : undefined } })"
):
antd.Icon("CloudUploadOutlined")
sender_header.open_change(
fn=toggle_open,
inputs=[state, attachments],
outputs=[sender_header, prefix_badge, state])
prefix_button.click(fn=toggle_open,
inputs=[state, attachments],
outputs=[sender_header, prefix_badge, state])
sender.submit(fn=submit,
inputs=[sender, attachments],
outputs=[sender, attachments, prefix_badge])
if __name__ == "__main__":
demo.queue().launch()
|