Coloring commited on
Commit
d88e289
·
1 Parent(s): e08e97a

feat: update docs

Browse files
components/pro/multimodal_input/README-zh_CN.md CHANGED
@@ -16,6 +16,10 @@
16
 
17
  <demo name="extra_button"></demo>
18
 
 
 
 
 
19
  ### 上传配置
20
 
21
  <demo name="upload_config"></demo>
@@ -28,6 +32,7 @@
28
  | ------------- | -------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------- |
29
  | value | `dict \| MultimodalInputValue \| None` | None | 显示的默认值,格式为`{ "text":"", "files":[] }`。 |
30
  | loading | `bool \| None` | None | 输入框是否处处于加载状态,此时可以触发 `cancel` 事件。 |
 
31
  | auto_size | `bool \| { minRows?: number; maxRows?: number } \| None` | { "maxRows": 8 } | 自适应内容高度,可设置为 True \| False 或对象:{ "minRows": 2, "maxRows": 6 }。 |
32
  | read_only | `bool \| None` | None | 输入框是否为只读状态。 |
33
  | submit_type | `Literal['enter', 'shiftEnter'] \| None` | 'enter' | 输入框触发`submit`事件的方式。 |
 
16
 
17
  <demo name="extra_button"></demo>
18
 
19
+ ### Block 模式
20
+
21
+ <demo name="block_mode"></demo>
22
+
23
  ### 上传配置
24
 
25
  <demo name="upload_config"></demo>
 
32
  | ------------- | -------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------- |
33
  | value | `dict \| MultimodalInputValue \| None` | None | 显示的默认值,格式为`{ "text":"", "files":[] }`。 |
34
  | loading | `bool \| None` | None | 输入框是否处处于加载状态,此时可以触发 `cancel` 事件。 |
35
+ | mode | `inline \| block` | 'inline' | 输入框的渲染模式, 值为 `block` 时会将输入框与提交按钮分开渲染。 |
36
  | auto_size | `bool \| { minRows?: number; maxRows?: number } \| None` | { "maxRows": 8 } | 自适应内容高度,可设置为 True \| False 或对象:{ "minRows": 2, "maxRows": 6 }。 |
37
  | read_only | `bool \| None` | None | 输入框是否为只读状态。 |
38
  | submit_type | `Literal['enter', 'shiftEnter'] \| None` | 'enter' | 输入框触发`submit`事件的方式。 |
components/pro/multimodal_input/README.md CHANGED
@@ -16,6 +16,10 @@ A multimodal input component based on [Ant Design X](https://x.ant.design), supp
16
 
17
  <demo name="extra_button"></demo>
18
 
 
 
 
 
19
  ### Upload Configuration
20
 
21
  <demo name="upload_config"></demo>
@@ -24,16 +28,17 @@ A multimodal input component based on [Ant Design X](https://x.ant.design), supp
24
 
25
  ### Props
26
 
27
- | Attribute | Type | Default Value | Description |
28
- | ------------- | -------------------------------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------- |
29
- | value | `dict \| MultimodalInputValue \| None` | None | Default value to display, formatted as `{ "text":"", "files":[] }`. |
30
- | loading | `bool \| None` | None | Whether the input is in a loading state, in which case the `cancel` event can be triggered. |
31
- | auto_size | `bool \| { minRows?: number; maxRows?: number } \| None` | { "maxRows": 8 } | Height auto size feature, can be set to True \| False or an object { "minRows": 2, "maxRows": 6 }. |
32
- | read_only | `bool \| None` | None | Whether the input is read-only. |
33
- | submit_type | `Literal['enter', 'shiftEnter'] \| None` | 'enter' | How the input box triggers the `submit` event. |
34
- | placeholder | `str \| None` | None | Input placeholder text. |
35
- | disabled | `bool \| None` | None | Whether to disable. |
36
- | upload_config | `MultimodalInputUploadConfig \| dict \| None` | None | File upload configuration. |
 
37
 
38
  ### Slots
39
 
 
16
 
17
  <demo name="extra_button"></demo>
18
 
19
+ ### Block Mode
20
+
21
+ <demo name="block_mode"></demo>
22
+
23
  ### Upload Configuration
24
 
25
  <demo name="upload_config"></demo>
 
28
 
29
  ### Props
30
 
31
+ | Attribute | Type | Default Value | Description |
32
+ | ------------- | -------------------------------------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------- |
33
+ | value | `dict \| MultimodalInputValue \| None` | None | Default value to display, formatted as `{ "text":"", "files":[] }`. |
34
+ | loading | `bool \| None` | None | Whether the input is in a loading state, in which case the `cancel` event can be triggered. |
35
+ | mode | `inline \| block` | 'inline' | The rending mode of the input box. If `block`, the input box and the submit button will be rendered separately. |
36
+ | auto_size | `bool \| { minRows?: number; maxRows?: number } \| None` | { "maxRows": 8 } | Height auto size feature, can be set to True \| False or an object { "minRows": 2, "maxRows": 6 }. |
37
+ | read_only | `bool \| None` | None | Whether the input is read-only. |
38
+ | submit_type | `Literal['enter', 'shiftEnter'] \| None` | 'enter' | How the input box triggers the `submit` event. |
39
+ | placeholder | `str \| None` | None | Input placeholder text. |
40
+ | disabled | `bool \| None` | None | Whether to disable. |
41
+ | upload_config | `MultimodalInputUploadConfig \| dict \| None` | None | File upload configuration. |
42
 
43
  ### Slots
44
 
components/pro/multimodal_input/demos/block_mode.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+
3
+ import gradio as gr
4
+ import modelscope_studio.components.antd as antd
5
+ import modelscope_studio.components.antdx as antdx
6
+ import modelscope_studio.components.base as ms
7
+ import modelscope_studio.components.pro as pro
8
+
9
+
10
+ def submit(input_value, chatbot_value):
11
+ chatbot_value.append({
12
+ "role":
13
+ "user",
14
+ "content": [{
15
+ "type": "text",
16
+ "content": input_value["text"]
17
+ }, {
18
+ "type": "file",
19
+ "content": [file for file in input_value["files"]]
20
+ }]
21
+ })
22
+ chatbot_value.append({
23
+ "role": "assistant",
24
+ "loading": True,
25
+ "status": "pending"
26
+ })
27
+ yield gr.update(value=None, loading=True), gr.update(value=chatbot_value)
28
+ time.sleep(2)
29
+ chatbot_value[-1]["loading"] = False
30
+ chatbot_value[-1]["content"] = "Hello"
31
+ chatbot_value[-1]["status"] = "done"
32
+ yield gr.update(loading=False), gr.update(value=chatbot_value)
33
+
34
+
35
+ def cancel(chatbot_value):
36
+ chatbot_value[-1]["loading"] = False
37
+ chatbot_value[-1]["footer"] = "canceled"
38
+ chatbot_value[-1]["status"] = "done"
39
+ return gr.update(loading=False), gr.update(value=chatbot_value)
40
+
41
+
42
+ def clear():
43
+ return gr.update(value=None)
44
+
45
+
46
+ with gr.Blocks() as demo, ms.Application(), antdx.XProvider():
47
+ with antd.Flex(elem_style=dict(height=300), vertical=True):
48
+ chatbot = pro.Chatbot(height=0,
49
+ elem_style=dict(flex=1),
50
+ value=[{
51
+ "role": "user",
52
+ "content": "Hello"
53
+ }, {
54
+ "role": "assistant",
55
+ "content": "Hello"
56
+ }])
57
+ with pro.MultimodalInput(
58
+ mode="block",
59
+ auto_size=dict(minRows=2, maxRows=6),
60
+ upload_config=dict(
61
+ upload_button_tooltip="Attachments")) as input:
62
+ with ms.Slot("footer"):
63
+ with antd.Tooltip("Clear History"):
64
+ with antd.Button(value=None,
65
+ variant="text",
66
+ color="default") as clear_btn:
67
+ with ms.Slot("icon"):
68
+ antd.Icon("ClearOutlined")
69
+ submit_event = input.submit(fn=submit,
70
+ inputs=[input, chatbot],
71
+ outputs=[input, chatbot])
72
+ input.cancel(fn=cancel,
73
+ cancels=[submit_event],
74
+ inputs=[chatbot],
75
+ outputs=[input, chatbot],
76
+ queue=False)
77
+ clear_btn.click(fn=clear, outputs=[chatbot])
78
+
79
+ if __name__ == "__main__":
80
+ demo.queue().launch()
components/pro/multimodal_input/demos/upload_config.py CHANGED
@@ -28,6 +28,10 @@ with gr.Blocks() as demo, ms.Application(), antdx.XProvider():
28
  antd.Divider("Other Sources")
29
  pro.MultimodalInput(upload_config=MultimodalInputUploadConfig(
30
  allow_speech=True, allow_paste_file=True))
 
 
 
 
31
 
32
  if __name__ == "__main__":
33
  demo.queue().launch()
 
28
  antd.Divider("Other Sources")
29
  pro.MultimodalInput(upload_config=MultimodalInputUploadConfig(
30
  allow_speech=True, allow_paste_file=True))
31
+ pro.MultimodalInput(mode="block",
32
+ auto_size=dict(minRows=2, maxRows=6),
33
+ upload_config=MultimodalInputUploadConfig(
34
+ allow_speech=True, allow_paste_file=True))
35
 
36
  if __name__ == "__main__":
37
  demo.queue().launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- modelscope_studio==1.3.0
2
  openai
 
1
+ modelscope_studio==1.3.1
2
  openai
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "modelscope_studio"
11
- version = "1.3.0"
12
  description = "A third-party component library based on Gradio."
13
  readme = "README.md"
14
  license = "Apache-2.0"
@@ -226,6 +226,7 @@ artifacts = [
226
  "/backend/modelscope_studio/components/antdx/x_provider/templates",
227
  "/backend/modelscope_studio/components/pro/chatbot/templates",
228
  "/backend/modelscope_studio/components/pro/multimodal_input/templates",
 
229
  ]
230
 
231
  [tool.yapfignore]
 
8
 
9
  [project]
10
  name = "modelscope_studio"
11
+ version = "1.3.1"
12
  description = "A third-party component library based on Gradio."
13
  readme = "README.md"
14
  license = "Apache-2.0"
 
226
  "/backend/modelscope_studio/components/antdx/x_provider/templates",
227
  "/backend/modelscope_studio/components/pro/chatbot/templates",
228
  "/backend/modelscope_studio/components/pro/multimodal_input/templates",
229
+ "/backend/modelscope_studio/components/pro/web_sandbox/templates",
230
  ]
231
 
232
  [tool.yapfignore]