File size: 1,499 Bytes
			
			| 870ab6b | 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 48 49 50 51 | """gr.State() component."""
from __future__ import annotations
from copy import deepcopy
from typing import Any
from gradio_client.documentation import document, set_documentation_group
from gradio_client.serializing import SimpleSerializable
from gradio.components.base import IOComponent
set_documentation_group("component")
@document()
class State(IOComponent, SimpleSerializable):
    """
    Special hidden component that stores session state across runs of the demo by the
    same user. The value of the State variable is cleared when the user refreshes the page.
    Preprocessing: No preprocessing is performed
    Postprocessing: No postprocessing is performed
    Demos: blocks_simple_squares
    Guides: real-time-speech-recognition
    """
    allow_string_shortcut = False
    def __init__(
        self,
        value: Any = None,
        **kwargs,
    ):
        """
        Parameters:
            value: the initial value (of arbitrary type) of the state. The provided argument is deepcopied. If a callable is provided, the function will be called whenever the app loads to set the initial value of the state.
        """
        self.stateful = True
        IOComponent.__init__(self, value=deepcopy(value), **kwargs)
class Variable(State):
    """Variable was renamed to State. This class is kept for backwards compatibility."""
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
    def get_block_name(self):
        return "state"
 |