Skip to content

Gradio Backend

GradioBackend

Bases: Backend

Gradio backend that handles connections to gradio servers.

Source code in mbodied/agents/backends/gradio_backend.py
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
52
53
54
55
56
57
58
59
class GradioBackend(Backend):
    """Gradio backend that handles connections to gradio servers."""

    def __init__(
        self,
        endpoint: str = None,
        **kwargs,
    ) -> None:
        """Initializes the GradioBackend.

        Args:
            endpoint: The url of the gradio server.
            **kwargs: The keywrod arguments to pass to the gradio client.
        """
        self.endpoint = endpoint
        self.client = Client(src=endpoint, **kwargs)

    def predict(self, *args, **kwargs) -> str:
        """Forward queries to the gradio api endpoint `predict`.

        Args:
            *args: The arguments to pass to the gradio server.
            **kwargs: The keywrod arguments to pass to the gradio server.
        """
        return self.client.predict(*args, **kwargs)

    def submit(self, *args, api_name="/predict", result_callbacks=None, **kwargs) -> Job:
        """Submit queries asynchronously without need of asyncio.

        Args:
            *args: The arguments to pass to the gradio server.
            api_name: The name of the api endpoint to submit the job.
            result_callbacks: The callbacks to apply to the result.
            **kwargs: The keywrod arguments to pass to the gradio server.

        Returns:
            Job: Gradio job object.
        """
        return self.client.submit(api_name=api_name, result_callbacks=result_callbacks, *args, **kwargs)

__init__(endpoint=None, **kwargs)

Initializes the GradioBackend.

Parameters:

Name Type Description Default
endpoint str

The url of the gradio server.

None
**kwargs

The keywrod arguments to pass to the gradio client.

{}
Source code in mbodied/agents/backends/gradio_backend.py
24
25
26
27
28
29
30
31
32
33
34
35
36
def __init__(
    self,
    endpoint: str = None,
    **kwargs,
) -> None:
    """Initializes the GradioBackend.

    Args:
        endpoint: The url of the gradio server.
        **kwargs: The keywrod arguments to pass to the gradio client.
    """
    self.endpoint = endpoint
    self.client = Client(src=endpoint, **kwargs)

predict(*args, **kwargs)

Forward queries to the gradio api endpoint predict.

Parameters:

Name Type Description Default
*args

The arguments to pass to the gradio server.

()
**kwargs

The keywrod arguments to pass to the gradio server.

{}
Source code in mbodied/agents/backends/gradio_backend.py
38
39
40
41
42
43
44
45
def predict(self, *args, **kwargs) -> str:
    """Forward queries to the gradio api endpoint `predict`.

    Args:
        *args: The arguments to pass to the gradio server.
        **kwargs: The keywrod arguments to pass to the gradio server.
    """
    return self.client.predict(*args, **kwargs)

submit(*args, api_name='/predict', result_callbacks=None, **kwargs)

Submit queries asynchronously without need of asyncio.

Parameters:

Name Type Description Default
*args

The arguments to pass to the gradio server.

()
api_name

The name of the api endpoint to submit the job.

'/predict'
result_callbacks

The callbacks to apply to the result.

None
**kwargs

The keywrod arguments to pass to the gradio server.

{}

Returns:

Name Type Description
Job Job

Gradio job object.

Source code in mbodied/agents/backends/gradio_backend.py
47
48
49
50
51
52
53
54
55
56
57
58
59
def submit(self, *args, api_name="/predict", result_callbacks=None, **kwargs) -> Job:
    """Submit queries asynchronously without need of asyncio.

    Args:
        *args: The arguments to pass to the gradio server.
        api_name: The name of the api endpoint to submit the job.
        result_callbacks: The callbacks to apply to the result.
        **kwargs: The keywrod arguments to pass to the gradio server.

    Returns:
        Job: Gradio job object.
    """
    return self.client.submit(api_name=api_name, result_callbacks=result_callbacks, *args, **kwargs)