- 组件
- 侧边栏
侧边栏
gradio.Sidebar(···)描述
Sidebar 是一个可折叠面板,用于在 Blocks 布局中将子组件渲染在屏幕左侧。
示例用法
with gr.Blocks() as demo:
with gr.Sidebar():
gr.Textbox()
gr.Button()初始化
elem_classes: list[str] | str | None
elem_classes: list[str] | str | None= None一个可选字符串或字符串列表,分配为该组件在 HTML DOM 中的 class。可用于定位 CSS 样式。
position: Literal['left', 'right']
position: Literal['left', 'right']= "left"侧边栏在布局中的位置,可以是 "left"(左侧)或 "right"(右侧)。默认为 "left"。
方法
gradio.Sidebar.expand(···)描述 %20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
当侧边栏展开时触发此监听器。
fn: Callable | None | Literal['decorator']
fn: Callable | None | Literal['decorator']= "decorator"当此事件触发时调用的函数。通常是机器学习模型的预测函数。函数的每个参数对应一个输入组件,函数应返回一个单一值或一个值元组,元组中的每个元素对应一个输出组件。
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None= None用作输入的 gradio.components 列表。如果函数不接受输入,则此列表应为空。
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None= None用作输出的 gradio.components 列表。如果函数不返回输出,则此列表应为空。
api_name: str | None
api_name: str | None= None定义该端点在 API 文档中如何显示。可以是字符串或 None。如果设置为字符串,则该端点将在 API 文档中以给定名称显示。如果为 None(默认),则使用函数的名称作为 API 端点。
api_description: str | None | Literal[False]
api_description: str | None | Literal[False]= NoneAPI 端点的描述。可以是字符串、None 或 False。如果设置为字符串,则该端点将在 API 文档中以给定描述显示。如果为 None,则使用函数的 docstring 作为 API 端点描述。如果为 False,则 API 文档中不会显示任何描述。
show_progress: Literal['full', 'minimal', 'hidden']
show_progress: Literal['full', 'minimal', 'hidden']= "full"事件运行时如何显示进度动画:“full”显示一个覆盖输出组件区域的加载指示器,并在右上角显示运行时信息,“minimal”仅显示运行时信息,“hidden”不显示任何进度动画。
show_progress_on: Component | list[Component] | None
show_progress_on: Component | list[Component] | None= None用于显示进度动画的组件或组件列表。如果为 None,则进度动画将显示在所有输出组件上。
queue: bool
queue: bool= True如果为 True,则会将请求放在队列中(如果队列已启用)。如果为 False,则不会将此事件放入队列,即使队列已启用。如果为 None,则将使用 Gradio 应用的队列设置。
batch: bool
batch: bool= False如果为 True,则函数应处理一批输入,这意味着它应该为每个参数接受一个输入值列表。列表的长度应相同(最多为 `max_batch_size`)。然后,该函数*必须*返回一个元组的列表(即使只有一个输出组件),元组中的每个列表对应一个输出组件。
preprocess: bool
preprocess: bool= True如果为 False,则在运行 'fn' 之前不会进行组件数据预处理(例如,当使用 `Image` 组件调用此方法时,将其保留为 base64 字符串)。
cancels: dict[str, Any] | list[dict[str, Any]] | None
cancels: dict[str, Any] | list[dict[str, Any]] | None= None取消其他事件的列表,当此监听器触发时。例如,设置 cancels=[click_event] 将会取消 click_event,其中 click_event 是另一个组件的 .click 方法的返回值。尚未运行的函数(或正在迭代的生成器)将被取消,但正在运行的函数将被允许完成。
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
trigger_mode: Literal['once', 'multiple', 'always_last'] | None= None如果设置为 "once"(除 `.change()` 之外所有事件的默认值),则在事件挂起时不允许任何提交。如果设置为 "multiple",则在事件挂起时允许无限次提交,而 "always_last"(`.change()` 和 `.key_up()` 事件的默认值)则允许在挂起事件完成后进行第二次提交。
js: str | Literal[True] | None
js: str | Literal[True] | None= None在运行 'fn' 之前运行可选的前端 JS 方法。JS 方法的输入参数是 'inputs' 和 'outputs' 的值,返回值应为输出组件的值列表。
concurrency_limit: int | None | Literal['default']
concurrency_limit: int | None | Literal['default']= "default"如果设置,这是可以同时运行的此事件的最大数量。可以设置为 None,表示没有并发限制(此事件可以同时运行任意数量)。设置为 "default" 可使用 `Blocks.queue()` 中的 `default_concurrency_limit` 参数定义的默认并发限制(该参数本身默认为 1)。
concurrency_id: str | None
concurrency_id: str | None= None如果设置,这是并发组的 ID。具有相同 `concurrency_id` 的事件将受到最低设置的 `concurrency_limit` 的限制。
api_visibility: Literal['public', 'private', 'undocumented']
api_visibility: Literal['public', 'private', 'undocumented']= "public"控制此端点的可见性和可访问性。可以是 "public"(在 API 文档中显示并可由客户端调用)、"private"(在 API 文档中隐藏,不可由客户端调用)或 "undocumented"(在 API 文档中隐藏,但可由客户端通过 gr.load 调用)。如果 fn 为 None,则 api_visibility 将自动设置为 "private"。
gradio.Sidebar.collapse(···)描述 %20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.3L391.3%20319.9C381%20334.2%20361%20337.6%20346.7%20327.3C332.3%20317%20328.9%20297%20339.2%20282.7L340.3%20281.1C363.2%20249%20359.6%20205.1%20331.7%20177.2C300.3%20145.8%20249.2%20145.8%20217.7%20177.2L105.5%20289.5C73.99%20320.1%2073.99%20372%20105.5%20403.5C133.3%20431.4%20177.3%20435%20209.3%20412.1L210.9%20410.1C225.3%20400.7%20245.3%20404%20255.5%20418.4C265.8%20432.8%20262.5%20452.8%20248.1%20463.1L246.5%20464.2C188.1%20505.3%20110.2%20498.7%2060.21%20448.8C3.741%20392.3%203.741%20300.7%2060.21%20244.3L172.5%20131.1zM467.5%20380C411%20436.5%20319.5%20436.5%20263%20380C213%20330%20206.5%20251.2%20247.6%20193.7L248.7%20192.1C258.1%20177.8%20278.1%20174.4%20293.3%20184.7C307.7%20194.1%20311.1%20214.1%20300.8%20229.3L299.7%20230.9C276.8%20262.1%20280.4%20306.9%20308.3%20334.8C339.7%20366.2%20390.8%20366.2%20422.3%20334.8L534.5%20222.5C566%20191%20566%20139.1%20534.5%20108.5C506.7%2080.63%20462.7%2076.99%20430.7%2099.9L429.1%20101C414.7%20111.3%20394.7%20107.1%20384.5%2093.58C374.2%2079.2%20377.5%2059.21%20391.9%2048.94L393.5%2047.82C451%206.731%20529.8%2013.25%20579.8%2063.24C636.3%20119.7%20636.3%20211.3%20579.8%20267.7L467.5%20380z'/%3e%3c/svg%3e)
当侧边栏折叠时触发此监听器。
fn: Callable | None | Literal['decorator']
fn: Callable | None | Literal['decorator']= "decorator"当此事件触发时调用的函数。通常是机器学习模型的预测函数。函数的每个参数对应一个输入组件,函数应返回一个单一值或一个值元组,元组中的每个元素对应一个输出组件。
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None= None用作输入的 gradio.components 列表。如果函数不接受输入,则此列表应为空。
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None= None用作输出的 gradio.components 列表。如果函数不返回输出,则此列表应为空。
api_name: str | None
api_name: str | None= None定义该端点在 API 文档中如何显示。可以是字符串或 None。如果设置为字符串,则该端点将在 API 文档中以给定名称显示。如果为 None(默认),则使用函数的名称作为 API 端点。
api_description: str | None | Literal[False]
api_description: str | None | Literal[False]= NoneAPI 端点的描述。可以是字符串、None 或 False。如果设置为字符串,则该端点将在 API 文档中以给定描述显示。如果为 None,则使用函数的 docstring 作为 API 端点描述。如果为 False,则 API 文档中不会显示任何描述。
show_progress: Literal['full', 'minimal', 'hidden']
show_progress: Literal['full', 'minimal', 'hidden']= "full"事件运行时如何显示进度动画:“full”显示一个覆盖输出组件区域的加载指示器,并在右上角显示运行时信息,“minimal”仅显示运行时信息,“hidden”不显示任何进度动画。
show_progress_on: Component | list[Component] | None
show_progress_on: Component | list[Component] | None= None用于显示进度动画的组件或组件列表。如果为 None,则进度动画将显示在所有输出组件上。
queue: bool
queue: bool= True如果为 True,则会将请求放在队列中(如果队列已启用)。如果为 False,则不会将此事件放入队列,即使队列已启用。如果为 None,则将使用 Gradio 应用的队列设置。
batch: bool
batch: bool= False如果为 True,则函数应处理一批输入,这意味着它应该为每个参数接受一个输入值列表。列表的长度应相同(最多为 `max_batch_size`)。然后,该函数*必须*返回一个元组的列表(即使只有一个输出组件),元组中的每个列表对应一个输出组件。
preprocess: bool
preprocess: bool= True如果为 False,则在运行 'fn' 之前不会进行组件数据预处理(例如,当使用 `Image` 组件调用此方法时,将其保留为 base64 字符串)。
cancels: dict[str, Any] | list[dict[str, Any]] | None
cancels: dict[str, Any] | list[dict[str, Any]] | None= None取消其他事件的列表,当此监听器触发时。例如,设置 cancels=[click_event] 将会取消 click_event,其中 click_event 是另一个组件的 .click 方法的返回值。尚未运行的函数(或正在迭代的生成器)将被取消,但正在运行的函数将被允许完成。
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
trigger_mode: Literal['once', 'multiple', 'always_last'] | None= None如果设置为 "once"(除 `.change()` 之外所有事件的默认值),则在事件挂起时不允许任何提交。如果设置为 "multiple",则在事件挂起时允许无限次提交,而 "always_last"(`.change()` 和 `.key_up()` 事件的默认值)则允许在挂起事件完成后进行第二次提交。
js: str | Literal[True] | None
js: str | Literal[True] | None= None在运行 'fn' 之前运行可选的前端 JS 方法。JS 方法的输入参数是 'inputs' 和 'outputs' 的值,返回值应为输出组件的值列表。
concurrency_limit: int | None | Literal['default']
concurrency_limit: int | None | Literal['default']= "default"如果设置,这是可以同时运行的此事件的最大数量。可以设置为 None,表示没有并发限制(此事件可以同时运行任意数量)。设置为 "default" 可使用 `Blocks.queue()` 中的 `default_concurrency_limit` 参数定义的默认并发限制(该参数本身默认为 1)。
concurrency_id: str | None
concurrency_id: str | None= None如果设置,这是并发组的 ID。具有相同 `concurrency_id` 的事件将受到最低设置的 `concurrency_limit` 的限制。
api_visibility: Literal['public', 'private', 'undocumented']
api_visibility: Literal['public', 'private', 'undocumented']= "public"控制此端点的可见性和可访问性。可以是 "public"(在 API 文档中显示并可由客户端调用)、"private"(在 API 文档中隐藏,不可由客户端调用)或 "undocumented"(在 API 文档中隐藏,但可由客户端通过 gr.load 调用)。如果 fn 为 None,则 api_visibility 将自动设置为 "private"。