adf0d17497
publish / version_or_publish (push) Waiting to run
storybook-build / changes (push) Waiting to run
storybook-build / :storybook-build (push) Blocked by required conditions
Sync Gradio Skills to Hugging Face / sync-skills (push) Waiting to run
functional / changes (push) Waiting to run
functional / build-frontend (push) Blocked by required conditions
functional / functional-test-SSR=false (push) Blocked by required conditions
functional / functional-reload (push) Blocked by required conditions
functional / functional-test-SSR=true (push) Blocked by required conditions
hygiene / hygiene-test (push) Waiting to run
python / changes (push) Waiting to run
python / build (push) Blocked by required conditions
python / test-ubuntu-latest-flaky (push) Blocked by required conditions
python / test-ubuntu-latest-not-flaky (push) Blocked by required conditions
python / test-windows-latest-flaky (push) Blocked by required conditions
python / test-windows-latest-not-flaky (push) Blocked by required conditions
js / changes (push) Waiting to run
js / js-test (push) Blocked by required conditions
docs-build / changes (push) Waiting to run
docs-build / docs-build (push) Blocked by required conditions
docs-build / website-build (push) Blocked by required conditions
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""gr.Api() component."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from gradio.components.base import Component
|
|
|
|
|
|
class Api(Component):
|
|
"""
|
|
A generic component that holds any value. Used for generating APIs with no actual frontend component.
|
|
"""
|
|
|
|
EVENTS = []
|
|
|
|
def __init__(
|
|
self,
|
|
value: Any,
|
|
_api_info: dict[str, str],
|
|
label: str = "API",
|
|
):
|
|
"""
|
|
Parameters:
|
|
value: default value.
|
|
"""
|
|
self._api_info = _api_info
|
|
super().__init__(value=value, label=label)
|
|
|
|
def preprocess(self, payload: Any) -> Any:
|
|
return payload
|
|
|
|
def postprocess(self, value: Any) -> Any:
|
|
return value
|
|
|
|
def api_info(self) -> dict[str, str]: # type: ignore[override]
|
|
return self._api_info
|
|
|
|
def example_payload(self) -> Any:
|
|
return self.value if self.value is not None else "..."
|
|
|
|
def example_value(self) -> Any:
|
|
return self.value if self.value is not None else "..."
|
|
|
|
# def get_block_name(self) -> str:
|
|
# return "state" # so that it does not render in the frontend, just like state
|