File size: 1,124 Bytes
9c6594c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
"""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]:
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
|