Spaces:
Running
Running
File size: 3,546 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 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.base as ms
default_locale = "en_US"
default_direction = 'ltr'
default_color = "#816DF8"
with gr.Blocks() as demo:
with ms.Application():
with antd.ConfigProvider(
locale=default_locale,
direction=default_direction,
theme=dict(token=dict(
colorPrimary=default_color))) as config_provider:
with antd.Card():
with ms.Div(elem_style=dict(marginBottom=16)):
ms.Span("change locale of components:",
elem_style=dict(marginInlineEnd=16))
with antd.Radio.Group(value=default_locale) as locale:
with antd.Radio("en_US"):
ms.Text("English")
with antd.Radio("zh_CN"):
ms.Text("中文")
with antd.Radio("ja_JP"):
ms.Text("日本語")
with antd.Radio("ko_KR"):
ms.Text("한국어")
with antd.Space(wrap=True):
antd.DatePicker()
antd.DatePicker.RangePicker()
antd.TimePicker()
antd.TimePicker.RangePicker()
with ms.Div(elem_style=dict(marginBottom=16)):
ms.Span("change direction of components:",
elem_style=dict(marginInlineEnd=16))
with antd.Radio.Group(
value=default_direction) as direction:
with antd.Radio.Button("ltr"):
ms.Text("LTR")
with antd.Radio.Button("rtl"):
ms.Text("RTL")
antd.Input(placeholder="do something...")
with ms.Div(elem_style=dict(marginBottom=16)):
ms.Span("change theme of components:",
elem_style=dict(marginInlineEnd=16))
with antd.Space():
with antd.Checkbox.Group() as theme:
antd.Checkbox.Group.Option("dark", label="dark")
antd.Checkbox.Group.Option("compact",
label="compact")
ms.Text("Primary Color: ")
color = antd.ColorPicker(value=default_color)
antd.Button("Primary Button", type="primary", block=True)
locale.change(fn=lambda _locale: gr.update(locale=_locale),
inputs=[locale],
outputs=[config_provider])
direction.change(fn=lambda _direction: gr.update(direction=_direction),
inputs=[direction],
outputs=[config_provider])
gr.on(
[theme.change, color.change],
fn=lambda _theme, _color: gr.update(theme=dict(
token=dict(colorPrimary=_color) if _color else None,
algorithm=dict(dark=True
if _theme and 'dark' in _theme else False,
compact=True
if _theme and 'compact' in _theme else False))),
inputs=[theme, color],
outputs=[config_provider])
if __name__ == "__main__":
demo.queue().launch()
|