Skip to content

Commit 287c2ca

Browse files
committed
docs: add faq docs
1 parent 070ac18 commit 287c2ca

10 files changed

Lines changed: 85 additions & 4 deletions

File tree

.changeset/tender-maps-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'modelscope_studio': patch
3+
---
4+
5+
docs: add FAQ docs

README-zh_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
然而,当您的应用需要 Gradio 在 Python 端更多地处理内置数据时,`modelscope_studio`的组件可能不是最好的选择,但是不用担心,它可以很好地与已有的 Gradio 组件相结合,您仍然可以使用`modelscope_studio`来优化您的应用。
3131

32+
> 如果您正在 Hugging Face Space 中使用`modelscope_studio`,请在`demo.launch()`中添加`ssr_mode=False`参数:`demo.launch(ssr_mode=False)`,否则页面可能无法正常显示。
33+
3234
## 依赖
3335

3436
- Gradio >= 4.43.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Compared to the original components of Gradio, `modelscope_studio` focuses more
2929

3030
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.
3131

32+
> If you are using `modelscope_studio` in Hugging Face Space, please add the `ssr_mode=False` parameter to the `demo.launch()`: `demo.launch(ssr_mode=False)`, otherwise the page may not display properly.
33+
3234
## Dependencies
3335

3436
- Gradio >= 4.43.0

docs/FAQ-zh_CN.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# FAQ
2+
3+
## 为什么我的应用在本地可以正常运行,在 Hugging Face Space 中界面无法正常显示?
4+
5+
在 Hugging Face Space 中,默认开启了 Gradio 的 ssr 模式,但是此功能目前还无法很好的兼容自定义组件,需要我们手动关闭。请在`demo.launch()`方法中添加`ssr_mode=False`参数:`demo.launch(ssr_mode=False)`
6+
7+
## 为什么我的应用每次操作都需要等待一小段时间才会有响应
8+
9+
`modelscope_studio`将组件的加载反馈进行了单独抽离。由于 Gradio 的交互操作涉及到前后端通信,需要有一段加载中的等待时间,当没有`AutoLoading`组件时,页面将不会显示 Gradio 的加载状态。因此,建议您至少在全局使用一次`AutoLoading`组件,以显示兜底的加载反馈。
10+
11+
```python
12+
import gradio as gr
13+
import modelscope_studio.components.antd as antd
14+
import modelscope_studio.components.base as ms
15+
16+
with gr.Blocks() as demo:
17+
with ms.Application(), antd.ConfigProvider(), ms.AutoLoading():
18+
antd.Button()
19+
```

docs/FAQ.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# FAQ
2+
3+
## Why does my application run normally locally but the interface doesn't display properly in Hugging Face Space?
4+
5+
In Hugging Face Space, Gradio's SSR mode is enabled by default, but this feature currently doesn't work well with custom components and needs to be manually disabled. Please add the `ssr_mode=False` parameter to the `demo.launch()`: `demo.launch(ssr_mode=False)`.
6+
7+
## Why does my application need to wait for a short time before responding to each operation?
8+
9+
`modelscope_studio` has separately extracted the loading feedback for components. Since Gradio's interactive operations involve frontend-backend communication, there needs to be a loading wait time. When there is no `AutoLoading` component, the page will not display Gradio's loading status. Therefore, it is recommended that you use the `AutoLoading` component at least once globally to display fallback loading feedback.
10+
11+
```python
12+
import gradio as gr
13+
import modelscope_studio.components.antd as antd
14+
import modelscope_studio.components.base as ms
15+
16+
with gr.Blocks() as demo:
17+
with ms.Application(), antd.ConfigProvider(), ms.AutoLoading():
18+
antd.Button()
19+
```

docs/README-zh_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
然而,当您的应用需要 Gradio 在 Python 端更多地处理内置数据时,`modelscope_studio`的组件可能不是最好的选择,但是不用担心,它可以很好地与已有的 Gradio 组件相结合,您仍然可以使用`modelscope_studio`来优化您的应用。
2525

26+
> 如果您正在 Hugging Face Space 中使用`modelscope_studio`,请在`demo.launch()`方法中添加`ssr_mode=False`参数:`demo.launch(ssr_mode=False)`,否则页面可能无法正常显示。
27+
2628
## 依赖
2729

2830
- Gradio >= 4.43.0

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Compared to the original components of Gradio, `modelscope_studio` focuses more
4040

4141
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.
4242

43+
> If you are using `modelscope_studio` in Hugging Face Space, please add the `ssr_mode=False` parameter to the `demo.launch()`: `demo.launch(ssr_mode=False)`, otherwise the page may not display properly.
44+
4345
## Dependencies
4446

4547
- Gradio >= 4.43.0

docs/app.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,26 @@ def get_layout_templates():
6262

6363
layout_templates = get_layout_templates()
6464

65-
index_docs = {"overview": Docs(__file__), **layout_templates}
65+
misc_docs = Docs(__file__)
66+
67+
68+
class IndexDocsItem:
69+
70+
def __init__(self, module_name):
71+
self.module_name = module_name
72+
73+
def get_css(self):
74+
return misc_docs.get_css()
75+
76+
def render(self):
77+
return misc_docs.render(module_name=self.module_name)
78+
79+
80+
index_docs = {
81+
"overview": IndexDocsItem("README"),
82+
"faq": IndexDocsItem("FAQ"),
83+
**layout_templates
84+
}
6685

6786
base_docs = get_docs("base")
6887
antd_docs = get_docs("antd")
@@ -73,6 +92,9 @@ def get_layout_templates():
7392
index_menu_items = [{
7493
"label": get_text("ModelScope-Studio", "ModelScope-Studio"),
7594
"key": "overview"
95+
}, {
96+
"label": get_text("FAQ", "FAQ"),
97+
"key": "faq"
7698
}, {
7799
"label":
78100
get_text("Layout Templates", "布局模板"),

docs/demos/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
antd.DatePicker()
88

99
if __name__ == "__main__":
10-
demo.queue().launch()
10+
demo.queue().launch(ssr_mode=False)

docs/helper/Docs.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def __init__(self, file_path: str):
3030
filter(lambda x: not x.endswith("-zh_CN.md"),
3131
self.markdown_files))
3232

33+
def _get_filename(self, filename: str):
34+
if is_modelscope_studio:
35+
return f"{filename}-zh_CN.md"
36+
return f"{filename}.md"
37+
3338
def _remove_formatter(self, markdown_text):
3439
pattern = r"^ *---[\s\S]*?---"
3540
replaced_text = re.sub(pattern, "", markdown_text)
@@ -163,7 +168,10 @@ def get_css(self):
163168
css += module.css
164169
return css
165170

166-
def render(self):
171+
def render(self, module_name: str = None):
172+
parsed_filename = self._get_filename(
173+
module_name) if module_name else None
167174
with gr.Blocks() as demo:
168-
self._render_markdown(self.markdown_files[0])
175+
self._render_markdown(
176+
parsed_filename if parsed_filename else self.markdown_files[0])
169177
return demo

0 commit comments

Comments
 (0)