towhee.dag.base_repr.BaseRepr

class towhee.dag.base_repr.BaseRepr(name: str)[source]

Bases: object

Base representation from which all other representation objects inherit.

Primarily implements automatic serialization into YAML/YAML-like string formats, along with defining other universally used properties.

Parameters:

name (str) – Name of the internal object described by this representation.

Methods

inject_template

is_valid

Check if the src is a valid YAML file to describe a component in Towhee.

load_file

Load the representation(s) information from a local YAML file.

load_src

Load the information for the representation.

load_str

Load the representation(s) information from a YAML file (pre-loaded as string).

load_url

Load the representation information from a remote YAML file.

render_template

Attributes

name

__init__(name: str)[source]
static is_valid(info: Dict[str, Any], essentials: Set[str]) bool[source]

Check if the src is a valid YAML file to describe a component in Towhee.

Parameters:
  • info (Dict[str, Any]) – The dict loaded from the source file.

  • essentials (Set[str]) – The essential keys that a valid YAML file should contain.

Returns:

(bool)

Return True if the src file is a valid YAML file to describe a component in Towhee, else False.

static load_file(file: str) dict[source]

Load the representation(s) information from a local YAML file.

Parameters:

file (str) – The file path.

Returns:

(dict)

The dict loaded from the YAML file that contains the representation information.

static load_src(file_or_src: str) dict[source]

Load the information for the representation. We support file from local file/HTTP/HDFS.

Parameters:

file_or_src (str) – The source YAML file or the URL points to the source file or a str loaded from source file.

Returns:

(dict)

The YAML file loaded as dict.

static load_str(string: str) dict[source]

Load the representation(s) information from a YAML file (pre-loaded as string).

Parameters:

string (str) – The string pre-loaded from a YAML.

Returns:

(dict)

The dict loaded from the YAML file that contains the representation information.

static load_url(url: str) dict[source]

Load the representation information from a remote YAML file.

Parameters:

url (str) – The url points to the remote YAML file.

Returns:

(dict)

The dict loaded from the YAML file that contains the representation information.