Coloring commited on
Commit
aa39585
1 Parent(s): a21d9fe

feat: add chart in markdown

Browse files
README-zh_CN.md CHANGED
@@ -1,4 +1,4 @@
1
- <h1>Modelscope Studio</h1>
2
 
3
  <p align="center">
4
  <img src="https://modelscope.oss-cn-beijing.aliyuncs.com/modelscope.gif" height="60" style="vertical-align: middle;"/>
@@ -9,7 +9,7 @@
9
  <p>
10
 
11
  <p align="center">
12
- <a href="https://github.com/modelscope/modelscope-studio">Github</a> | 🤖 <a href="https://modelscope.cn/studios/modelscope/modelscope-studio/summary">Modelscope Studio</a> | 🤗 <a href="https://huggingface.co/spaces/modelscope/modelscope-studio">HuggingFace Space</a>
13
 
14
  `modelscope_studio` 是一套基于 gradio 4.x 的扩展组件库,致力于服务于 ModelScope 创空间中对于 gradio 应用的各类扩展需求,目前主要聚集在对话场景增强、多模态场景以及一些其他垂直场景支持。
15
 
 
1
+ <h1>ModelScope Studio</h1>
2
 
3
  <p align="center">
4
  <img src="https://modelscope.oss-cn-beijing.aliyuncs.com/modelscope.gif" height="60" style="vertical-align: middle;"/>
 
9
  <p>
10
 
11
  <p align="center">
12
+ <a href="https://github.com/modelscope/modelscope-studio">GitHub</a> | 🤖 <a href="https://modelscope.cn/studios/modelscope/modelscope-studio/summary">ModelScope Studio</a> | 🤗 <a href="https://huggingface.co/spaces/modelscope/modelscope-studio">Hugging Face Space</a>
13
 
14
  `modelscope_studio` 是一套基于 gradio 4.x 的扩展组件库,致力于服务于 ModelScope 创空间中对于 gradio 应用的各类扩展需求,目前主要聚集在对话场景增强、多模态场景以及一些其他垂直场景支持。
15
 
README.md CHANGED
@@ -14,7 +14,7 @@ pinned: false
14
  license: apache-2.0
15
  ---
16
 
17
- <h1>Modelscope Studio</h1>
18
 
19
  <p align="center">
20
  <img src="https://modelscope.oss-cn-beijing.aliyuncs.com/modelscope.gif" height="60" style="vertical-align: middle;"/>
@@ -25,7 +25,7 @@ license: apache-2.0
25
  <p>
26
 
27
  <p align="center">
28
- <a href="https://github.com/modelscope/modelscope-studio">Github</a> | 🤖 <a href="https://modelscope.cn/studios/modelscope/modelscope-studio/summary">Modelscope Studio</a> | 🤗 <a href="https://huggingface.co/spaces/modelscope/modelscope-studio">HuggingFace Space</a>
29
 
30
  `modelscope_studio` is a set of extension component libraries based on gradio 4.x, dedicated to serving the various extension needs of gradio applications within the ModelScope Studio. It mainly focuses on enhancing conversational scenarios, supporting multimodal contexts, and providing assistance for various other specialized scenarios.
31
 
 
14
  license: apache-2.0
15
  ---
16
 
17
+ <h1>ModelScope Studio</h1>
18
 
19
  <p align="center">
20
  <img src="https://modelscope.oss-cn-beijing.aliyuncs.com/modelscope.gif" height="60" style="vertical-align: middle;"/>
 
25
  <p>
26
 
27
  <p align="center">
28
+ <a href="https://github.com/modelscope/modelscope-studio">GitHub</a> | 🤖 <a href="https://modelscope.cn/studios/modelscope/modelscope-studio/summary">ModelScope Studio</a> | 🤗 <a href="https://huggingface.co/spaces/modelscope/modelscope-studio">Hugging Face Space</a>
29
 
30
  `modelscope_studio` is a set of extension component libraries based on gradio 4.x, dedicated to serving the various extension needs of gradio applications within the ModelScope Studio. It mainly focuses on enhancing conversational scenarios, supporting multimodal contexts, and providing assistance for various other specialized scenarios.
31
 
components/Chatbot/README-zh_CN.md CHANGED
@@ -53,6 +53,12 @@ Observation: <result>「任意 md 内容,将作为完成调用的展示的下
53
 
54
  <demo name="select-box"></demo>
55
 
 
 
 
 
 
 
56
  ### 多 bot 场景
57
 
58
  <demo name="multi_bots"></demo>
@@ -131,8 +137,7 @@ class CustomComponentDict(TypedDict):
131
 
132
  ### event listeners
133
 
134
- | 事件 | 描述 |
135
- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
136
- | `mgr.Chatbot.flushed(fn, ···)` | 当打字机效果结束时触发。EventData 为:<br/> - index:当前 message 的 index tuple。<br/> - value:当前 message value。 |
137
-
138
- | `mgr.Chatbot.custom(fn, ···)` | 自定义标签触发事件时触发,EventData 为:<br/> - index:当前 message 的 index tuple ([message index, user group(index 0) or bot group(index 1), user/bot group index])。<br/> - tag:当前触发的标签。<br/> - tag_index:当前触发标签的 index,此 index 在 message 的 index tuple 基础上重新计算。<br/> - value:自定义传入的值。 |
 
53
 
54
  <demo name="select-box"></demo>
55
 
56
+ ### 支持图表展示
57
+
58
+ 在返回的内容中加入 `chart` 标签,更多用法详见 <tab-link component-tab="Markdown">Markdown 内置自定义标签</tab-link>
59
+
60
+ <demo name="chart"></demo>
61
+
62
  ### 多 bot 场景
63
 
64
  <demo name="multi_bots"></demo>
 
137
 
138
  ### event listeners
139
 
140
+ | 事件 | 描述 |
141
+ | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142
+ | `mgr.Chatbot.flushed(fn, ···)` | 当打字机效果结束时触发。EventData 为:<br/> - index:当前 message 的 index tuple。<br/> - value:当前 message value。 |
143
+ | `mgr.Chatbot.custom(fn, ···)` | 自定义标签触发事件时触发,EventData 为:<br/> - index:当前 message 的 index tuple ([message index, user group(index 0) or bot group(index 1), user/bot group index])。<br/> - tag:当前触发的标签。<br/> - tag_index:当前触发标签的 index,此 index 在 message 的 index tuple 基础上重新计算。<br/> - value:自定义传入的值。 |
 
components/Chatbot/README.md CHANGED
@@ -52,6 +52,12 @@ Include the `select-box` tag in the returned content for more usage details, see
52
 
53
  <demo name="select-box"></demo>
54
 
 
 
 
 
 
 
55
  ### Multi-bot Scenarios
56
 
57
  <demo name="multi_bots"></demo>
 
52
 
53
  <demo name="select-box"></demo>
54
 
55
+ ### Support for Chart Display
56
+
57
+ Include the `chart` tag in the returned content for more usage details, see <tab-link component-tab="Markdown">Markdown Built-in Custom Tags <tab-link component-tab="Markdown">.
58
+
59
+ <demo name="chart"></demo>
60
+
61
  ### Multi-bot Scenarios
62
 
63
  <demo name="multi_bots"></demo>
components/Chatbot/demos/accordion.py CHANGED
@@ -16,6 +16,7 @@ conversation = [
16
  None, {
17
  "text": f"""
18
  Use accordion tag:
 
19
  <accordion title="Using tool">
20
 
21
  ```json
 
16
  None, {
17
  "text": f"""
18
  Use accordion tag:
19
+
20
  <accordion title="Using tool">
21
 
22
  ```json
components/Chatbot/demos/chart.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+
5
+ import modelscope_studio as mgr
6
+
7
+ # echarts options, see: https://echarts.apache.org/en/index.html
8
+ option1 = {
9
+ "xAxis": {
10
+ "type": 'category',
11
+ "data": ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
12
+ },
13
+ "yAxis": {
14
+ "type": 'value',
15
+ },
16
+ "series": [
17
+ {
18
+ "data": [150, 230, 224, 218, 135, 147, 260],
19
+ "type": 'line',
20
+ },
21
+ ],
22
+ }
23
+
24
+ conversation = [
25
+ [
26
+ None, {
27
+ "text": f"""
28
+ Chart:
29
+ <chart options='{json.dumps(option1)}'></chart>
30
+ """
31
+ }
32
+ ],
33
+ ]
34
+
35
+ with gr.Blocks() as demo:
36
+ mgr.Chatbot(
37
+ value=conversation,
38
+ height=600,
39
+ )
40
+
41
+ if __name__ == "__main__":
42
+ demo.queue().launch()
components/Markdown/README-zh_CN.md CHANGED
@@ -27,6 +27,12 @@
27
 
28
  <demo name="select-box"></demo>
29
 
 
 
 
 
 
 
30
  ### 自定义标签(高阶用法,需要了解前端知识)
31
 
32
  <demo name="custom-tag"></demo>
@@ -81,6 +87,7 @@ class CustomComponentDict(TypedDict):
81
 
82
  - <tab-link tab="custom_tags/select-box">select-box</tab-link>
83
  - <tab-link tab="custom_tags/accordion">accordion</tab-link>
 
84
 
85
  ### event listeners
86
 
 
27
 
28
  <demo name="select-box"></demo>
29
 
30
+ ### 支持图表展示
31
+
32
+ 在返回的内容中加入 `chart` 标签,更多用法详见 <tab-link tab="custom_tags/chart">chart</tab-link>
33
+
34
+ <demo name="chart"></demo>
35
+
36
  ### 自定义标签(高阶用法,需要了解前端知识)
37
 
38
  <demo name="custom-tag"></demo>
 
87
 
88
  - <tab-link tab="custom_tags/select-box">select-box</tab-link>
89
  - <tab-link tab="custom_tags/accordion">accordion</tab-link>
90
+ - <tab-link tab="custom_tags/chart">chart</tab-link>
91
 
92
  ### event listeners
93
 
components/Markdown/README.md CHANGED
@@ -25,11 +25,16 @@ Include the `accordion` tag in the returned content for more usage details, see
25
  Include the `select-box` tag in the returned content for more usage details, see <tab-link tab="custom_tags/select-box">select-box</tab-link>
26
  <demo name="select-box"></demo>
27
 
 
 
 
 
 
28
  ### Custom Tags (Advanced Usage, Requires Frontend Knowledge)
29
 
30
  <demo name="custom-tag"></demo>
31
 
32
- #### Importing js
33
 
34
  <demo name="custom-tag2"></demo>
35
  The template can only perform simple variable replacements. If you want to introduce more custom behaviors, such as conditional judgments, loop rendering, etc., please use js to control the element for processing. Here is a simple example:
@@ -77,6 +82,7 @@ class CustomComponentDict(TypedDict):
77
 
78
  - <tab-link tab="custom_tags/select-box">select-box</tab-link>
79
  - <tab-link tab="custom_tags/accordion">accordion</tab-link>
 
80
 
81
  ### Event Listeners
82
 
 
25
  Include the `select-box` tag in the returned content for more usage details, see <tab-link tab="custom_tags/select-box">select-box</tab-link>
26
  <demo name="select-box"></demo>
27
 
28
+ ### Support for Chart Display
29
+
30
+ Include the `chart` tag in the returned content for more usage details, see <tab-link tab="custom_tags/chart">chart</tab-link>
31
+ <demo name="chart"></demo>
32
+
33
  ### Custom Tags (Advanced Usage, Requires Frontend Knowledge)
34
 
35
  <demo name="custom-tag"></demo>
36
 
37
+ #### Import JS
38
 
39
  <demo name="custom-tag2"></demo>
40
  The template can only perform simple variable replacements. If you want to introduce more custom behaviors, such as conditional judgments, loop rendering, etc., please use js to control the element for processing. Here is a simple example:
 
82
 
83
  - <tab-link tab="custom_tags/select-box">select-box</tab-link>
84
  - <tab-link tab="custom_tags/accordion">accordion</tab-link>
85
+ - <tab-link tab="custom_tags/chart">chart</tab-link>
86
 
87
  ### Event Listeners
88
 
components/Markdown/custom_tags/chart-zh_CN.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chart
2
+
3
+ 在 markdown 文本中添加图表。
4
+
5
+ ## 如何使用
6
+
7
+ ### 基本使用
8
+
9
+ <demo name="custom_tags/chart/basic"></demo>
10
+
11
+ ## API 及参数列表
12
+
13
+ ### props
14
+
15
+ | 属性 | 类型 | 默认值 | 描述 |
16
+ | ------- | ------ | ------ | ----------------------------------------------------------------------------------------- |
17
+ | options | object | | `echarts`的 options 配置,详见:[echarts docs](https://echarts.apache.org/en/option.html) |
components/Markdown/custom_tags/chart.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chart
2
+
3
+ Add a chart to markdown text.
4
+
5
+ ## How to Use
6
+
7
+ ### Basic Usage
8
+
9
+ <demo name="custom_tags/chart/basic"></demo>
10
+
11
+ ## API and Parameter List
12
+
13
+ ### props
14
+
15
+ | Attribute | Type | Default Value | Description |
16
+ | --------- | ------ | ------------- | --------------------------------------------------------------------------------- |
17
+ | options | object | | `echarts` options, see: [echarts docs](https://echarts.apache.org/en/option.html) |
components/Markdown/demos/chart.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+
5
+ import modelscope_studio as mgr
6
+
7
+ # echarts options, see: https://echarts.apache.org/en/index.html
8
+ option1 = {
9
+ "xAxis": {
10
+ "type": 'category',
11
+ "data": ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
12
+ },
13
+ "yAxis": {
14
+ "type": 'value',
15
+ },
16
+ "series": [
17
+ {
18
+ "data": [150, 230, 224, 218, 135, 147, 260],
19
+ "type": 'line',
20
+ },
21
+ ],
22
+ }
23
+
24
+ with gr.Blocks() as demo:
25
+ mgr.Markdown(f"""
26
+ Chart:
27
+ <chart options='{json.dumps(option1)}'></chart>
28
+ """)
29
+
30
+ if __name__ == "__main__":
31
+ demo.queue().launch()
components/Markdown/demos/custom_tags/chart/basic.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import gradio as gr
4
+
5
+ import modelscope_studio as mgr
6
+
7
+ # echarts options, see: https://echarts.apache.org/en/index.html
8
+ option1 = {
9
+ "xAxis": {
10
+ "type": 'category',
11
+ "data": ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
12
+ },
13
+ "yAxis": {
14
+ "type": 'value',
15
+ },
16
+ "series": [
17
+ {
18
+ "data": [150, 230, 224, 218, 135, 147, 260],
19
+ "type": 'line',
20
+ },
21
+ ],
22
+ }
23
+
24
+ option2 = {
25
+ "tooltip": {
26
+ "trigger": 'item'
27
+ },
28
+ "legend": {
29
+ "top": '5%',
30
+ "left": 'center'
31
+ },
32
+ "series": [{
33
+ "name":
34
+ 'Access From',
35
+ "type":
36
+ 'pie',
37
+ "radius": ['40%', '70%'],
38
+ "avoidLabelOverlap":
39
+ False,
40
+ "itemStyle": {
41
+ "borderRadius": 10,
42
+ "borderColor": '#fff',
43
+ "borderWidth": 2
44
+ },
45
+ "label": {
46
+ "show": False,
47
+ "position": 'center'
48
+ },
49
+ "emphasis": {
50
+ "label": {
51
+ "show": True,
52
+ "fontSize": 40,
53
+ "fontWeight": 'bold'
54
+ }
55
+ },
56
+ "labelLine": {
57
+ "show": False
58
+ },
59
+ "data": [{
60
+ "value": 1048,
61
+ "name": 'Search Engine'
62
+ }, {
63
+ "value": 735,
64
+ "name": 'Direct'
65
+ }, {
66
+ "value": 580,
67
+ "name": 'Email'
68
+ }, {
69
+ "value": 484,
70
+ "name": 'Union Ads'
71
+ }, {
72
+ "value": 300,
73
+ "name": 'Video Ads'
74
+ }]
75
+ }]
76
+ }
77
+
78
+ with gr.Blocks() as demo:
79
+ chatbot = mgr.Markdown(f"""<chart options='{json.dumps(option1)}'></chart>
80
+
81
+ <chart options='{json.dumps(option2)}'></chart>
82
+ """)
83
+ if __name__ == "__main__":
84
+ demo.queue().launch()
modelscope_studio-0.1.1-py3-none-any.whl → modelscope_studio-0.1.4-py3-none-any.whl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:be1efaf87fdc1b197182272a3d043cc5b832fbc8bf54c8fe89431aa5491b3a92
3
- size 6195613
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:918f05ea07a5ceffe1b6e759f288c214345f4f61b12b4315d9d61544b7196a4a
3
+ size 7456942
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  modelscope_studio
2
- modelscope_studio-0.1.1-py3-none-any.whl
 
1
  modelscope_studio
2
+ modelscope_studio-0.1.4-py3-none-any.whl
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "modelscope_studio"
11
- version = "0.1.1"
12
  description = "A set of extension component, inluding components for conversational input and display in multimodal scenarios, as well as more components for vertical scenarios."
13
  readme = "README.md"
14
  license = "Apache-2.0"
 
8
 
9
  [project]
10
  name = "modelscope_studio"
11
+ version = "0.1.4"
12
  description = "A set of extension component, inluding components for conversational input and display in multimodal scenarios, as well as more components for vertical scenarios."
13
  readme = "README.md"
14
  license = "Apache-2.0"