You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
modelscope_studio is a third-party component library based on Gradio, offers developers more customized interface building capabilities and a richer variety of component usage forms.
In version 1.0, we integrated components from Ant Design and ensure compatibility with most of its APIs. Now you can build your Gradio application with them.
Different from the layout in Gradio, to make more flexible layouts, modelscope-studio provides a Slot component for developers.
For example, in Ant Design, there are some properties of type ReactNode (which can be simply understood as they accept components as parameters). and these properties cannot be directly passed through Python, they can only be implemented using the Slot component.
If we want to add some additional styles to the top of the Card in the example above:
withantd.Card():
withms.Slot("title"): # corresponds to the prop name of cardantd.Typography.Text("ModelScope",
strong=True,
copyable=True)
withms.Slot("extra"):
withantd.Button(
href="https://github.com/modelscope/modelscope-studio",
href_target="_blank"):
ms.Text("GitHub")
withms.Slot("icon"):
antd.Icon("GithubOutlined")
antd.Tag("modelscope", color="purple")
antd.Tag("ms-swift", color="magenta")
antd.Tag("modelscope-studio", color="geekblue")
With Slot, we can adjust the page more freely!
Integrating with other Gradio components
modelscope_studio focuses more on page layout and component flexibility. If some features cannot be implemented with the components in modelscope-studio, developers can also easily embed other Gradio components and still use them together with modelscope-studio.
Modify the above code and add the button of Gradio in the upper right corner of the card:
modelscope-studio supports interactivity between different components. For example, in a common form submission scenario:
importgradioasgrimportmodelscope_studio.components.antdasantdimportmodelscope_studio.components.baseasmsdefon_submit(_form):
print(_form) # the Form Component will automatically collect the form datawithgr.Blocks() asdemo:
withms.Application():
withantd.ConfigProvider():
withantd.Card(elem_style=dict(width=800, margin="0 auto")):
withantd.Form(variant="outlined",
label_col=dict(span=4),
wrapper_col=dict(span=20)) asform:
withantd.Form.Item(form_name="username",
label="Username",
tooltip="This is a required field",
rules=[{
"required":
True,
"message":
'Please input your username!'
}]):
antd.Input()
withantd.Form.Item(form_name="password",
label="Password",
tooltip="This is a required field",
rules=[{
"required":
True,
"message":
'Please input your password!'
}]):
antd.Input.Password()
withantd.Form.Item(form_name="files", label="Upload"):
withantd.Upload.Dragger():
withms.Div(elem_style=dict(fontSize=40,
color="#1677ff")):
antd.Icon("InboxOutlined")
antd.Typography.Paragraph(
"Click or drag file to this area to upload")
antd.Typography.Paragraph(
"Support for a single or bulk upload.",
type="secondary")
withantd.Form.Item(
wrapper_col=dict(offset=4, span=20),
form_name="remember",
value_prop_name="checked",
):
withantd.Checkbox():
ms.Text("Remember me")
withantd.Form.Item(wrapper_col=dict(offset=4, span=20)):
submit_btn=antd.Button("Submit",
type="primary",
html_type="submit")
# Fired when a button with html_type of submit is clickedform.finish(on_submit, inputs=[form])
demo.launch()
In this example, developers can collect form data uniformly through context. (automatic collection can only be triggered by the form component provided by Ant Design)
Custom themes and i18n
Customize themes and i18n by passing theme and locale parameters to the antd.ConfigProvider component.
importgradioasgrimportmodelscope_studio.components.antdasantdimportmodelscope_studio.components.baseasmsdefon_submit(_form):
print(_form) # the Form Component will automatically collect the form datawithgr.Blocks() asdemo:
withms.Application():
withantd.ConfigProvider():
withantd.Card(elem_style=dict(width=800, margin="0 auto")):
withantd.Form(variant="outlined",
label_col=dict(span=4),
wrapper_col=dict(span=20)) asform:
withantd.Form.Item(form_name="username",
label="Username",
tooltip="This is a required field",
rules=[{
"required":
True,
"message":
'Please input your username!'
}]):
antd.Input()
withantd.Form.Item(form_name="password",
label="Password",
tooltip="This is a required field",
rules=[{
"required":
True,
"message":
'Please input your password!'
}]):
antd.Input.Password()
withantd.Form.Item(form_name="files", label="Upload"):
withantd.Upload.Dragger():
withms.Div(elem_style=dict(fontSize=40,
color="#1677ff")):
antd.Icon("InboxOutlined")
antd.Typography.Paragraph(
"Click or drag file to this area to upload")
antd.Typography.Paragraph(
"Support for a single or bulk upload.",
type="secondary")
withantd.Form.Item(
wrapper_col=dict(offset=4, span=20),
form_name="remember",
value_prop_name="checked",
):
withantd.Checkbox():
ms.Text("Remember me")
withantd.Form.Item(wrapper_col=dict(offset=4, span=20)):
submit_btn=antd.Button("Submit",
type="primary",
html_type="submit")
# Fired when a button with html_type of submit is clickedform.finish(on_submit, inputs=[form])
demo.launch()
English Version
modelscope_studio
is a third-party component library based on Gradio, offers developers more customized interface building capabilities and a richer variety of component usage forms.In version 1.0, we integrated components from Ant Design and ensure compatibility with most of its APIs. Now you can build your Gradio application with them.
Docs & Demo:
Install
Usage Example
Features
Layouts with slots
Different from the layout in Gradio, to make more flexible layouts,
modelscope-studio
provides aSlot
component for developers.For example, in Ant Design, there are some properties of type
ReactNode
(which can be simply understood as they accept components as parameters). and these properties cannot be directly passed through Python, they can only be implemented using theSlot
component.If we want to add some additional styles to the top of the Card in the example above:
With
Slot
, we can adjust the page more freely!Integrating with other Gradio components
modelscope_studio
focuses more on page layout and component flexibility. If some features cannot be implemented with the components inmodelscope-studio
, developers can also easily embed other Gradio components and still use them together withmodelscope-studio
.Modify the above code and add the button of Gradio in the upper right corner of the card:
Component context interactivity
modelscope-studio
supports interactivity between different components. For example, in a common form submission scenario:The submitted print result is:
In this example, developers can collect form data uniformly through context. (automatic collection can only be triggered by the form component provided by Ant Design)
Custom themes and i18n
Customize themes and i18n by passing
theme
andlocale
parameters to theantd.ConfigProvider
component.中文版
modelscope_studio
是一个基于 Gradio 的三方组件库,为开发者提供更定制化的界面搭建能力和更丰富的组件使用形式。在 1.0 版本中,我们与 Ant Design 中的组件进行了集成,并兼容其中大多数 API。现在你可以使用它们构建你的 Gradio 应用。
文档 & Demo:
下载
使用示例
特性
使用插槽布局
与 Gradio 本身的布局机制不同,为了实现更自由的布局,
modelscope-studio
为开发者提供了Slot
(插槽)组件。比如在 Ant Design 中,有一些类型为
ReactNode
的属性(可以简单理解为它们接收的参数是一个个组件),这些属性就无法直接通过 Python 传入,只能通过Slot
组件实现。在上面的示例中,如果我们希望给 Card 的顶部添加一些额外的样式:
通过
Slot
,我们就可以更加自由地对页面进行调整了!集成其他 Gradio 组件
modelscope-studio
更加关注页面布局和组件的灵活性,如果某些功能modelscope-studio
中的组件无法实现,开发者也可以很轻松地嵌入其他的 Gradio 组件,并且仍然可以和modelscope-studio
一起搭配使用。修改一下上面的代码,我们在卡片右上角加入 Gradio 自带的按钮:
组件上下文联动
modelscope-studio
支持不同组件之间的产生联动,以常见的表单提交场景为例:提交的打印结果为:
在这个示例中,开发者可以通过上下文统一收集表单数据。(自动收集只有 Ant Design 提供的表单组件才能触发哦)
自定义主题与国际化
通过为
antd.ConfigProvider
组件传递theme
和locale
等参数实现自定义主题和国际化。The text was updated successfully, but these errors were encountered: