- 组件
- ParamViewer
ParamViewer
gradio.ParamViewer(···)描述
显示一个交互式参数表及其描述和默认值,并进行语法高亮显示。对于每个参数,用户应提供一个类型(例如,str)、一个人可读的描述和一个默认值。由于此组件不接受用户输入,因此很少用作输入组件。在内部,此组件用于在自定义组件库(https://gradio.org.cn/custom-components/gallery)中显示组件的参数。
行为
作为输入组件: (很少使用)将值作为 dict[str, dict] 传递。外部字典中的键是参数名称,而内部字典包含每个参数的“type”、“description”和“default”键。
您的函数应接受其中一种类型
def predict(
value: dict[str, Parameter]
)
...作为输出组件: 期望值为 dict[str, dict]。外部字典中的键是参数名称,而内部字典包含每个参数的“type”、“description”和“default”键。
您的函数应返回其中一种类型
def predict(···) -> dict[str, Parameter]
...
return value初始化
value: dict[str, Parameter] | None
value: dict[str, Parameter] | None= None字典的字典。外部字典中的键是参数名称,而内部字典包含每个参数的“type”、“description”和“default”键。Markdown 链接在“description”中受支持。
every: Timer | float | None
every: Timer | float | None= None持续调用 `value` 来重新计算它(如果 `value` 是一个函数,否则无效)。可以提供一个 Timer,其滴答声会重置 `value`,或者提供一个浮点数来为重置 Timer 提供常规间隔。
inputs: Component | list[Component] | set[Component] | None
inputs: Component | list[Component] | set[Component] | None= None用作计算 `value` 的输入的组件(如果 `value` 是一个函数,否则无效)。`value` 在输入更改时会重新计算。
key: int | str | tuple[int | str, ...] | None
key: int | str | tuple[int | str, ...] | None= None在 `gr.render` 中,跨重渲染具有相同键的组件被视为同一个组件,而不是一个新组件。在 `preserved_by_key` 中设置的属性在重渲染时不会重置。
preserved_by_key: list[str] | str | None
preserved_by_key: list[str] | str | None= "value"此组件构造函数中的参数列表。在 `gr.render()` 函数内部,如果一个组件使用相同的键进行重渲染,则这些(也是唯一的)参数将在 UI 中被保留(如果它们已被用户或事件监听器更改),而不是根据构造函数中提供的值进行重渲染。
快捷方式
gradio.ParamViewer
gradio.ParamViewer"paramviewer"事件监听器
描述
事件监听器允许您响应 Gradio Blocks 应用中定义的 UI 组件的用户交互。当用户与元素交互时(例如,更改滑块值或上传图像),会调用一个函数。
支持的事件监听器
ParamViewer 组件支持以下事件监听器。每个事件监听器都采用相同的参数,这些参数列在下面的 事件参数 表中。
ParamViewer.change(fn, ···)
ParamViewer.change(fn, ···)当 ParamViewer 的值发生变化时触发,无论是由于用户输入(例如,用户在文本框中键入)还是由于函数更新(例如,图像从事件触发器的输出接收值)。请参阅 .input() 以了解仅由用户输入触发的监听器。
ParamViewer.upload(fn, ···)
ParamViewer.upload(fn, ···)当用户将文件上传到 ParamViewer 时触发此监听器。
事件参数
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"。