Coloring commited on
Commit
9689f33
·
1 Parent(s): 651793a
app.py CHANGED
@@ -8,6 +8,8 @@ from helper.env import is_modelscope_studio
8
  from helper.Site import Site
9
  from legacy_app import legacy_demo
10
 
 
 
11
 
12
  def get_text(text: str, cn_text: str):
13
  if is_modelscope_studio:
@@ -572,7 +574,7 @@ tabs = [
572
  "label": get_text("Version 0.x", "0.x 版本"),
573
  "key": "legacy",
574
  "content": legacy_demo
575
- },
576
  ]
577
 
578
  site = Site(
 
8
  from helper.Site import Site
9
  from legacy_app import legacy_demo
10
 
11
+ is_dev = os.environ.get("GRADIO_WATCH_MODULE_NAME") == 'docs.app'
12
+
13
 
14
  def get_text(text: str, cn_text: str):
15
  if is_modelscope_studio:
 
574
  "label": get_text("Version 0.x", "0.x 版本"),
575
  "key": "legacy",
576
  "content": legacy_demo
577
+ } if not is_dev else None,
578
  ]
579
 
580
  site = Site(
components/antd/form/README-zh_CN.md CHANGED
@@ -5,4 +5,9 @@ High-performance form component with data domain management. Includes data entry
5
  ## Examples
6
 
7
  <demo name="basic"></demo>
8
- <demo name="form_rules" title="Form Rules"></demo>
 
 
 
 
 
 
5
  ## Examples
6
 
7
  <demo name="basic"></demo>
8
+ <demo name="form_rules" title="表单规则"></demo>
9
+ <demo name="dynamic_form" title="动态表单"></demo>
10
+
11
+ 通过修改`form_action`可以手动触发表单动作,每当`form_action`变化并触发对应表单动作时,都会自动重置`form_action`的值,以便后续多次调用。
12
+
13
+ <demo name="form_action" title="表单动作"></demo>
components/antd/form/README.md CHANGED
@@ -6,3 +6,8 @@ High-performance form component with data domain management. Includes data entry
6
 
7
  <demo name="basic"></demo>
8
  <demo name="form_rules" title="Form Rules"></demo>
 
 
 
 
 
 
6
 
7
  <demo name="basic"></demo>
8
  <demo name="form_rules" title="Form Rules"></demo>
9
+ <demo name="dynamic_form" title="Dynamic Form"></demo>
10
+
11
+ By modifying `form_action`, you can manually trigger a form action. Whenever `form_action` changes and triggers the corresponding form action, the value of `form_action` will be automatically reset for subsequent multiple calls.
12
+
13
+ <demo name="form_action" title="Form Action"></demo>
components/antd/form/demos/dynamic_form.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import modelscope_studio.components.antd as antd
3
+ import modelscope_studio.components.base as ms
4
+
5
+
6
+ def submit(form_value):
7
+ print(form_value)
8
+
9
+
10
+ def add(state_value):
11
+ count = len(state_value)
12
+ return state_value + [{
13
+ "form_name": str(count),
14
+ "label": "Label " + str(count)
15
+ }]
16
+
17
+
18
+ with gr.Blocks() as demo, ms.Application(), antd.ConfigProvider():
19
+ state = gr.State([{"form_name": "0", "label": "Label 0"}])
20
+ with antd.Form() as form:
21
+ with antd.Form.Item():
22
+ add_btn = antd.Button("Add List")
23
+
24
+ @gr.render(inputs=[state])
25
+ def render_inputs(state_data):
26
+ for item in state_data:
27
+ with antd.Form.Item(form_name=item["form_name"],
28
+ label=item["label"]):
29
+ antd.Input()
30
+
31
+ with antd.Form.Item():
32
+ antd.Button("Submit", type="primary", html_type="submit")
33
+ add_btn.click(fn=add, inputs=[state], outputs=[state])
34
+ form.finish(fn=submit, inputs=[form])
35
+
36
+ if __name__ == "__main__":
37
+ demo.queue().launch()
components/antd/form/demos/form_action.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import modelscope_studio.components.antd as antd
3
+ import modelscope_studio.components.base as ms
4
+
5
+
6
+ def on_submit(_form):
7
+ print(_form) # the Form Component will automatically collect the form data
8
+
9
+
10
+ def bind_action_event(action):
11
+
12
+ def on_action():
13
+ return gr.update(form_action=action)
14
+
15
+ return on_action
16
+
17
+
18
+ with gr.Blocks() as demo:
19
+ with ms.Application():
20
+ with antd.ConfigProvider():
21
+ with antd.Card(title="Out of the Form"):
22
+ submit_btn = antd.Button("Submit", type="primary")
23
+ reset_btn = antd.Button("Reset")
24
+ validate_btn = antd.Button("Validate")
25
+
26
+ with antd.Form(label_col=dict(span=8),
27
+ wrapper_col=dict(span=16)) as form:
28
+ with antd.Form.Item(
29
+ form_name="username",
30
+ label="Username",
31
+ rules=[{
32
+ "required": True,
33
+ "message": 'Please input your username!'
34
+ }, {
35
+ "pattern":
36
+ "^[a-zA-Z0-9]+$",
37
+ "message":
38
+ "Username can only contain letters and numbers!"
39
+ }, {
40
+ "min":
41
+ 6,
42
+ "message":
43
+ "Username must be at least 6 characters long!"
44
+ }, {
45
+ "max":
46
+ 20,
47
+ "message":
48
+ "Username must be at most 20 characters long!"
49
+ }]):
50
+ antd.Input()
51
+ with antd.Form.Item(
52
+ form_name="password",
53
+ label="Password",
54
+ rules=[
55
+ {
56
+ "required": True,
57
+ "message": 'Please input your password!'
58
+ },
59
+ {
60
+ # custom validator with javascript function
61
+ "validator":
62
+ """(rule, value, cb) => {
63
+ if (value !== '123') {
64
+ cb('Password must be "123"')
65
+ }
66
+ cb()
67
+ }"""
68
+ }
69
+ ]):
70
+ antd.Input.Password()
71
+
72
+ with antd.Form.Item(wrapper_col=dict(offset=8, span=16)):
73
+ antd.Button("Submit", type="primary", html_type="submit")
74
+ form.finish(on_submit, inputs=[form])
75
+ submit_btn.click(bind_action_event("submit"), outputs=[form])
76
+ reset_btn.click(bind_action_event("reset"), outputs=[form])
77
+ validate_btn.click(bind_action_event("validate"), outputs=[form])
78
+
79
+ if __name__ == "__main__":
80
+ demo.queue().launch()
helper/Site.py CHANGED
@@ -13,7 +13,7 @@ class Site:
13
  docs: dict,
14
  default_active_tab: str | None = None,
15
  logo: Component | Callable | None = None):
16
- self.tabs = tabs
17
  self.docs = docs
18
  self.default_active_tab = default_active_tab
19
  self.default_active_tab_item = next(
 
13
  docs: dict,
14
  default_active_tab: str | None = None,
15
  logo: Component | Callable | None = None):
16
+ self.tabs = [tab for tab in tabs if tab]
17
  self.docs = docs
18
  self.default_active_tab = default_active_tab
19
  self.default_active_tab_item = next(
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- modelscope_studio==1.4.6
2
  openai
 
1
+ modelscope_studio==1.5.0
2
  openai
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "modelscope_studio"
11
- version = "1.4.6"
12
  description = "A third-party component library based on Gradio."
13
  readme = "README.md"
14
  license = "Apache-2.0"
 
8
 
9
  [project]
10
  name = "modelscope_studio"
11
+ version = "1.5.0"
12
  description = "A third-party component library based on Gradio."
13
  readme = "README.md"
14
  license = "Apache-2.0"