Spaces:
Running
Running
update
#1
by
justmywyw
- opened
This view is limited to 50 files because it contains too many changes.
See the raw diff here.
- .gitattributes +4 -2
- DOCS.md +15 -0
- Dockerfile +16 -0
- README-zh_CN.md +6 -45
- README.md +15 -55
- api/app.py +0 -19
- api/load-zh_CN.md +0 -30
- api/load.md +0 -30
- app.py +19 -526
- components/{legacy/Chatbot → Chatbot}/README-zh_CN.md +21 -36
- components/{legacy/Chatbot → Chatbot}/README.md +20 -35
- components/{antd/auto_complete → Chatbot}/app.py +1 -1
- components/Chatbot/demos/.DS_Store +0 -0
- components/{legacy/Chatbot → Chatbot}/demos/accordion.py +4 -8
- components/{legacy/Chatbot → Chatbot}/demos/basic.py +10 -11
- components/{legacy/Chatbot → Chatbot}/demos/message_config.py +2 -3
- components/{legacy/Chatbot → Chatbot}/demos/multi_bots.py +3 -4
- components/{legacy/Chatbot → Chatbot}/demos/multimodal.py +7 -4
- components/{legacy/Chatbot → Chatbot}/demos/select-box.py +4 -5
- components/{legacy → Chatbot}/resources/audio.wav +0 -0
- components/{legacy → Chatbot}/resources/bot.jpeg +0 -0
- components/Chatbot/resources/custom_components/custom_select.js +26 -0
- components/Chatbot/resources/dog.mp4 +3 -0
- components/{legacy → Chatbot}/resources/image-bot.jpeg +0 -0
- components/{legacy → Chatbot}/resources/music-bot.jpeg +0 -0
- components/{legacy → Chatbot}/resources/screen.jpeg +0 -0
- components/{legacy → Chatbot}/resources/user.jpeg +0 -0
- components/{legacy/Docs.py → Docs.py} +17 -35
- components/{legacy/Markdown → Markdown}/README-zh_CN.md +13 -23
- components/{legacy/Markdown → Markdown}/README.md +16 -25
- components/{legacy/Markdown → Markdown}/app.py +1 -1
- components/{legacy/Markdown → Markdown}/custom_tags/accordion-zh_CN.md +0 -0
- components/{legacy/Markdown → Markdown}/custom_tags/accordion.md +0 -0
- components/{legacy/Markdown → Markdown}/custom_tags/select-box-zh_CN.md +0 -0
- components/{legacy/Markdown → Markdown}/custom_tags/select-box.md +0 -0
- components/{legacy/Markdown → Markdown}/demos/accordion.py +6 -7
- components/{legacy/Markdown → Markdown}/demos/basic.py +2 -3
- components/{legacy/Markdown → Markdown}/demos/custom-tag.py +4 -5
- components/{legacy/Markdown → Markdown}/demos/custom-tag2.py +5 -23
- components/{legacy/Markdown → Markdown}/demos/custom-tag3.py +3 -4
- components/{legacy/Markdown → Markdown}/demos/custom-tag4.py +3 -4
- components/Markdown/demos/custom_tags/accordion/__pycache__/accordion-title.cpython-39.pyc +0 -0
- components/Markdown/demos/custom_tags/accordion/__pycache__/basic.cpython-39.pyc +0 -0
- components/{legacy/Markdown → Markdown}/demos/custom_tags/accordion/accordion-title.py +4 -5
- components/{legacy/Markdown → Markdown}/demos/custom_tags/accordion/basic.py +4 -5
- components/Markdown/demos/custom_tags/select-box/__pycache__/basic.cpython-39.pyc +0 -0
- components/Markdown/demos/custom_tags/select-box/__pycache__/card_shape.cpython-39.pyc +0 -0
- components/Markdown/demos/custom_tags/select-box/__pycache__/card_shape_width_auto.cpython-39.pyc +0 -0
- components/Markdown/demos/custom_tags/select-box/__pycache__/python_events.cpython-39.pyc +0 -0
- components/{legacy/Markdown → Markdown}/demos/custom_tags/select-box/basic.py +4 -5
.gitattributes
CHANGED
@@ -31,5 +31,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
31 |
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
32 |
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
33 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
35 |
-
|
|
|
|
|
|
31 |
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
32 |
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
33 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -textcomponents/Chatbot/resources/dog.mp4 filter=lfs diff=lfs merge=lfs -text
|
35 |
+
components/Markdown/resources/dog.mp4 filter=lfs diff=lfs merge=lfs -text
|
36 |
+
modelscope_gradio_components-0.0.1b8-py3-none-any.whl filter=lfs diff=lfs merge=lfs -text
|
37 |
+
components/Chatbot/resources/dog.mp4 filter=lfs diff=lfs merge=lfs -text
|
DOCS.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ModelScope Gradio Components
|
2 |
+
|
3 |
+
ModelScope_Gradio_Components 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.
|
4 |
+
|
5 |
+
## Install
|
6 |
+
|
7 |
+
```sh
|
8 |
+
pip install modelscope_gradio_components
|
9 |
+
```
|
10 |
+
|
11 |
+
## Components
|
12 |
+
|
13 |
+
- <tab-link component-tab="Chatbot">Chatbot</tab-link>
|
14 |
+
- <tab-link component-tab="MultimodalInput">MultimodalInput</tab-link>
|
15 |
+
- <tab-link component-tab="Markdown">Markdown</tab-link>
|
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
FROM python:3.9
|
3 |
+
|
4 |
+
WORKDIR /code
|
5 |
+
|
6 |
+
COPY --link --chown=1000 . .
|
7 |
+
|
8 |
+
RUN mkdir -p /tmp/cache/
|
9 |
+
RUN chmod a+rwx -R /tmp/cache/
|
10 |
+
ENV TRANSFORMERS_CACHE=/tmp/cache/
|
11 |
+
|
12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
13 |
+
|
14 |
+
ENV PYTHONUNBUFFERED=1 GRADIO_ALLOW_FLAGGING=never GRADIO_NUM_PORTS=1 GRADIO_SERVER_NAME=0.0.0.0 GRADIO_SERVER_PORT=7860 SYSTEM=spaces
|
15 |
+
|
16 |
+
CMD ["python", "app.py"]
|
README-zh_CN.md
CHANGED
@@ -1,54 +1,15 @@
|
|
1 |
# ModelScope Studio
|
2 |
|
3 |
-
|
4 |
-
<img src="https://modelscope.oss-cn-beijing.aliyuncs.com/modelscope.gif" height="60" style="vertical-align: middle;"/>
|
5 |
-
<span style="font-size: 30px; vertical-align: middle;">
|
6 |
-
✖️
|
7 |
-
</span>
|
8 |
-
<img src="https://img.alicdn.com/imgextra/i1/O1CN01OmXst929933KJd7og_!!6000000008024-55-tps-2016-703.svg" height="60" style="vertical-align: middle;">
|
9 |
-
<p>
|
10 |
|
11 |
-
|
12 |
-
<a href="https://github.com/modelscope/modelscope-studio">GitHub</a> | 🤖 <a href="https://modelscope.cn/studios/modelscope/modelscope-studio">ModelScope Studio</a> | 🤗 <a href="https://huggingface.co/spaces/modelscope/modelscope-studio">Hugging Face Space</a>
|
13 |
-
|
14 |
-
`modelscope_studio`是一个基于 Gradio 的三方组件库,为开发者提供更定制化的界面搭建能力和更丰富的组件使用形式。
|
15 |
-
|
16 |
-
目前支持的 UI 库:
|
17 |
-
|
18 |
-
- [Ant Design](https://ant.design/)
|
19 |
-
|
20 |
-
## 何时使用
|
21 |
-
|
22 |
-
比起 Gradio 自身的组件,`modelscope_studio`更加注重页面布局和组件的灵活性,如果您想要构建更漂亮的用户界面,我们非常推荐您使用`modelscope_studio`。
|
23 |
-
|
24 |
-
然而,当您的应用需要 Gradio 在 Python 端更多地处理内置数据时,`modelscope_studio`的组件可能不是最好的选择,但是不用担心,它可以很好地与已有的 Gradio 组件相结合,您仍然可以使用`modelscope_studio`来优化您的应用。
|
25 |
-
|
26 |
-
## 依赖
|
27 |
-
|
28 |
-
- Gradio >= 4.0
|
29 |
-
|
30 |
-
## 安装
|
31 |
|
32 |
```sh
|
33 |
pip install modelscope_studio
|
34 |
```
|
35 |
|
36 |
-
##
|
37 |
-
|
38 |
-
<demo name="example"></demo>
|
39 |
-
|
40 |
-
## 迁移到 1.0
|
41 |
-
|
42 |
-
如果您在之前使用了`modelscope_studio`的组件,并且想要在新版本中继续使用。不需要对原有组件做任何修改,只需要在外层引入`ms.Application`即可。
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
import modelscope_studio.components.legacy as mgr
|
48 |
-
|
49 |
-
with gr.Blocks() as demo:
|
50 |
-
with ms.Application():
|
51 |
-
mgr.Chatbot()
|
52 |
-
|
53 |
-
demo.launch()
|
54 |
-
```
|
|
|
1 |
# ModelScope Studio
|
2 |
|
3 |
+
`modelscope_studio` 是一套基于 gradio 4.x 的扩展组件库,致力于服务于 ModelScope 创空间中对于 gradio 应用的各类扩展需求,目前主要聚集在对话场景增强、多模态场景以及一些其他垂直场景支持。
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
## Install
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
```sh
|
8 |
pip install modelscope_studio
|
9 |
```
|
10 |
|
11 |
+
## Components
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
- <tab-link component-tab="Chatbot">Chatbot</tab-link>
|
14 |
+
- <tab-link component-tab="MultimodalInput">MultimodalInput</tab-link>
|
15 |
+
- <tab-link component-tab="Markdown">Markdown</tab-link>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
@@ -1,71 +1,31 @@
|
|
1 |
---
|
2 |
tags:
|
3 |
- gradio-custom-component
|
4 |
-
-
|
5 |
-
-
|
6 |
-
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
pinned: false
|
13 |
-
header: mini
|
14 |
-
app_file: app.py
|
15 |
license: apache-2.0
|
16 |
---
|
17 |
|
18 |
# ModelScope Studio
|
19 |
|
20 |
-
|
21 |
-
<img src="https://modelscope.oss-cn-beijing.aliyuncs.com/modelscope.gif" height="60" style="vertical-align: middle;"/>
|
22 |
-
<span style="font-size: 30px; vertical-align: middle;">
|
23 |
-
✖️
|
24 |
-
</span>
|
25 |
-
<img src="https://github.com/gradio-app/gradio/raw/main/readme_files/gradio.svg" height="60" style="vertical-align: middle;">
|
26 |
-
<p>
|
27 |
|
28 |
-
|
29 |
-
<a href="https://github.com/modelscope/modelscope-studio">GitHub</a> | 🤖 <a href="https://modelscope.cn/studios/modelscope/modelscope-studio">ModelScope Studio</a> | 🤗 <a href="https://huggingface.co/spaces/modelscope/modelscope-studio">Hugging Face Space</a>
|
30 |
-
|
31 |
-
`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.
|
32 |
-
|
33 |
-
Currently supported UI libraries:
|
34 |
-
|
35 |
-
- [Ant Design](https://ant.design/)
|
36 |
-
|
37 |
-
## When to Use
|
38 |
-
|
39 |
-
Compared to the original components of Gradio, `modelscope_studio` focuses more on page layout and component flexibility. If you want to build a more beautiful user interface, we highly recommend using `modelscope_studio`.
|
40 |
-
|
41 |
-
However, when your application needs Gradio to handle more built-in data on the Python side, the components of `modelscope_studio` may not be the best choice, but don't worry, it integrates well with existing Gradio components, you can still use `modelscope_studio` to optimize your application.
|
42 |
-
|
43 |
-
## Dependencies
|
44 |
-
|
45 |
-
- Gradio >= 4.0
|
46 |
-
|
47 |
-
## Installation
|
48 |
|
49 |
```sh
|
50 |
pip install modelscope_studio
|
51 |
```
|
52 |
|
53 |
-
##
|
54 |
-
|
55 |
-
<demo name="example"></demo>
|
56 |
-
|
57 |
-
## Migration to 1.0
|
58 |
-
|
59 |
-
If you have used the `modelscope_studio` component before and want to continue using it in the new version, you do not need to make any changes to the original component, just import `ms.Application` in the outer layer.
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
import modelscope_studio.components.legacy as mgr
|
65 |
-
|
66 |
-
with gr.Blocks() as demo:
|
67 |
-
with ms.Application():
|
68 |
-
mgr.Chatbot()
|
69 |
-
|
70 |
-
demo.launch()
|
71 |
-
```
|
|
|
1 |
---
|
2 |
tags:
|
3 |
- gradio-custom-component
|
4 |
+
- Chatbot
|
5 |
+
- MutilmodalInput
|
6 |
+
- Markdown
|
7 |
+
- gradio-template-Chatbot
|
8 |
+
- gradio-template-Markdown
|
9 |
+
title: modelscope_gradio_components V0.0.1b8
|
10 |
+
colorFrom: red
|
11 |
+
colorTo: red
|
12 |
+
sdk: docker
|
13 |
pinned: false
|
|
|
|
|
14 |
license: apache-2.0
|
15 |
---
|
16 |
|
17 |
# ModelScope Studio
|
18 |
|
19 |
+
`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.
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
## Install
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
```sh
|
24 |
pip install modelscope_studio
|
25 |
```
|
26 |
|
27 |
+
## Components
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
- <tab-link component-tab="Chatbot">Chatbot</tab-link>
|
30 |
+
- <tab-link component-tab="MultimodalInput">MultimodalInput</tab-link>
|
31 |
+
- <tab-link component-tab="Markdown">Markdown</tab-link>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/app.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
-
from components.legacy.Docs import Docs
|
4 |
-
|
5 |
-
|
6 |
-
def resolve(relative_path: str):
|
7 |
-
return os.path.join(os.path.dirname(__file__), relative_path)
|
8 |
-
|
9 |
-
|
10 |
-
docs = Docs(
|
11 |
-
__file__,
|
12 |
-
markdown_files=([
|
13 |
-
filename for filename in os.listdir(resolve('.'))
|
14 |
-
if filename.endswith(".md")
|
15 |
-
]),
|
16 |
-
)
|
17 |
-
|
18 |
-
if __name__ == "__main__":
|
19 |
-
docs.render().queue().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/load-zh_CN.md
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
# load
|
2 |
-
|
3 |
-
该特性与 [gr.load](https://www.gradio.app/docs/gradio/load) 类似。允许用户从已有创空间 [ModelScope Studio](https://modelscope.cn/studios) 仓库构造 demo。
|
4 |
-
|
5 |
-
## 如何使用
|
6 |
-
|
7 |
-
### 基本使用
|
8 |
-
|
9 |
-
```python
|
10 |
-
import modelscope_studio.components.legacy as mgr
|
11 |
-
demo = mgr.load("modelscope/modelscope-studio")
|
12 |
-
demo.launch()
|
13 |
-
```
|
14 |
-
|
15 |
-
### 使用访问令牌
|
16 |
-
|
17 |
-
使用访问令牌来加载私有创空间。在这里找到您的 sdk 令牌:https://modelscope.cn/my/myaccesstoken。
|
18 |
-
|
19 |
-
```python
|
20 |
-
import modelscope_studio.components.legacy as mgr
|
21 |
-
demo = mgr.load("modelscope/modelscope-studio", token="YOUR_ACCESS_TOKEN")
|
22 |
-
demo.launch()
|
23 |
-
```
|
24 |
-
|
25 |
-
## 初始化
|
26 |
-
|
27 |
-
| 属性 | 类型 | 默认值 | 描述 |
|
28 |
-
| ----- | ---- | ------ | ---------------------------------------------------------------------------------------------------- |
|
29 |
-
| name | str | None | 必填。 创空间名称(如: "modelscope/modelscope-studio")。 |
|
30 |
-
| token | str | None | 用于加载私有创空间的可选访问令牌。 在这里找到您的 sdk 令牌:https://modelscope.cn/my/myaccesstoken。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/load.md
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
# load
|
2 |
-
|
3 |
-
This feature is similar to [gr.load](https://www.gradio.app/docs/gradio/load). Allow users to Construct a demo from a [ModelScope Studio](https://modelscope.cn/studios) repo.
|
4 |
-
|
5 |
-
## How to Use
|
6 |
-
|
7 |
-
### Basic Usage
|
8 |
-
|
9 |
-
```python
|
10 |
-
import modelscope_studio.components.legacy as mgr
|
11 |
-
demo = mgr.load("modelscope/modelscope-studio")
|
12 |
-
demo.launch()
|
13 |
-
```
|
14 |
-
|
15 |
-
### With Access Token
|
16 |
-
|
17 |
-
Use the access token to load a private ModelScope Studio repo. Find your sdk token here: https://modelscope.cn/my/myaccesstoken.
|
18 |
-
|
19 |
-
```python
|
20 |
-
import modelscope_studio.components.legacy as mgr
|
21 |
-
demo = mgr.load("modelscope/modelscope-studio", token="YOUR_ACCESS_TOKEN")
|
22 |
-
demo.launch()
|
23 |
-
```
|
24 |
-
|
25 |
-
## Initialization
|
26 |
-
|
27 |
-
| Parameter | Type | Default Value | Description |
|
28 |
-
| --------- | ---- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
29 |
-
| name | str | None | required. the name of the ModelScope Studio repo (e.g. "modelscope/modelscope-studio"). |
|
30 |
-
| token | str | None | optional access token for loading private ModelScope Studio repo. Find your sdk token here: https://modelscope.cn/my/myaccesstoken. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,529 +1,22 @@
|
|
1 |
-
import
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
return cn_text
|
15 |
-
return text
|
16 |
-
|
17 |
-
|
18 |
-
def get_docs(type: Literal["antd", "antdx", "base"]):
|
19 |
-
import importlib.util
|
20 |
-
|
21 |
-
components = []
|
22 |
-
components_dir = os.path.join(os.path.dirname(__file__), "components",
|
23 |
-
type)
|
24 |
-
for dir in os.listdir(components_dir):
|
25 |
-
abs_dir = os.path.join(components_dir, dir)
|
26 |
-
if os.path.isdir(abs_dir):
|
27 |
-
app_file = os.path.join(abs_dir, "app.py")
|
28 |
-
if os.path.exists(app_file):
|
29 |
-
components.append(dir)
|
30 |
-
|
31 |
-
docs = {}
|
32 |
-
for component in components:
|
33 |
-
spec = importlib.util.spec_from_file_location(
|
34 |
-
"doc", os.path.join(components_dir, component, "app.py"))
|
35 |
-
module = importlib.util.module_from_spec(spec)
|
36 |
-
spec.loader.exec_module(module)
|
37 |
-
docs[component] = module.docs
|
38 |
-
return docs
|
39 |
-
|
40 |
-
|
41 |
-
def get_layout_templates():
|
42 |
-
import importlib.util
|
43 |
-
|
44 |
-
templates = []
|
45 |
-
templates_dir = os.path.join(os.path.dirname(__file__), "layout_templates")
|
46 |
-
for dir in os.listdir(templates_dir):
|
47 |
-
abs_dir = os.path.join(templates_dir, dir)
|
48 |
-
if os.path.isdir(abs_dir):
|
49 |
-
app_file = os.path.join(abs_dir, "app.py")
|
50 |
-
if os.path.exists(app_file):
|
51 |
-
templates.append(dir)
|
52 |
-
|
53 |
-
docs = {}
|
54 |
-
for template in templates:
|
55 |
-
spec = importlib.util.spec_from_file_location(
|
56 |
-
"doc", os.path.join(templates_dir, template, "app.py"))
|
57 |
-
module = importlib.util.module_from_spec(spec)
|
58 |
-
spec.loader.exec_module(module)
|
59 |
-
docs[template] = module.docs
|
60 |
-
return docs
|
61 |
-
|
62 |
-
|
63 |
-
layout_templates = get_layout_templates()
|
64 |
-
|
65 |
-
index_docs = {"overview": Docs(__file__), **layout_templates}
|
66 |
-
|
67 |
-
base_docs = get_docs("base")
|
68 |
-
antd_docs = get_docs("antd")
|
69 |
-
antdx_docs = get_docs("antdx")
|
70 |
-
|
71 |
-
default_active_tab = "index"
|
72 |
-
index_menu_items = [{
|
73 |
-
"label": get_text("ModelScope-Studio", "ModelScope-Studio"),
|
74 |
-
"key": "overview"
|
75 |
-
}, {
|
76 |
-
"label":
|
77 |
-
get_text("Layout Templates", "布局模板"),
|
78 |
-
"type":
|
79 |
-
"group",
|
80 |
-
"children": [{
|
81 |
-
"label": get_text("Coder-Artifacts", "Coder-Artifacts"),
|
82 |
-
"key": "coder_artifacts"
|
83 |
-
}]
|
84 |
-
}]
|
85 |
-
|
86 |
-
base_menu_items = [{
|
87 |
-
"label":
|
88 |
-
get_text("Core", "核心"),
|
89 |
-
"type":
|
90 |
-
"group",
|
91 |
-
"children": [{
|
92 |
-
"label": get_text("Application", "Application 应用"),
|
93 |
-
"key": "application"
|
94 |
-
}, {
|
95 |
-
"label": get_text("AutoLoading", "AutoLoading 自动加载"),
|
96 |
-
"key": "auto_loading"
|
97 |
-
}, {
|
98 |
-
"label": get_text("Slot", "Slot 插槽"),
|
99 |
-
"key": "slot"
|
100 |
-
}, {
|
101 |
-
"label": get_text("Fragment", "Fragment 片段"),
|
102 |
-
"key": "fragment"
|
103 |
-
}]
|
104 |
-
}, {
|
105 |
-
"label":
|
106 |
-
get_text("Layout", "布局"),
|
107 |
-
"type":
|
108 |
-
"group",
|
109 |
-
"children": [{
|
110 |
-
"label": "Div",
|
111 |
-
"key": "div"
|
112 |
-
}, {
|
113 |
-
"label": "Span",
|
114 |
-
"key": "span"
|
115 |
-
}, {
|
116 |
-
"label": "Text",
|
117 |
-
"key": "text"
|
118 |
-
}, {
|
119 |
-
"label": "Markdown",
|
120 |
-
"key": "markdown"
|
121 |
-
}]
|
122 |
-
}, {
|
123 |
-
"label":
|
124 |
-
get_text("Render", "渲染"),
|
125 |
-
"type":
|
126 |
-
"group",
|
127 |
-
"children": [{
|
128 |
-
"label": get_text("Each", "Each 循环"),
|
129 |
-
"key": "each"
|
130 |
-
}, {
|
131 |
-
"label": get_text("Filter", "Filter 过滤"),
|
132 |
-
"key": "filter"
|
133 |
-
}]
|
134 |
-
}]
|
135 |
-
|
136 |
-
antd_menu_items = [{
|
137 |
-
"label": get_text("Overview", "概览"),
|
138 |
-
"key": "overview"
|
139 |
-
}, {
|
140 |
-
"label":
|
141 |
-
get_text("General", "通用"),
|
142 |
-
"type":
|
143 |
-
"group",
|
144 |
-
"children": [{
|
145 |
-
"label": get_text("Button", "Button 按钮"),
|
146 |
-
"key": "button"
|
147 |
-
}, {
|
148 |
-
"label": get_text("FloatButton", "FloatButton 悬浮按钮"),
|
149 |
-
"key": "float_button"
|
150 |
-
}, {
|
151 |
-
"label": get_text("Icon", "Icon 图标"),
|
152 |
-
"key": "icon"
|
153 |
-
}, {
|
154 |
-
"label": get_text("Typography", "Typography 排版"),
|
155 |
-
"key": "typography"
|
156 |
-
}]
|
157 |
-
}, {
|
158 |
-
"label":
|
159 |
-
get_text("Layout", "布局"),
|
160 |
-
"type":
|
161 |
-
"group",
|
162 |
-
"children": [{
|
163 |
-
"label": get_text("Divider", "Divider 分割线"),
|
164 |
-
"key": "divider"
|
165 |
-
}, {
|
166 |
-
"label": get_text("Flex", "Flex 弹性布局"),
|
167 |
-
"key": "flex"
|
168 |
-
}, {
|
169 |
-
"label": get_text("Grid", "Grid 栅格"),
|
170 |
-
"key": "grid"
|
171 |
-
}, {
|
172 |
-
"label": get_text("Layout", "Layout 布局"),
|
173 |
-
"key": "layout"
|
174 |
-
}, {
|
175 |
-
"label": get_text("Space", "Space 间距"),
|
176 |
-
"key": "space"
|
177 |
-
}, {
|
178 |
-
"label": get_text("Splitter", "Splitter 分割面板"),
|
179 |
-
"key": "splitter"
|
180 |
-
}]
|
181 |
-
}, {
|
182 |
-
"label":
|
183 |
-
get_text("Navigation", "导航"),
|
184 |
-
"type":
|
185 |
-
"group",
|
186 |
-
"children": [{
|
187 |
-
"label": get_text("Anchor", "Anchor 锚点"),
|
188 |
-
"key": "anchor"
|
189 |
-
}, {
|
190 |
-
"label": get_text("Breadcrumb", "Breadcrumb 面包屑"),
|
191 |
-
"key": "breadcrumb"
|
192 |
-
}, {
|
193 |
-
"label": get_text("Dropdown", "Dropdown 下拉菜单"),
|
194 |
-
"key": "dropdown"
|
195 |
-
}, {
|
196 |
-
"label": get_text("Menu", "Menu 导航菜单"),
|
197 |
-
"key": "menu"
|
198 |
-
}, {
|
199 |
-
"label": get_text("Pagination", "Pagination 分页"),
|
200 |
-
"key": "pagination"
|
201 |
-
}, {
|
202 |
-
"label": get_text("Steps", "Steps 步骤条"),
|
203 |
-
"key": "steps"
|
204 |
-
}]
|
205 |
-
}, {
|
206 |
-
"label":
|
207 |
-
get_text("Data Entry", "数据录入"),
|
208 |
-
"type":
|
209 |
-
"group",
|
210 |
-
"children": [{
|
211 |
-
"label": get_text("AutoComplete", "AutoComplete 自动完成"),
|
212 |
-
"key": "auto_complete"
|
213 |
-
}, {
|
214 |
-
"label": get_text("Cascader", "Cascader 级联选择"),
|
215 |
-
"key": "cascader"
|
216 |
-
}, {
|
217 |
-
"label": get_text("Checkbox", "Checkbox 多选框"),
|
218 |
-
"key": "checkbox"
|
219 |
-
}, {
|
220 |
-
"label": get_text("ColorPicker", "ColorPicker 颜色选择器"),
|
221 |
-
"key": "color_picker"
|
222 |
-
}, {
|
223 |
-
"label": get_text("DatePicker", "DatePicker 日期选择框"),
|
224 |
-
"key": "date_picker"
|
225 |
-
}, {
|
226 |
-
"label": get_text("Form", "Form 表单"),
|
227 |
-
"key": "form"
|
228 |
-
}, {
|
229 |
-
"label": get_text("Input", "Input 输入框"),
|
230 |
-
"key": "input"
|
231 |
-
}, {
|
232 |
-
"label": get_text("InputNumber", "InputNumber 数字输入框"),
|
233 |
-
"key": "input_number"
|
234 |
-
}, {
|
235 |
-
"label": get_text("Mentions", "Mentions 提及"),
|
236 |
-
"key": "mentions"
|
237 |
-
}, {
|
238 |
-
"label": get_text("Radio", "Radio 单选框"),
|
239 |
-
"key": "radio"
|
240 |
-
}, {
|
241 |
-
"label": get_text("Rate", "Rate 评分"),
|
242 |
-
"key": "rate"
|
243 |
-
}, {
|
244 |
-
"label": get_text("Select", "Select 选择器"),
|
245 |
-
"key": "select"
|
246 |
-
}, {
|
247 |
-
"label": get_text("Slider", "Slider 滑动输入条"),
|
248 |
-
"key": "slider"
|
249 |
-
}, {
|
250 |
-
"label": get_text("Switch", "Switch 开关"),
|
251 |
-
"key": "switch"
|
252 |
-
}, {
|
253 |
-
"label": get_text("TimePicker", "TimePicker 时间选择器"),
|
254 |
-
"key": "time_picker"
|
255 |
-
}, {
|
256 |
-
"label": get_text("Transfer", "Transfer 穿梭框"),
|
257 |
-
"key": "transfer"
|
258 |
-
}, {
|
259 |
-
"label": get_text("TreeSelect", "TreeSelect 树选择"),
|
260 |
-
"key": "tree_select"
|
261 |
-
}, {
|
262 |
-
"label": get_text("Upload", "Upload 上传"),
|
263 |
-
"key": "upload"
|
264 |
-
}]
|
265 |
-
}, {
|
266 |
-
"label":
|
267 |
-
get_text("Data Display", "数据展示"),
|
268 |
-
"type":
|
269 |
-
"group",
|
270 |
-
"children": [{
|
271 |
-
"label": get_text("Avatar", "Avatar 头像"),
|
272 |
-
"key": "avatar"
|
273 |
-
}, {
|
274 |
-
"label": get_text("Badge", "Badge 徽标数"),
|
275 |
-
"key": "badge"
|
276 |
-
}, {
|
277 |
-
"label": get_text("Calendar", "Calendar 日历"),
|
278 |
-
"key": "calendar"
|
279 |
-
}, {
|
280 |
-
"label": get_text("Card", "Card 卡片"),
|
281 |
-
"key": "card"
|
282 |
-
}, {
|
283 |
-
"label": get_text("Carousel", "Carousel 走马灯"),
|
284 |
-
"key": "carousel"
|
285 |
-
}, {
|
286 |
-
"label": get_text("Collapse", "Collapse 折叠面板"),
|
287 |
-
"key": "collapse"
|
288 |
-
}, {
|
289 |
-
"label": get_text("Descriptions", "Descriptions 描述列表"),
|
290 |
-
"key": "descriptions"
|
291 |
-
}, {
|
292 |
-
"label": get_text("Empty", "Empty 空状态"),
|
293 |
-
"key": "empty"
|
294 |
-
}, {
|
295 |
-
"label": get_text("Image", "Image 图片"),
|
296 |
-
"key": "image"
|
297 |
-
}, {
|
298 |
-
"label": get_text("List", "List 列表"),
|
299 |
-
"key": "list"
|
300 |
-
}, {
|
301 |
-
"label": get_text("Popover", "Popover 气泡卡片"),
|
302 |
-
"key": "popover"
|
303 |
-
}, {
|
304 |
-
"label": get_text("QRCode", "QRCode 二维码"),
|
305 |
-
"key": "qr_code"
|
306 |
-
}, {
|
307 |
-
"label": get_text("Segmented", "Segmented 分段控制器"),
|
308 |
-
"key": "segmented"
|
309 |
-
}, {
|
310 |
-
"label": get_text("Statistic", "Statistic 统计数值"),
|
311 |
-
"key": "statistic"
|
312 |
-
}, {
|
313 |
-
"label": get_text("Table", "Table 表格"),
|
314 |
-
"key": "table"
|
315 |
-
}, {
|
316 |
-
"label": get_text("Tabs", "Tabs 标签页"),
|
317 |
-
"key": "tabs"
|
318 |
-
}, {
|
319 |
-
"label": get_text("Tag", "Tag 标签"),
|
320 |
-
"key": "tag"
|
321 |
-
}, {
|
322 |
-
"label": get_text("Timeline", "Timeline 时间轴"),
|
323 |
-
"key": "timeline"
|
324 |
-
}, {
|
325 |
-
"label": get_text("Tooltip", "Tooltip 文字提示"),
|
326 |
-
"key": "tooltip"
|
327 |
-
}, {
|
328 |
-
"label": get_text("Tour", "Tour 漫游式引导"),
|
329 |
-
"key": "tour"
|
330 |
-
}, {
|
331 |
-
"label": get_text("Tree", "Tree 树形控件"),
|
332 |
-
"key": "tree"
|
333 |
-
}]
|
334 |
-
}, {
|
335 |
-
"label":
|
336 |
-
get_text("Feedback", "反馈"),
|
337 |
-
"type":
|
338 |
-
"group",
|
339 |
-
"children": [{
|
340 |
-
"label": get_text("Alert", "Alert 警告提示"),
|
341 |
-
"key": "alert"
|
342 |
-
}, {
|
343 |
-
"label": get_text("Drawer", "Drawer 抽屉"),
|
344 |
-
"key": "drawer"
|
345 |
-
}, {
|
346 |
-
"label": get_text("Message", "Message 全局提示"),
|
347 |
-
"key": "message"
|
348 |
-
}, {
|
349 |
-
"label": get_text("Modal", "Modal 对话框"),
|
350 |
-
"key": "modal"
|
351 |
-
}, {
|
352 |
-
"label": get_text("Notification", "Notification 通知提醒框"),
|
353 |
-
"key": "notification"
|
354 |
-
}, {
|
355 |
-
"label": get_text("Popconfirm", "Popconfirm 气泡确认框"),
|
356 |
-
"key": "popconfirm"
|
357 |
-
}, {
|
358 |
-
"label": get_text("Progress", "Progress 进度条"),
|
359 |
-
"key": "progress"
|
360 |
-
}, {
|
361 |
-
"label": get_text("Result", "Result 结果"),
|
362 |
-
"key": "result"
|
363 |
-
}, {
|
364 |
-
"label": get_text("Skeleton", "Skeleton 骨架屏"),
|
365 |
-
"key": "skeleton"
|
366 |
-
}, {
|
367 |
-
"label": get_text("Spin", "Spin 加载中"),
|
368 |
-
"key": "spin"
|
369 |
-
}, {
|
370 |
-
"label": get_text("Watermark", "Watermark 水印"),
|
371 |
-
"key": "watermark"
|
372 |
-
}]
|
373 |
-
}, {
|
374 |
-
"label":
|
375 |
-
get_text("Other", "其他"),
|
376 |
-
"type":
|
377 |
-
"group",
|
378 |
-
"children": [{
|
379 |
-
"label": get_text("Affix", "Affix 固钉"),
|
380 |
-
"key": "affix"
|
381 |
-
}, {
|
382 |
-
"label": get_text("ConfigProvider", "ConfigProvider 全局化配置"),
|
383 |
-
"key": "config_provider"
|
384 |
-
}]
|
385 |
-
}]
|
386 |
-
|
387 |
-
antdx_menu_items = [{
|
388 |
-
"label": get_text("Overview", "概览"),
|
389 |
-
"key": "overview"
|
390 |
-
}, {
|
391 |
-
"label":
|
392 |
-
get_text("Common", "通用"),
|
393 |
-
"type":
|
394 |
-
"group",
|
395 |
-
"children": [{
|
396 |
-
"label": get_text("Bubble", "Bubble 对话气泡"),
|
397 |
-
"key": "bubble"
|
398 |
-
}, {
|
399 |
-
"label": get_text("Conversations", "Conversations 管理对话"),
|
400 |
-
"key": "conversations"
|
401 |
-
}]
|
402 |
-
}, {
|
403 |
-
"label":
|
404 |
-
get_text("Wake", "唤醒"),
|
405 |
-
"type":
|
406 |
-
"group",
|
407 |
-
"children": [{
|
408 |
-
"label": get_text("Welcome", "Welcome 欢迎"),
|
409 |
-
"key": "welcome"
|
410 |
-
}, {
|
411 |
-
"label": get_text("Prompts", "Prompts 提示集"),
|
412 |
-
"key": "prompts"
|
413 |
-
}]
|
414 |
-
}, {
|
415 |
-
"label":
|
416 |
-
get_text("Express", "表达"),
|
417 |
-
"type":
|
418 |
-
"group",
|
419 |
-
"children": [{
|
420 |
-
"label": get_text("Attachments", "Attachments 输入附件"),
|
421 |
-
"key": "attachments"
|
422 |
-
}, {
|
423 |
-
"label": get_text("Sender", "Sender 输入框"),
|
424 |
-
"key": "sender"
|
425 |
-
}, {
|
426 |
-
"label": get_text("Suggestion", "Suggestion 快捷指令"),
|
427 |
-
"key": "suggestion"
|
428 |
-
}]
|
429 |
-
}, {
|
430 |
-
"label":
|
431 |
-
get_text("Confirm", "确认"),
|
432 |
-
"type":
|
433 |
-
"group",
|
434 |
-
"children": [{
|
435 |
-
"label": get_text("ThoughtChain", "ThoughtChain 思考链"),
|
436 |
-
"key": "thought_chain"
|
437 |
-
}]
|
438 |
-
}, {
|
439 |
-
"label":
|
440 |
-
get_text("Tools", "工具"),
|
441 |
-
"type":
|
442 |
-
"group",
|
443 |
-
"children": [{
|
444 |
-
"label": get_text("XProvider", "XProvider 全局化配置"),
|
445 |
-
"key": "x_provider"
|
446 |
-
}]
|
447 |
-
}]
|
448 |
-
|
449 |
-
|
450 |
-
def logo():
|
451 |
-
with antd.Flex(align='center', gap=8):
|
452 |
-
antd.Image(os.path.join(os.path.dirname(__file__),
|
453 |
-
"./resources/modelscope.png"),
|
454 |
-
preview=False,
|
455 |
-
height=20,
|
456 |
-
elem_style=dict(width="auto"))
|
457 |
-
ms.Span('✖️')
|
458 |
-
antd.Image(os.path.join(os.path.dirname(__file__),
|
459 |
-
"./resources/gradio.png"),
|
460 |
-
preview=False,
|
461 |
-
height=40,
|
462 |
-
elem_style=dict(width="auto"))
|
463 |
-
|
464 |
-
|
465 |
-
def more_components():
|
466 |
-
with antd.Button(type="link",
|
467 |
-
block=True,
|
468 |
-
href="https://ant.design/components/overview/",
|
469 |
-
href_target="_blank",
|
470 |
-
elem_style=dict(display="block",
|
471 |
-
textAlign="left",
|
472 |
-
whiteSpace="nowrap",
|
473 |
-
textOverflow="ellipsis",
|
474 |
-
overflow="hidden")):
|
475 |
-
ms.Text(get_text("More Components", "更多组件"))
|
476 |
-
|
477 |
-
with ms.Slot("icon"):
|
478 |
-
antd.Icon("ExportOutlined", elem_style=dict(marginRight=4))
|
479 |
-
|
480 |
-
|
481 |
-
tabs = [
|
482 |
-
{
|
483 |
-
"label": get_text("Overview", "概览"),
|
484 |
-
"key": "index",
|
485 |
-
"default_active_key": "overview",
|
486 |
-
"menus": index_menu_items
|
487 |
-
},
|
488 |
-
{
|
489 |
-
"label": get_text("Base Components", "基础组件"),
|
490 |
-
"key": "base",
|
491 |
-
"default_active_key": "application",
|
492 |
-
"menus": base_menu_items
|
493 |
-
},
|
494 |
-
{
|
495 |
-
"label": get_text("Antd Components", "Antd 组件"),
|
496 |
-
"key": "antd",
|
497 |
-
"default_active_key": "overview",
|
498 |
-
"menus": antd_menu_items,
|
499 |
-
"extra_menu_footer": more_components
|
500 |
-
},
|
501 |
-
{
|
502 |
-
"label": get_text("Antdx Components", "Antdx 组件"),
|
503 |
-
"key": "antdx",
|
504 |
-
"default_active_key": "overview",
|
505 |
-
"menus": antdx_menu_items,
|
506 |
-
},
|
507 |
-
{
|
508 |
-
"label": get_text("Version 0.x", "0.x 版本"),
|
509 |
-
"key": "legacy",
|
510 |
-
"content": legacy_demo
|
511 |
-
},
|
512 |
]
|
513 |
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
"antd": antd_docs,
|
520 |
-
"antdx": antdx_docs,
|
521 |
-
"base": base_docs
|
522 |
-
},
|
523 |
-
default_active_tab=default_active_tab,
|
524 |
-
logo=logo)
|
525 |
-
|
526 |
-
demo = site.render()
|
527 |
|
528 |
-
|
529 |
-
demo.queue().launch(ssr_mode=False)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from components.Chatbot.app import docs as chatbot_docs
|
3 |
+
from components.Docs import Docs
|
4 |
+
from components.Markdown.app import docs as markdown_docs
|
5 |
+
from components.MultimodalInput.app import docs as multimodel_input_docs
|
6 |
+
|
7 |
+
readme_docs = Docs(__file__)
|
8 |
+
|
9 |
+
docs = [
|
10 |
+
["Quick Start", readme_docs],
|
11 |
+
["Chatbot", chatbot_docs],
|
12 |
+
["Markdown", markdown_docs],
|
13 |
+
["MultimodalInput", multimodel_input_docs],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
]
|
15 |
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
with gr.Tabs() as components_tabs:
|
18 |
+
for doc in docs:
|
19 |
+
with gr.TabItem(doc[0], id=doc[0]):
|
20 |
+
doc[1].render(components_tabs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
demo.queue().launch()
|
|
components/{legacy/Chatbot → Chatbot}/README-zh_CN.md
RENAMED
@@ -3,10 +3,9 @@
|
|
3 |
升级版的 gradio Chatbot。
|
4 |
|
5 |
- 支持前端匀速流式输出 message
|
6 |
-
-
|
7 |
-
- 内置标签(chart、select-box、accordion)
|
8 |
- 支持多 agent 场景
|
9 |
-
- 支持自定义渲染组件,并与 Python
|
10 |
|
11 |
## 如何使用
|
12 |
|
@@ -29,8 +28,8 @@
|
|
29 |
同时为了适配大模型的工具调用链路,额外对某些大模型的格式做了预设配置,支持下述格式的预设处理(会将下面的格式转换成上方`accordion`标签包裹形式)
|
30 |
|
31 |
```python
|
32 |
-
import modelscope_studio
|
33 |
-
from modelscope_studio.components.
|
34 |
|
35 |
# 添加 qwen 解析预设
|
36 |
mgr.Chatbot(llm_thinking_presets=[qwen()])
|
@@ -54,12 +53,6 @@ Observation: <result>「任意 md 内容,将作为完成调用的展示的下
|
|
54 |
|
55 |
<demo name="select-box"></demo>
|
56 |
|
57 |
-
### 支持图表展示
|
58 |
-
|
59 |
-
在返回的内容中加入 `chart` 标签,更多用法详见 <tab-link component-tab="Markdown">Markdown 内置自定义标签</tab-link>
|
60 |
-
|
61 |
-
<demo name="chart"></demo>
|
62 |
-
|
63 |
### 多 bot 场景
|
64 |
|
65 |
<demo name="multi_bots"></demo>
|
@@ -84,12 +77,6 @@ class FileMessage(GradioModel):
|
|
84 |
|
85 |
|
86 |
class MultimodalMessage(GradioModel):
|
87 |
-
# 默认以 index 为作为 id,id 改变会导致 message 重新渲染
|
88 |
-
id: Optional[str] = None
|
89 |
-
# message 容器的 elem id
|
90 |
-
elem_id: Optional[str] = None
|
91 |
-
# message 容器的 elem classes
|
92 |
-
elem_classes: Optional[List[str] | str] = None
|
93 |
name: Optional[str] = None
|
94 |
text: Optional[str] = None
|
95 |
flushing: Optional[bool] = None
|
@@ -109,21 +96,19 @@ class ChatbotData(GradioRootModel):
|
|
109 |
|
110 |
### props
|
111 |
|
112 |
-
| 属性
|
113 |
-
|
|
114 |
-
| flushing
|
115 |
-
| enable_base64
|
116 |
-
|
|
117 |
-
|
|
118 |
-
|
|
119 |
-
|
|
120 |
-
|
|
121 |
-
|
|
122 |
-
|
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
**CustomComponentDict 定义如下**
|
127 |
|
128 |
```python
|
129 |
class CustomComponentDict(TypedDict):
|
@@ -138,7 +123,7 @@ class CustomComponentDict(TypedDict):
|
|
138 |
|
139 |
### event listeners
|
140 |
|
141 |
-
| 事件 | 描述
|
142 |
-
| ------------------------------ |
|
143 |
-
| `mgr.Chatbot.flushed(fn, ···)` | 当打字机效果结束时触发。EventData 为:<br/> - index:当前 message 的 index tuple。<br/> - value:当前 message value。
|
144 |
-
| `mgr.Chatbot.custom(fn, ···)` | 自定义标签触发事件时触发,EventData 为:<br/> - index
|
|
|
3 |
升级版的 gradio Chatbot。
|
4 |
|
5 |
- 支持前端匀速流式输出 message
|
6 |
+
- 支持输出多模态内容(音频、视频、语音、文件、文本)
|
|
|
7 |
- 支持多 agent 场景
|
8 |
+
- 支持自定义渲染组件,并与 Python 侧事件交互
|
9 |
|
10 |
## 如何使用
|
11 |
|
|
|
28 |
同时为了适配大模型的工具调用链路,额外对某些大模型的格式做了预设配置,支持下述格式的预设处理(会将下面的格式转换成上方`accordion`标签包裹形式)
|
29 |
|
30 |
```python
|
31 |
+
import modelscope_studio as mgr
|
32 |
+
from modelscope_studio.components.Chatbot.llm_thinking_presets import qwen
|
33 |
|
34 |
# 添加 qwen 解析预设
|
35 |
mgr.Chatbot(llm_thinking_presets=[qwen()])
|
|
|
53 |
|
54 |
<demo name="select-box"></demo>
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
### 多 bot 场景
|
57 |
|
58 |
<demo name="multi_bots"></demo>
|
|
|
77 |
|
78 |
|
79 |
class MultimodalMessage(GradioModel):
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
name: Optional[str] = None
|
81 |
text: Optional[str] = None
|
82 |
flushing: Optional[bool] = None
|
|
|
96 |
|
97 |
### props
|
98 |
|
99 |
+
| 属性 | 类型 | 默认值 | 描述 |
|
100 |
+
| -------------------- | -------------------------------------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
101 |
+
| flushing | bool | True | 是否开启打字机效果。默认只有 bot 的 message 会开启,可以通过单独修改 message 的 flushing 属性精确控制每一条 message 的显示效果 |
|
102 |
+
| enable_base64 | bool | False | 是否支持渲染的内容为 base64,因为直接渲染 base64 有安全问题,默认为 False。 |
|
103 |
+
| preview | bool | True | 是否开启图片预览功能 |
|
104 |
+
| avatar_images | tuple\[str \| Path \| None \| dict \| list, str \| Path \| None \| dict\| list\] | None | 拓展gr.Chatbot的参数值,除了接收 url 外还可以接收 dict 和 list,dict 可以传入avatar和name字段,name字段在渲染时会显示在头像下方。 <br/> - 当传入 dict 时,必须包含有avatar字段。<br/> - 当传入 list 时,一般对应多 bot 模式,每一项可以接收前面所有的值,每个 bot 的头像与 message 中 bot 的位置一一对应 |
|
105 |
+
| avatar_image_align | Literal['top', 'middle', 'bottom'] | 'bottom' | 控制头像与 message 的对齐方式,默认为下对齐 |
|
106 |
+
| avatar_image_width | int | 45 | 头像与名称的宽度 |
|
107 |
+
| flushing_speed | int | 3 | 打字机速度,值为 1 - 10,值越大速度越快 |
|
108 |
+
| llm_thinking_presets | list\[dict\] | \[\] | llm 思考链路解析预设,可以将 llm 调用工具的输出格式转为固定的前端展示格式,需要从modelscope_studio.Chatbot.llm_thinking_presets引入,目前支持:qwen |
|
109 |
+
| custom_components | dict\[str, CustomComponentDict\] CustomComponentDict 定义见下方 | None | 支持用户定义自定义标签,并通过 js 控制标签渲染样式与触发 python 事件。 |
|
110 |
+
|
111 |
+
**CustomComponent 定义如下**
|
|
|
|
|
112 |
|
113 |
```python
|
114 |
class CustomComponentDict(TypedDict):
|
|
|
123 |
|
124 |
### event listeners
|
125 |
|
126 |
+
| 事件 | 描述 |
|
127 |
+
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
128 |
+
| `mgr.Chatbot.flushed(fn, ···)` | 当打字机效果结束时触发。EventData 为:<br/> - index:当前 message 的 index tuple。<br/> - value:当前 message value。 |
|
129 |
+
| `mgr.Chatbot.custom(fn, ···)` | 自定义标签触发事件时触发,EventData 为:<br/> - index:前 message 的 index tuple。<br/> - tag:当前触发的标签。<br/> - tag_index:当前触发标签的 index,此 index 在 mesage 的 index tuple 基础上重新计算。<br/> - value:自定义传入的值。 |
|
components/{legacy/Chatbot → Chatbot}/README.md
RENAMED
@@ -3,10 +3,9 @@
|
|
3 |
Upgraded gradio Chatbot.
|
4 |
|
5 |
- Supports uniform frontend streaming output of messages
|
6 |
-
- Supports output of multimodal content (audio, video,
|
7 |
-
- Built-in tags (chart, select-box, accordion)
|
8 |
- Supports multi-agent scenarios
|
9 |
-
- Supports custom rendering components and interaction with Python
|
10 |
|
11 |
## How to Use
|
12 |
|
@@ -28,8 +27,8 @@ Include the `accordion` tag in the returned content to add an accordion within t
|
|
28 |
Additionally, to adapt to the toolchain usage of large models, some preset configurations for certain large models have been made. Support for the following preset formats (which will be converted into the form wrapped by the above `accordion` tag).
|
29 |
|
30 |
```python
|
31 |
-
import modelscope_studio
|
32 |
-
from modelscope_studio.components.
|
33 |
|
34 |
# Add qwen preset
|
35 |
mgr.Chatbot(llm_thinking_presets=[qwen()])
|
@@ -49,16 +48,10 @@ Observation: <result>「Any md content will be displayed in the drop-down box wh
|
|
49 |
|
50 |
### Support for User Selection Interaction
|
51 |
|
52 |
-
Include the `select-box` tag in the returned content
|
53 |
|
54 |
<demo name="select-box"></demo>
|
55 |
|
56 |
-
### Support for Chart Display
|
57 |
-
|
58 |
-
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>.
|
59 |
-
|
60 |
-
<demo name="chart"></demo>
|
61 |
-
|
62 |
### Multi-bot Scenarios
|
63 |
|
64 |
<demo name="multi_bots"></demo>
|
@@ -83,12 +76,6 @@ class FileMessage(GradioModel):
|
|
83 |
|
84 |
|
85 |
class MultimodalMessage(GradioModel):
|
86 |
-
# By default, message index is used as id. it will cause the message to be re-rendered when id changed.
|
87 |
-
id: Optional[str] = None
|
88 |
-
# elem id of message container
|
89 |
-
elem_id: Optional[str] = None
|
90 |
-
# elem classes of message container
|
91 |
-
elem_classes: Optional[List[str] | str] = None
|
92 |
name: Optional[str] = None
|
93 |
text: Optional[str] = None
|
94 |
flushing: Optional[bool] = None
|
@@ -108,19 +95,17 @@ class ChatbotData(GradioRootModel):
|
|
108 |
|
109 |
### props
|
110 |
|
111 |
-
| Attribute
|
112 |
-
|
|
113 |
-
| flushing
|
114 |
-
| enable_base64
|
115 |
-
|
|
116 |
-
|
|
117 |
-
|
|
118 |
-
|
|
119 |
-
|
|
120 |
-
|
|
121 |
-
|
|
122 |
-
| llm_thinking_presets | list\[dict\] | \[\] | llm thinking link presets, which can convert the output format of llm calling tools into a fixed front-end display format. It needs to be imported from modelscope_studio.Chatbot.llm_thinking_presets, and currently supports: qwen. |
|
123 |
-
| custom_components | dict\[str, CustomComponentDict\] CustomComponentDict is defined below | None | Allows users to define custom tags and control tag rendering styles and trigger Python events through JS. |
|
124 |
|
125 |
**Definition of CustomComponent is as follows:**
|
126 |
|
@@ -137,7 +122,7 @@ See <tab-link component-tab="Markdown">Markdown Built-in Custom Tags</tab-link>
|
|
137 |
|
138 |
### event listeners
|
139 |
|
140 |
-
| Event | Description
|
141 |
-
| ------------------------------ |
|
142 |
-
| `mgr.Chatbot.flushed(fn, ···)` | Triggered when the typewriter effect ends. EventData is: <br/> - index: The index tuple of the current message.<br/> - value: The current message value.
|
143 |
-
| `mgr.Chatbot.custom(fn, ···)` | Triggered when a custom tag event occurs. EventData is: <br/> - index: The index tuple of the
|
|
|
3 |
Upgraded gradio Chatbot.
|
4 |
|
5 |
- Supports uniform frontend streaming output of messages
|
6 |
+
- Supports output of multimodal content (audio, video, voice, files, text)
|
|
|
7 |
- Supports multi-agent scenarios
|
8 |
+
- Supports custom rendering components and interaction with events on the Python side
|
9 |
|
10 |
## How to Use
|
11 |
|
|
|
27 |
Additionally, to adapt to the toolchain usage of large models, some preset configurations for certain large models have been made. Support for the following preset formats (which will be converted into the form wrapped by the above `accordion` tag).
|
28 |
|
29 |
```python
|
30 |
+
import modelscope_studio as mgr
|
31 |
+
from modelscope_studio.components.Chatbot.llm_thinking_presets import qwen
|
32 |
|
33 |
# Add qwen preset
|
34 |
mgr.Chatbot(llm_thinking_presets=[qwen()])
|
|
|
48 |
|
49 |
### Support for User Selection Interaction
|
50 |
|
51 |
+
Include the `select-box` 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">.
|
52 |
|
53 |
<demo name="select-box"></demo>
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
### Multi-bot Scenarios
|
56 |
|
57 |
<demo name="multi_bots"></demo>
|
|
|
76 |
|
77 |
|
78 |
class MultimodalMessage(GradioModel):
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
name: Optional[str] = None
|
80 |
text: Optional[str] = None
|
81 |
flushing: Optional[bool] = None
|
|
|
95 |
|
96 |
### props
|
97 |
|
98 |
+
| Attribute | Type | Default Value | Description |
|
99 |
+
| -------------------- | -------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
100 |
+
| flushing | bool | True | Whether to enable the typewriter effect. By default, only the bot's messages will have this effect, but you can control the display effect of each message precisely by modifying the flushing attribute of a message individually. |
|
101 |
+
| enable_base64 | bool | False | Whether to support rendering content as base64, since rendering base64 is not safe, the default is False. |
|
102 |
+
| preview | bool | True | Whether to enable image preview functionality. |
|
103 |
+
| avatar_images | tuple\[str \| Path \| None \| dict \| list, str \| Path \| None \| dict\| list\] | None | An extended parameter value for gr.Chatbot, in addition to accepting a URL, it can also accept a dict and list. The dict can include the fields avatar and name, where the name field will be displayed under the avatar when rendered. <br/> - When passing a dict, it must include an avatar field.<br/> - When passing a list, it generally corresponds to the multi-bot mode, where each item can receive all the aforementioned values, and each bot’s avatar matches with the position of the bot in the messages. |
|
104 |
+
| avatar_image_align | Literal['top', 'middle', 'bottom'] | 'bottom' | Controls the alignment of the avatar with the messages, default is bottom-aligned. |
|
105 |
+
| avatar_image_width | int | 45 | The width of the avatar and name. |
|
106 |
+
| flushing_speed | int | 3 | Typewriter speed, values range from 1 - 10, with larger values indicating faster speeds. |
|
107 |
+
| llm_thinking_presets | list\[dict\] | \[\] | llm thinking link presets, which can convert the output format of llm calling tools into a fixed front-end display format. It needs to be imported from modelscope_studio.Chatbot.llm_thinking_presets, and currently supports: qwen. |
|
108 |
+
| custom_components | dict\[str, CustomComponentDict\] CustomComponentDict is defined below | None | Allows users to define custom tags and control tag rendering styles and trigger Python events through JS. |
|
|
|
|
|
109 |
|
110 |
**Definition of CustomComponent is as follows:**
|
111 |
|
|
|
122 |
|
123 |
### event listeners
|
124 |
|
125 |
+
| Event | Description |
|
126 |
+
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
127 |
+
| `mgr.Chatbot.flushed(fn, ···)` | Triggered when the typewriter effect ends. EventData is: <br/> - index: The index tuple of the current message.<br/> - value: The current message value. |
|
128 |
+
| `mgr.Chatbot.custom(fn, ···)` | Triggered when a custom tag event occurs. EventData is: <br/> - index: The index tuple of the previous message.<br/> - tag: The current tag that triggered the event.<br/> - tag_index: The index of the current triggered tag, re-calculated based on the index tuple of the message.<br/> - value: The custom value passed in. |
|
components/{antd/auto_complete → Chatbot}/app.py
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
from
|
2 |
|
3 |
docs = Docs(__file__)
|
4 |
|
|
|
1 |
+
from components.Docs import Docs
|
2 |
|
3 |
docs = Docs(__file__)
|
4 |
|
components/Chatbot/demos/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
components/{legacy/Chatbot → Chatbot}/demos/accordion.py
RENAMED
@@ -1,14 +1,12 @@
|
|
1 |
import os
|
2 |
|
3 |
import gradio as gr
|
4 |
-
import modelscope_studio
|
5 |
-
|
6 |
-
from modelscope_studio.components.legacy.Chatbot.llm_thinking_presets import \
|
7 |
-
qwen
|
8 |
|
9 |
|
10 |
def resolve_assets(relative_path):
|
11 |
-
return os.path.join(os.path.dirname(__file__), "
|
12 |
relative_path)
|
13 |
|
14 |
|
@@ -17,13 +15,11 @@ conversation = [
|
|
17 |
None, {
|
18 |
"text": f"""
|
19 |
Use accordion tag:
|
20 |
-
|
21 |
<accordion title="Using tool">
|
22 |
|
23 |
```json
|
24 |
{{"text": "glorious weather", "resolution": "1024*1024"}}
|
25 |
```
|
26 |
-
|
27 |
</accordion>
|
28 |
|
29 |
Qwen preset:
|
@@ -40,7 +36,7 @@ Observation: <result>「Any md content will be displayed in the drop-down box wh
|
|
40 |
],
|
41 |
]
|
42 |
|
43 |
-
with gr.Blocks() as demo
|
44 |
mgr.Chatbot(
|
45 |
value=conversation,
|
46 |
llm_thinking_presets=[qwen()],
|
|
|
1 |
import os
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import modelscope_studio as mgr
|
5 |
+
from modelscope_studio.components.Chatbot.llm_thinking_presets import qwen
|
|
|
|
|
6 |
|
7 |
|
8 |
def resolve_assets(relative_path):
|
9 |
+
return os.path.join(os.path.dirname(__file__), "../resources",
|
10 |
relative_path)
|
11 |
|
12 |
|
|
|
15 |
None, {
|
16 |
"text": f"""
|
17 |
Use accordion tag:
|
|
|
18 |
<accordion title="Using tool">
|
19 |
|
20 |
```json
|
21 |
{{"text": "glorious weather", "resolution": "1024*1024"}}
|
22 |
```
|
|
|
23 |
</accordion>
|
24 |
|
25 |
Qwen preset:
|
|
|
36 |
],
|
37 |
]
|
38 |
|
39 |
+
with gr.Blocks() as demo:
|
40 |
mgr.Chatbot(
|
41 |
value=conversation,
|
42 |
llm_thinking_presets=[qwen()],
|
components/{legacy/Chatbot → Chatbot}/demos/basic.py
RENAMED
@@ -2,8 +2,7 @@ import os
|
|
2 |
import time
|
3 |
|
4 |
import gradio as gr
|
5 |
-
import modelscope_studio
|
6 |
-
import modelscope_studio.components.legacy as mgr
|
7 |
|
8 |
conversation = [
|
9 |
[
|
@@ -31,18 +30,18 @@ def flushed():
|
|
31 |
return gr.update(interactive=True)
|
32 |
|
33 |
|
34 |
-
with gr.Blocks() as demo
|
35 |
chatbot = mgr.Chatbot(
|
36 |
value=conversation,
|
37 |
avatar_images=[
|
38 |
-
os.path.join(os.path.dirname(__file__),
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
],
|
47 |
height=600,
|
48 |
)
|
|
|
2 |
import time
|
3 |
|
4 |
import gradio as gr
|
5 |
+
import modelscope_studio as mgr
|
|
|
6 |
|
7 |
conversation = [
|
8 |
[
|
|
|
30 |
return gr.update(interactive=True)
|
31 |
|
32 |
|
33 |
+
with gr.Blocks() as demo:
|
34 |
chatbot = mgr.Chatbot(
|
35 |
value=conversation,
|
36 |
avatar_images=[
|
37 |
+
os.path.join(os.path.dirname(__file__), "../resources/user.jpeg"),
|
38 |
+
{
|
39 |
+
"name":
|
40 |
+
"bot",
|
41 |
+
"avatar":
|
42 |
+
os.path.join(os.path.dirname(__file__),
|
43 |
+
"../resources/bot.jpeg")
|
44 |
+
}
|
45 |
],
|
46 |
height=600,
|
47 |
)
|
components/{legacy/Chatbot → Chatbot}/demos/message_config.py
RENAMED
@@ -1,8 +1,7 @@
|
|
1 |
import time
|
2 |
|
3 |
import gradio as gr
|
4 |
-
import modelscope_studio
|
5 |
-
import modelscope_studio.components.legacy as mgr
|
6 |
|
7 |
|
8 |
def submit(_chatbot):
|
@@ -26,7 +25,7 @@ def submit(_chatbot):
|
|
26 |
yield _chatbot
|
27 |
|
28 |
|
29 |
-
with gr.Blocks() as demo
|
30 |
chatbot = mgr.Chatbot(height=600, )
|
31 |
button = gr.Button("Submit")
|
32 |
button.click(fn=submit, inputs=[chatbot], outputs=[chatbot])
|
|
|
1 |
import time
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import modelscope_studio as mgr
|
|
|
5 |
|
6 |
|
7 |
def submit(_chatbot):
|
|
|
25 |
yield _chatbot
|
26 |
|
27 |
|
28 |
+
with gr.Blocks() as demo:
|
29 |
chatbot = mgr.Chatbot(height=600, )
|
30 |
button = gr.Button("Submit")
|
31 |
button.click(fn=submit, inputs=[chatbot], outputs=[chatbot])
|
components/{legacy/Chatbot → Chatbot}/demos/multi_bots.py
RENAMED
@@ -2,12 +2,11 @@ import os
|
|
2 |
import time
|
3 |
|
4 |
import gradio as gr
|
5 |
-
import modelscope_studio
|
6 |
-
import modelscope_studio.components.legacy as mgr
|
7 |
|
8 |
|
9 |
def resolve_assets(relative_path):
|
10 |
-
return os.path.join(os.path.dirname(__file__), "
|
11 |
relative_path)
|
12 |
|
13 |
|
@@ -58,7 +57,7 @@ def flushed():
|
|
58 |
return gr.update(interactive=True)
|
59 |
|
60 |
|
61 |
-
with gr.Blocks() as demo
|
62 |
chatbot = mgr.Chatbot(
|
63 |
value=conversation,
|
64 |
avatar_image_width=40,
|
|
|
2 |
import time
|
3 |
|
4 |
import gradio as gr
|
5 |
+
import modelscope_studio as mgr
|
|
|
6 |
|
7 |
|
8 |
def resolve_assets(relative_path):
|
9 |
+
return os.path.join(os.path.dirname(__file__), "../resources",
|
10 |
relative_path)
|
11 |
|
12 |
|
|
|
57 |
return gr.update(interactive=True)
|
58 |
|
59 |
|
60 |
+
with gr.Blocks() as demo:
|
61 |
chatbot = mgr.Chatbot(
|
62 |
value=conversation,
|
63 |
avatar_image_width=40,
|
components/{legacy/Chatbot → Chatbot}/demos/multimodal.py
RENAMED
@@ -1,12 +1,11 @@
|
|
1 |
import os
|
2 |
|
3 |
import gradio as gr
|
4 |
-
import modelscope_studio
|
5 |
-
import modelscope_studio.components.legacy as mgr
|
6 |
|
7 |
|
8 |
def resolve_assets(relative_path):
|
9 |
-
return os.path.join(os.path.dirname(__file__), "
|
10 |
relative_path)
|
11 |
|
12 |
|
@@ -20,6 +19,10 @@ Image
|
|
20 |
|
21 |
<img src="{resolve_assets("user.jpeg")}" />
|
22 |
|
|
|
|
|
|
|
|
|
23 |
Audio
|
24 |
|
25 |
<audio src="{resolve_assets("audio.wav")}"></audio>
|
@@ -29,7 +32,7 @@ Audio
|
|
29 |
],
|
30 |
]
|
31 |
|
32 |
-
with gr.Blocks() as demo
|
33 |
mgr.Chatbot(
|
34 |
value=conversation,
|
35 |
height=600,
|
|
|
1 |
import os
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import modelscope_studio as mgr
|
|
|
5 |
|
6 |
|
7 |
def resolve_assets(relative_path):
|
8 |
+
return os.path.join(os.path.dirname(__file__), "../resources",
|
9 |
relative_path)
|
10 |
|
11 |
|
|
|
19 |
|
20 |
<img src="{resolve_assets("user.jpeg")}" />
|
21 |
|
22 |
+
Video
|
23 |
+
|
24 |
+
<video src="{resolve_assets("dog.mp4")}"></video>
|
25 |
+
|
26 |
Audio
|
27 |
|
28 |
<audio src="{resolve_assets("audio.wav")}"></audio>
|
|
|
32 |
],
|
33 |
]
|
34 |
|
35 |
+
with gr.Blocks() as demo:
|
36 |
mgr.Chatbot(
|
37 |
value=conversation,
|
38 |
height=600,
|
components/{legacy/Chatbot → Chatbot}/demos/select-box.py
RENAMED
@@ -1,8 +1,7 @@
|
|
1 |
import json
|
2 |
|
3 |
import gradio as gr
|
4 |
-
import modelscope_studio
|
5 |
-
import modelscope_studio.components.legacy as mgr
|
6 |
|
7 |
# `label` will display on the page, and `value` is the actual selected value.
|
8 |
options = [{"label": "A", "value": "a"}, "b", "c"]
|
@@ -11,9 +10,9 @@ conversation = [[
|
|
11 |
None, f"""
|
12 |
Single Select: <select-box options='{json.dumps(options)}' select-once></select-box>
|
13 |
|
14 |
-
Multiple Select
|
15 |
|
16 |
-
Vertical Direction
|
17 |
|
18 |
<select-box direction="vertical" type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
|
19 |
|
@@ -35,7 +34,7 @@ def fn(data: gr.EventData):
|
|
35 |
print(data._data)
|
36 |
|
37 |
|
38 |
-
with gr.Blocks() as demo
|
39 |
chatbot = mgr.Chatbot(
|
40 |
value=conversation,
|
41 |
flushing=False,
|
|
|
1 |
import json
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import modelscope_studio as mgr
|
|
|
5 |
|
6 |
# `label` will display on the page, and `value` is the actual selected value.
|
7 |
options = [{"label": "A", "value": "a"}, "b", "c"]
|
|
|
10 |
None, f"""
|
11 |
Single Select: <select-box options='{json.dumps(options)}' select-once></select-box>
|
12 |
|
13 |
+
Multiple Select:<select-box type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
|
14 |
|
15 |
+
Vertical Direction:
|
16 |
|
17 |
<select-box direction="vertical" type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
|
18 |
|
|
|
34 |
print(data._data)
|
35 |
|
36 |
|
37 |
+
with gr.Blocks() as demo:
|
38 |
chatbot = mgr.Chatbot(
|
39 |
value=conversation,
|
40 |
flushing=False,
|
components/{legacy → Chatbot}/resources/audio.wav
RENAMED
File without changes
|
components/{legacy → Chatbot}/resources/bot.jpeg
RENAMED
File without changes
|
components/Chatbot/resources/custom_components/custom_select.js
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(props, cc, { el, onMount }) => {
|
2 |
+
const options = JSON.parse(props.options);
|
3 |
+
el.innerHTML = `
|
4 |
+
${options
|
5 |
+
.map((option) => {
|
6 |
+
return `<div>
|
7 |
+
<label>${option} <input type="radio"/></label>
|
8 |
+
<div>`;
|
9 |
+
})
|
10 |
+
.join('')}
|
11 |
+
`;
|
12 |
+
onMount(() => {
|
13 |
+
const inputs = Array.from(el.getElementsByTagName('input'));
|
14 |
+
Array.from(el.getElementsByTagName('label')).forEach((label, i) => {
|
15 |
+
label.addEventListener('click', () => {
|
16 |
+
inputs.forEach((input) => {
|
17 |
+
input.checked = false;
|
18 |
+
});
|
19 |
+
const input = label.getElementsByTagName('input')[0];
|
20 |
+
input.checked = true;
|
21 |
+
// Use cc.dispatch to trigger events.
|
22 |
+
cc.dispatch(options[i]);
|
23 |
+
});
|
24 |
+
});
|
25 |
+
});
|
26 |
+
};
|
components/Chatbot/resources/dog.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:39d086ce29e48cf76e5042d2f3f0611ee46575f70fa3dc0c40dd4cfffde3d933
|
3 |
+
size 8626383
|
components/{legacy → Chatbot}/resources/image-bot.jpeg
RENAMED
File without changes
|
components/{legacy → Chatbot}/resources/music-bot.jpeg
RENAMED
File without changes
|
components/{legacy → Chatbot}/resources/screen.jpeg
RENAMED
File without changes
|
components/{legacy → Chatbot}/resources/user.jpeg
RENAMED
File without changes
|
components/{legacy/Docs.py → Docs.py}
RENAMED
@@ -3,8 +3,7 @@ import re
|
|
3 |
from typing import Callable
|
4 |
|
5 |
import gradio as gr
|
6 |
-
import modelscope_studio
|
7 |
-
from helper.env import is_modelscope_studio
|
8 |
|
9 |
from .parse_markdown import parse_markdown
|
10 |
|
@@ -49,7 +48,7 @@ def get_demo_modules(file_path: str):
|
|
49 |
demos = [
|
50 |
demo for demo in list_demos(
|
51 |
os.path.join(os.path.dirname(file_path), "demos"))
|
52 |
-
if demo.endswith(".py")
|
53 |
]
|
54 |
demo_modules = {}
|
55 |
for demo in demos:
|
@@ -62,6 +61,9 @@ def get_demo_modules(file_path: str):
|
|
62 |
return demo_modules
|
63 |
|
64 |
|
|
|
|
|
|
|
65 |
class Docs:
|
66 |
|
67 |
def __init__(self, file_path: str, markdown_files: list = None):
|
@@ -90,41 +92,23 @@ class Docs:
|
|
90 |
"r") as f:
|
91 |
return f.read()
|
92 |
|
93 |
-
def render_demo(self,
|
94 |
-
demo_name,
|
95 |
-
code_position='left',
|
96 |
-
prefix='',
|
97 |
-
suffix=''):
|
98 |
content = self.read_file(f"./demos/{demo_name}.py")
|
99 |
module = self.demo_modules[demo_name]
|
100 |
with gr.Accordion("Show Demo", open=False):
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
104 |
````python
|
105 |
{content}
|
106 |
````
|
107 |
-
{suffix}
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
if code_position == 'top':
|
112 |
-
with gr.Row():
|
113 |
-
with gr.Column():
|
114 |
-
render_code()
|
115 |
-
with gr.Row():
|
116 |
-
if code_position == 'left':
|
117 |
-
with gr.Column():
|
118 |
-
render_code()
|
119 |
with gr.Column():
|
120 |
module.demo.render()
|
121 |
-
if code_position == 'right':
|
122 |
-
with gr.Column():
|
123 |
-
render_code()
|
124 |
-
if code_position == 'bottom':
|
125 |
-
with gr.Row():
|
126 |
-
with gr.Column():
|
127 |
-
render_code()
|
128 |
|
129 |
def render_markdown(self,
|
130 |
markdown_file,
|
@@ -136,21 +120,19 @@ class Docs:
|
|
136 |
if item["type"] == "text":
|
137 |
md = mgr.Markdown(item["value"],
|
138 |
header_links=True,
|
139 |
-
custom_components=custom_components
|
140 |
-
preview=False)
|
141 |
deps = [dep for dep in [components_tabs, self.tabs] if dep]
|
142 |
if len(deps) > 0:
|
143 |
md.custom(fn=on_tab_link_click, outputs=deps)
|
144 |
elif item["type"] == "demo":
|
145 |
self.render_demo(item["name"],
|
146 |
prefix=item["prefix"],
|
147 |
-
suffix=item["suffix"]
|
148 |
-
code_position=item["code_position"])
|
149 |
|
150 |
def render(self, components_tabs=None):
|
151 |
|
152 |
def tab_link_click(data: gr.EventData):
|
153 |
-
tab: str = data._data
|
154 |
component_tab: str = data._data["value"].get("component_tab", '')
|
155 |
if tab and tabs:
|
156 |
return {tabs: gr.update(selected=tab)}
|
|
|
3 |
from typing import Callable
|
4 |
|
5 |
import gradio as gr
|
6 |
+
import modelscope_studio as mgr
|
|
|
7 |
|
8 |
from .parse_markdown import parse_markdown
|
9 |
|
|
|
48 |
demos = [
|
49 |
demo for demo in list_demos(
|
50 |
os.path.join(os.path.dirname(file_path), "demos"))
|
51 |
+
if demo.endswith(".py")
|
52 |
]
|
53 |
demo_modules = {}
|
54 |
for demo in demos:
|
|
|
61 |
return demo_modules
|
62 |
|
63 |
|
64 |
+
is_modelscope_studio = os.getenv('MODELSCOPE_ENVIRONMENT') == 'studio'
|
65 |
+
|
66 |
+
|
67 |
class Docs:
|
68 |
|
69 |
def __init__(self, file_path: str, markdown_files: list = None):
|
|
|
92 |
"r") as f:
|
93 |
return f.read()
|
94 |
|
95 |
+
def render_demo(self, demo_name, prefix='', suffix=''):
|
|
|
|
|
|
|
|
|
96 |
content = self.read_file(f"./demos/{demo_name}.py")
|
97 |
module = self.demo_modules[demo_name]
|
98 |
with gr.Accordion("Show Demo", open=False):
|
99 |
+
with gr.Row():
|
100 |
+
with gr.Column():
|
101 |
+
mgr.Markdown(f"""
|
102 |
+
{prefix}
|
103 |
````python
|
104 |
{content}
|
105 |
````
|
106 |
+
{suffix}
|
107 |
+
""",
|
108 |
+
header_links=True,
|
109 |
+
custom_components=custom_components)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
with gr.Column():
|
111 |
module.demo.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
def render_markdown(self,
|
114 |
markdown_file,
|
|
|
120 |
if item["type"] == "text":
|
121 |
md = mgr.Markdown(item["value"],
|
122 |
header_links=True,
|
123 |
+
custom_components=custom_components)
|
|
|
124 |
deps = [dep for dep in [components_tabs, self.tabs] if dep]
|
125 |
if len(deps) > 0:
|
126 |
md.custom(fn=on_tab_link_click, outputs=deps)
|
127 |
elif item["type"] == "demo":
|
128 |
self.render_demo(item["name"],
|
129 |
prefix=item["prefix"],
|
130 |
+
suffix=item["suffix"])
|
|
|
131 |
|
132 |
def render(self, components_tabs=None):
|
133 |
|
134 |
def tab_link_click(data: gr.EventData):
|
135 |
+
tab: str = data._data["value"].get("tab", '')
|
136 |
component_tab: str = data._data["value"].get("component_tab", '')
|
137 |
if tab and tabs:
|
138 |
return {tabs: gr.update(selected=tab)}
|
components/{legacy/Markdown → Markdown}/README-zh_CN.md
RENAMED
@@ -2,9 +2,8 @@
|
|
2 |
|
3 |
升级版的 gradio Markdown。
|
4 |
|
5 |
-
-
|
6 |
-
-
|
7 |
-
- 支持自定义渲染组件,并与 Python 事件交互
|
8 |
|
9 |
## 如何使用
|
10 |
|
@@ -28,12 +27,6 @@
|
|
28 |
|
29 |
<demo name="select-box"></demo>
|
30 |
|
31 |
-
### 支持图表展示
|
32 |
-
|
33 |
-
在返回的内容中加入 `chart` 标签,更多用法详见 <tab-link tab="custom_tags/chart">chart</tab-link>
|
34 |
-
|
35 |
-
<demo name="chart"></demo>
|
36 |
-
|
37 |
### 自定义标签(高阶用法,需要了解前端知识)
|
38 |
|
39 |
<demo name="custom-tag"></demo>
|
@@ -49,13 +42,13 @@ template只能做简单的变量替换,如果想要引入更多自定义的行
|
|
49 |
custom_select.js
|
50 |
|
51 |
```js
|
52 |
-
<file src="
|
53 |
```
|
54 |
|
55 |
</demo-suffix>
|
56 |
</demo>
|
57 |
|
58 |
-
#### 与 Python
|
59 |
|
60 |
在 js 中可以使用`cc.dispatch`触发 Python 侧监听的`custom`事件,以前面的custom_select.js为例,我们在前端调用了`cc.dispatch(options[i])`,则会向 Python 侧同时发送通知。
|
61 |
|
@@ -67,15 +60,13 @@ custom_select.js
|
|
67 |
|
68 |
### props
|
69 |
|
70 |
-
| 属性
|
71 |
-
|
|
72 |
-
| enable_base64
|
73 |
-
|
|
74 |
-
|
|
75 |
-
| preview | bool | True | 是否开启图片预览功能 |
|
76 |
-
| custom_components | dict\[str, CustomComponentDict\] CustomComponentDict 定义见下方 | None | 支持用户定义自定义标签,并通过 js 控制标签渲染样式与触发 python 事件。 |
|
77 |
|
78 |
-
**
|
79 |
|
80 |
```python
|
81 |
class CustomComponentDict(TypedDict):
|
@@ -88,10 +79,9 @@ class CustomComponentDict(TypedDict):
|
|
88 |
|
89 |
- <tab-link tab="custom_tags/select-box">select-box</tab-link>
|
90 |
- <tab-link tab="custom_tags/accordion">accordion</tab-link>
|
91 |
-
- <tab-link tab="custom_tags/chart">chart</tab-link>
|
92 |
|
93 |
### event listeners
|
94 |
|
95 |
-
| 事件 | 描述
|
96 |
-
| ------------------------------ |
|
97 |
-
| `mgr.Markdown.custom(fn, ···)` | 自定义标签触发事件时触发,EventData 为:<br/> - tag_index:当前触发标签的 index
|
|
|
2 |
|
3 |
升级版的 gradio Markdown。
|
4 |
|
5 |
+
- 支持输出多模态内容(音频、视频、语音、文件、文本)
|
6 |
+
- 支持自定义渲染组件,并与 Python 侧事件交互
|
|
|
7 |
|
8 |
## 如何使用
|
9 |
|
|
|
27 |
|
28 |
<demo name="select-box"></demo>
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
### 自定义标签(高阶用法,需要了解前端知识)
|
31 |
|
32 |
<demo name="custom-tag"></demo>
|
|
|
42 |
custom_select.js
|
43 |
|
44 |
```js
|
45 |
+
<file src="./resources/custom_components/custom_select.js"></file>
|
46 |
```
|
47 |
|
48 |
</demo-suffix>
|
49 |
</demo>
|
50 |
|
51 |
+
#### 与 Python 侧交互
|
52 |
|
53 |
在 js 中可以使用`cc.dispatch`触发 Python 侧监听的`custom`事件,以前面的custom_select.js为例,我们在前端调用了`cc.dispatch(options[i])`,则会向 Python 侧同时发送通知。
|
54 |
|
|
|
60 |
|
61 |
### props
|
62 |
|
63 |
+
| 属性 | 类型 | 默认值 | 描述 |
|
64 |
+
| ----------------- | --------------------------------------------------------------- | ------ | --------------------------------------------------------------------------- |
|
65 |
+
| enable_base64 | bool | False | 是否支持渲染的内容为 base64,因为直接渲染 base64 有安全问题,默认为 False。 |
|
66 |
+
| preview | bool | True | 是否开启图片预览功能 |
|
67 |
+
| custom_components | dict\[str, CustomComponentDict\] CustomComponentDict 定义见下方 | None | 支持用户定义自定义标签,并通过 js 控制标签渲染样式与触发 python 事件。 |
|
|
|
|
|
68 |
|
69 |
+
**CustomComponent 定义如下**
|
70 |
|
71 |
```python
|
72 |
class CustomComponentDict(TypedDict):
|
|
|
79 |
|
80 |
- <tab-link tab="custom_tags/select-box">select-box</tab-link>
|
81 |
- <tab-link tab="custom_tags/accordion">accordion</tab-link>
|
|
|
82 |
|
83 |
### event listeners
|
84 |
|
85 |
+
| 事件 | 描述 |
|
86 |
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
87 |
+
| `mgr.Markdown.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 在 mesage 的 index tuple 基础上重新计算。<br/> - value:自定义传入的值。 |
|
components/{legacy/Markdown → Markdown}/README.md
RENAMED
@@ -2,9 +2,8 @@
|
|
2 |
|
3 |
Upgraded gradio Markdown.
|
4 |
|
5 |
-
- Supports output of multimodal content (audio, video,
|
6 |
-
-
|
7 |
-
- Supports custom rendering components and interaction with Python events
|
8 |
|
9 |
## How to Use
|
10 |
|
@@ -18,24 +17,19 @@ Upgraded gradio Markdown.
|
|
18 |
|
19 |
### Support for Accordion Content Display
|
20 |
|
21 |
-
Include the `accordion` tag in the returned content
|
22 |
<demo name="accordion"></demo>
|
23 |
|
24 |
### Support for User Selection Interaction
|
25 |
|
26 |
-
Include the `select-box` tag in the returned content
|
27 |
<demo name="select-box"></demo>
|
28 |
|
29 |
-
### Support for Chart Display
|
30 |
-
|
31 |
-
Include the `chart` tag in the returned content. For more usage details, see <tab-link tab="custom_tags/chart">chart</tab-link>
|
32 |
-
<demo name="chart"></demo>
|
33 |
-
|
34 |
### Custom Tags (Advanced Usage, Requires Frontend Knowledge)
|
35 |
|
36 |
<demo name="custom-tag"></demo>
|
37 |
|
38 |
-
####
|
39 |
|
40 |
<demo name="custom-tag2"></demo>
|
41 |
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:
|
@@ -44,13 +38,13 @@ The template can only perform simple variable replacements. If you want to intro
|
|
44 |
custom_select.js
|
45 |
|
46 |
```js
|
47 |
-
<file src="
|
48 |
```
|
49 |
|
50 |
</demo-suffix>
|
51 |
</demo>
|
52 |
|
53 |
-
#### Interaction with Python
|
54 |
|
55 |
In js, you can use `cc.dispatch` to trigger the `custom` event listened to on the Python side. Taking the previous custom_select.js as an example, when we call `cc.dispatch(options[i])` on the frontend, a notification will be sent to the Python side simultaneously.
|
56 |
<demo name="custom-tag4"></demo>
|
@@ -61,14 +55,12 @@ The following APIs are additional extended parameters beyond the original gradio
|
|
61 |
|
62 |
### props
|
63 |
|
64 |
-
| Attribute
|
65 |
-
|
|
66 |
-
| enable_base64
|
67 |
-
| preview
|
68 |
-
|
|
69 |
-
|
|
70 |
-
| custom_components | Dict[str, CustomComponentDict] CustomComponentDict definition below | None | Supports user-defined custom tags and controls tag rendering styles and triggers Python events through js. |
|
71 |
-
| |
|
72 |
|
73 |
**CustomComponent definition is as follows:**
|
74 |
|
@@ -83,10 +75,9 @@ class CustomComponentDict(TypedDict):
|
|
83 |
|
84 |
- <tab-link tab="custom_tags/select-box">select-box</tab-link>
|
85 |
- <tab-link tab="custom_tags/accordion">accordion</tab-link>
|
86 |
-
- <tab-link tab="custom_tags/chart">chart</tab-link>
|
87 |
|
88 |
### Event Listeners
|
89 |
|
90 |
-
| Event | Description
|
91 |
-
| ------------------------------ |
|
92 |
-
| `mgr.Markdown.custom(fn, ···)` | Triggered when a custom tag event occurs. EventData is: <br/> - tag: The current tag that triggered the event.<br/> - tag_index: The index of the current triggered tag.<br/> - value: The custom value passed in. |
|
|
|
2 |
|
3 |
Upgraded gradio Markdown.
|
4 |
|
5 |
+
- Supports output of multimodal content (audio, video, voice, files, text)
|
6 |
+
- Supports custom rendering components and interaction with Python-side events
|
|
|
7 |
|
8 |
## How to Use
|
9 |
|
|
|
17 |
|
18 |
### Support for Accordion Content Display
|
19 |
|
20 |
+
Include the `accordion` tag in the returned content for more usage details, see <tab-link tab="custom_tags/accordion">accordion</tab-link>
|
21 |
<demo name="accordion"></demo>
|
22 |
|
23 |
### Support for User Selection Interaction
|
24 |
|
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:
|
|
|
38 |
custom_select.js
|
39 |
|
40 |
```js
|
41 |
+
<file src="./resources/custom_components/custom_select.js"></file>
|
42 |
```
|
43 |
|
44 |
</demo-suffix>
|
45 |
</demo>
|
46 |
|
47 |
+
#### Interaction with Python Side
|
48 |
|
49 |
In js, you can use `cc.dispatch` to trigger the `custom` event listened to on the Python side. Taking the previous custom_select.js as an example, when we call `cc.dispatch(options[i])` on the frontend, a notification will be sent to the Python side simultaneously.
|
50 |
<demo name="custom-tag4"></demo>
|
|
|
55 |
|
56 |
### props
|
57 |
|
58 |
+
| Attribute | Type | Default Value | Description |
|
59 |
+
| ----------------- | ------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
60 |
+
| enable_base64 | bool | False | Whether to support rendering content as base64, since rendering base64 directly can pose security issues, the default is False. |
|
61 |
+
| preview | bool | True | Whether to enable image preview functionality. |
|
62 |
+
| custom_components | dict[str, CustomComponentDict] CustomComponentDict definition below | None | Supports user-defined custom tags and controls tag rendering styles and triggers Python events through js. |
|
63 |
+
| |
|
|
|
|
|
64 |
|
65 |
**CustomComponent definition is as follows:**
|
66 |
|
|
|
75 |
|
76 |
- <tab-link tab="custom_tags/select-box">select-box</tab-link>
|
77 |
- <tab-link tab="custom_tags/accordion">accordion</tab-link>
|
|
|
78 |
|
79 |
### Event Listeners
|
80 |
|
81 |
+
| Event | Description |
|
82 |
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
83 |
+
| `mgr.Markdown.custom(fn, ···)` | Triggered when a custom tag event occurs. EventData is: <br/> - index: The index tuple of the current message ([message index, user group(index 0) or bot group(index 1), user/bot group index]).<br/> - tag: The current tag that triggered the event.<br/> - tag_index: The index of the current triggered tag, re-calculated based on the message’s index tuple.<br/> - value: The custom value passed in. |
|
components/{legacy/Markdown → Markdown}/app.py
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
import os
|
2 |
|
3 |
-
from components.
|
4 |
|
5 |
|
6 |
def resolve(relative_path: str):
|
|
|
1 |
import os
|
2 |
|
3 |
+
from components.Docs import Docs
|
4 |
|
5 |
|
6 |
def resolve(relative_path: str):
|
components/{legacy/Markdown → Markdown}/custom_tags/accordion-zh_CN.md
RENAMED
File without changes
|
components/{legacy/Markdown → Markdown}/custom_tags/accordion.md
RENAMED
File without changes
|
components/{legacy/Markdown → Markdown}/custom_tags/select-box-zh_CN.md
RENAMED
File without changes
|
components/{legacy/Markdown → Markdown}/custom_tags/select-box.md
RENAMED
File without changes
|
components/{legacy/Markdown → Markdown}/demos/accordion.py
RENAMED
@@ -1,25 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import modelscope_studio
|
3 |
-
import modelscope_studio.components.legacy as mgr
|
4 |
|
5 |
-
with gr.Blocks() as demo
|
6 |
-
mgr.Markdown("""
|
7 |
<accordion title="Using tool">
|
8 |
|
9 |
```json
|
10 |
-
{"text": "glorious weather", "resolution": "1024*1024"}
|
11 |
```
|
12 |
|
13 |
</accordion>
|
14 |
|
15 |
-
Use `::accordion-title` to support markdown
|
16 |
|
17 |
<accordion>
|
18 |
|
19 |
::accordion-title[Using `tool`]
|
20 |
|
21 |
```json
|
22 |
-
{"text": "glorious weather", "resolution": "1024*1024"}
|
23 |
```
|
24 |
</accordion>
|
25 |
""")
|
|
|
1 |
import gradio as gr
|
2 |
+
import modelscope_studio as mgr
|
|
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
mgr.Markdown(f"""
|
6 |
<accordion title="Using tool">
|
7 |
|
8 |
```json
|
9 |
+
{{"text": "glorious weather", "resolution": "1024*1024"}}
|
10 |
```
|
11 |
|
12 |
</accordion>
|
13 |
|
14 |
+
Use `::accordion-title` to support markdown:
|
15 |
|
16 |
<accordion>
|
17 |
|
18 |
::accordion-title[Using `tool`]
|
19 |
|
20 |
```json
|
21 |
+
{{"text": "glorious weather", "resolution": "1024*1024"}}
|
22 |
```
|
23 |
</accordion>
|
24 |
""")
|
components/{legacy/Markdown → Markdown}/demos/basic.py
RENAMED
@@ -1,8 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
import modelscope_studio
|
3 |
-
import modelscope_studio.components.legacy as mgr
|
4 |
|
5 |
-
with gr.Blocks() as demo
|
6 |
mgr.Markdown(
|
7 |
"This _example_ was **written** in [Markdown](https://en.wikipedia.org/wiki/Markdown)\n"
|
8 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
import modelscope_studio as mgr
|
|
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
5 |
mgr.Markdown(
|
6 |
"This _example_ was **written** in [Markdown](https://en.wikipedia.org/wiki/Markdown)\n"
|
7 |
)
|
components/{legacy/Markdown → Markdown}/demos/custom-tag.py
RENAMED
@@ -1,10 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
import modelscope_studio
|
3 |
-
import modelscope_studio.components.legacy as mgr
|
4 |
|
5 |
-
with gr.Blocks() as demo
|
6 |
mgr.Markdown(
|
7 |
-
"""
|
8 |
custom tag:<custom-tag value="aaa"></custom-tag>
|
9 |
""",
|
10 |
custom_components={
|
@@ -12,7 +11,7 @@ custom tag:<custom-tag value="aaa"></custom-tag>
|
|
12 |
"custom-tag": {
|
13 |
# The tag props.
|
14 |
"props": ["value"],
|
15 |
-
# The tag template, use `{prop}` as placeholder
|
16 |
"template": "<div>{value}</div>"
|
17 |
}
|
18 |
})
|
|
|
1 |
import gradio as gr
|
2 |
+
import modelscope_studio as mgr
|
|
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
5 |
mgr.Markdown(
|
6 |
+
f"""
|
7 |
custom tag:<custom-tag value="aaa"></custom-tag>
|
8 |
""",
|
9 |
custom_components={
|
|
|
11 |
"custom-tag": {
|
12 |
# The tag props.
|
13 |
"props": ["value"],
|
14 |
+
# The tag template, use `{prop}` as placeholder。
|
15 |
"template": "<div>{value}</div>"
|
16 |
}
|
17 |
})
|
components/{legacy/Markdown → Markdown}/demos/custom-tag2.py
RENAMED
@@ -1,10 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
import modelscope_studio
|
3 |
-
import modelscope_studio.components.legacy as mgr
|
4 |
|
5 |
-
with gr.Blocks() as demo
|
6 |
mgr.Markdown(
|
7 |
-
"""
|
8 |
custom tag:<custom-tag value="aaa"></custom-tag>
|
9 |
""",
|
10 |
custom_components={
|
@@ -15,29 +14,12 @@ custom tag:<custom-tag value="aaa"></custom-tag>
|
|
15 |
# The `js` property should be a string containing a JavaScript Function.
|
16 |
"js":
|
17 |
"""
|
18 |
-
(props, cc, { el, onMount
|
19 |
-
// `onMount` will be called after the template
|
20 |
onMount(() => {
|
21 |
// `el` is the container element
|
22 |
console.log(el)
|
23 |
-
|
24 |
-
// the return function will be called when the component is being unmounted
|
25 |
-
return () => {
|
26 |
-
console.log('unmount')
|
27 |
-
}
|
28 |
-
})
|
29 |
-
|
30 |
-
// `onUpdate` will be called when the props changed
|
31 |
-
onUpdate(() => {
|
32 |
-
console.log(props)
|
33 |
})
|
34 |
-
onUpdate(
|
35 |
-
() => {
|
36 |
-
console.log(props, 'after mount')
|
37 |
-
},
|
38 |
-
// By default, the callback will not be called when the component is being mounted. Set `callAfterMount` to true to enable it.
|
39 |
-
{ callAfterMount: true }
|
40 |
-
)
|
41 |
console.log(props.children) // By default, `props` will be passed a property named `children`, which can get the content in the tag, such as 'xx' in '<tag>xx</tag>'.
|
42 |
|
43 |
// The return value will be merged with `props` and passed to the template.
|
|
|
1 |
import gradio as gr
|
2 |
+
import modelscope_studio as mgr
|
|
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
5 |
mgr.Markdown(
|
6 |
+
f"""
|
7 |
custom tag:<custom-tag value="aaa"></custom-tag>
|
8 |
""",
|
9 |
custom_components={
|
|
|
14 |
# The `js` property should be a string containing a JavaScript Function.
|
15 |
"js":
|
16 |
"""
|
17 |
+
(props, cc, { el, onMount }) => {
|
18 |
+
// `onMount` will be called after the template rendered
|
19 |
onMount(() => {
|
20 |
// `el` is the container element
|
21 |
console.log(el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
console.log(props.children) // By default, `props` will be passed a property named `children`, which can get the content in the tag, such as 'xx' in '<tag>xx</tag>'.
|
24 |
|
25 |
// The return value will be merged with `props` and passed to the template.
|
components/{legacy/Markdown → Markdown}/demos/custom-tag3.py
RENAMED
@@ -2,21 +2,20 @@ import json
|
|
2 |
import os
|
3 |
|
4 |
import gradio as gr
|
5 |
-
import modelscope_studio
|
6 |
-
import modelscope_studio.components.legacy as mgr
|
7 |
|
8 |
options = ["a", "b", "c"]
|
9 |
|
10 |
|
11 |
def resolve_assets(relative_path):
|
12 |
-
return os.path.join(os.path.dirname(__file__), "
|
13 |
relative_path)
|
14 |
|
15 |
|
16 |
with open(resolve_assets("./custom_components/custom_select.js"), 'r') as f:
|
17 |
custom_select_js = f.read()
|
18 |
|
19 |
-
with gr.Blocks() as demo
|
20 |
mgr.Markdown(value=f"""
|
21 |
custom tag: <custom-select options='{json.dumps(options)}'></custom-select>
|
22 |
""",
|
|
|
2 |
import os
|
3 |
|
4 |
import gradio as gr
|
5 |
+
import modelscope_studio as mgr
|
|
|
6 |
|
7 |
options = ["a", "b", "c"]
|
8 |
|
9 |
|
10 |
def resolve_assets(relative_path):
|
11 |
+
return os.path.join(os.path.dirname(__file__), "../resources",
|
12 |
relative_path)
|
13 |
|
14 |
|
15 |
with open(resolve_assets("./custom_components/custom_select.js"), 'r') as f:
|
16 |
custom_select_js = f.read()
|
17 |
|
18 |
+
with gr.Blocks() as demo:
|
19 |
mgr.Markdown(value=f"""
|
20 |
custom tag: <custom-select options='{json.dumps(options)}'></custom-select>
|
21 |
""",
|
components/{legacy/Markdown → Markdown}/demos/custom-tag4.py
RENAMED
@@ -2,14 +2,13 @@ import json
|
|
2 |
import os
|
3 |
|
4 |
import gradio as gr
|
5 |
-
import modelscope_studio
|
6 |
-
import modelscope_studio.components.legacy as mgr
|
7 |
|
8 |
options = ["a", "b", "c"]
|
9 |
|
10 |
|
11 |
def resolve_assets(relative_path):
|
12 |
-
return os.path.join(os.path.dirname(__file__), "
|
13 |
relative_path)
|
14 |
|
15 |
|
@@ -22,7 +21,7 @@ def fn(data: gr.EventData):
|
|
22 |
print("custom value", data._data)
|
23 |
|
24 |
|
25 |
-
with gr.Blocks() as demo
|
26 |
md = mgr.Markdown(value=f"""
|
27 |
custom tag: <custom-select options='{json.dumps(options)}'></custom-select>
|
28 |
""",
|
|
|
2 |
import os
|
3 |
|
4 |
import gradio as gr
|
5 |
+
import modelscope_studio as mgr
|
|
|
6 |
|
7 |
options = ["a", "b", "c"]
|
8 |
|
9 |
|
10 |
def resolve_assets(relative_path):
|
11 |
+
return os.path.join(os.path.dirname(__file__), "../resources",
|
12 |
relative_path)
|
13 |
|
14 |
|
|
|
21 |
print("custom value", data._data)
|
22 |
|
23 |
|
24 |
+
with gr.Blocks() as demo:
|
25 |
md = mgr.Markdown(value=f"""
|
26 |
custom tag: <custom-select options='{json.dumps(options)}'></custom-select>
|
27 |
""",
|
components/Markdown/demos/custom_tags/accordion/__pycache__/accordion-title.cpython-39.pyc
ADDED
Binary file (549 Bytes). View file
|
|
components/Markdown/demos/custom_tags/accordion/__pycache__/basic.cpython-39.pyc
ADDED
Binary file (525 Bytes). View file
|
|
components/{legacy/Markdown → Markdown}/demos/custom_tags/accordion/accordion-title.py
RENAMED
@@ -1,15 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
import modelscope_studio
|
3 |
-
import modelscope_studio.components.legacy as mgr
|
4 |
|
5 |
-
with gr.Blocks() as demo
|
6 |
-
mgr.Markdown("""
|
7 |
<accordion>
|
8 |
|
9 |
::accordion-title[Using `tool`]
|
10 |
|
11 |
```json
|
12 |
-
{"text": "glorious weather", "resolution": "1024*1024"}
|
13 |
```
|
14 |
|
15 |
</accordion>
|
|
|
1 |
import gradio as gr
|
2 |
+
import modelscope_studio as mgr
|
|
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
mgr.Markdown(f"""
|
6 |
<accordion>
|
7 |
|
8 |
::accordion-title[Using `tool`]
|
9 |
|
10 |
```json
|
11 |
+
{{"text": "glorious weather", "resolution": "1024*1024"}}
|
12 |
```
|
13 |
|
14 |
</accordion>
|
components/{legacy/Markdown → Markdown}/demos/custom_tags/accordion/basic.py
RENAMED
@@ -1,13 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
import modelscope_studio
|
3 |
-
import modelscope_studio.components.legacy as mgr
|
4 |
|
5 |
-
with gr.Blocks() as demo
|
6 |
-
mgr.Markdown("""
|
7 |
<accordion title="Using tool">
|
8 |
|
9 |
```json
|
10 |
-
{"text": "glorious weather", "resolution": "1024*1024"}
|
11 |
```
|
12 |
|
13 |
</accordion>
|
|
|
1 |
import gradio as gr
|
2 |
+
import modelscope_studio as mgr
|
|
|
3 |
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
mgr.Markdown(f"""
|
6 |
<accordion title="Using tool">
|
7 |
|
8 |
```json
|
9 |
+
{{"text": "glorious weather", "resolution": "1024*1024"}}
|
10 |
```
|
11 |
|
12 |
</accordion>
|
components/Markdown/demos/custom_tags/select-box/__pycache__/basic.cpython-39.pyc
ADDED
Binary file (851 Bytes). View file
|
|
components/Markdown/demos/custom_tags/select-box/__pycache__/card_shape.cpython-39.pyc
ADDED
Binary file (980 Bytes). View file
|
|
components/Markdown/demos/custom_tags/select-box/__pycache__/card_shape_width_auto.cpython-39.pyc
ADDED
Binary file (751 Bytes). View file
|
|
components/Markdown/demos/custom_tags/select-box/__pycache__/python_events.cpython-39.pyc
ADDED
Binary file (804 Bytes). View file
|
|
components/{legacy/Markdown → Markdown}/demos/custom_tags/select-box/basic.py
RENAMED
@@ -1,18 +1,17 @@
|
|
1 |
import json
|
2 |
|
3 |
import gradio as gr
|
4 |
-
import modelscope_studio
|
5 |
-
import modelscope_studio.components.legacy as mgr
|
6 |
|
7 |
options = [{"label": "A", "value": "a"}, "b", "c"]
|
8 |
|
9 |
-
with gr.Blocks() as demo
|
10 |
mgr.Markdown(
|
11 |
f"""Single Select: <select-box options='{json.dumps(options)}' select-once></select-box>
|
12 |
|
13 |
-
Multiple Select
|
14 |
|
15 |
-
Vertical Direction
|
16 |
|
17 |
<select-box direction="vertical" type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
|
18 |
""", )
|
|
|
1 |
import json
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import modelscope_studio as mgr
|
|
|
5 |
|
6 |
options = [{"label": "A", "value": "a"}, "b", "c"]
|
7 |
|
8 |
+
with gr.Blocks() as demo:
|
9 |
mgr.Markdown(
|
10 |
f"""Single Select: <select-box options='{json.dumps(options)}' select-once></select-box>
|
11 |
|
12 |
+
Multiple Select:<select-box type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
|
13 |
|
14 |
+
Vertical Direction:
|
15 |
|
16 |
<select-box direction="vertical" type="checkbox" options='{json.dumps(options)}' select-once submit-text="Submit"></select-box>
|
17 |
""", )
|