mp.tasks.text.TextSummarizer

Performs summarization on text.

Methods

close

View source

Shuts down the MediaPipe task instance.

create_from_model_path

View source

Creates a TextSummarizer object from model path.

Args
model_path Path to the model.

Returns
TextSummarizer object that's created from the model file and the default TextSummarizerOptions.

Raises
ValueError If failed to create TextSummarizer object from the provided file such as invalid file path.
RuntimeError If other types of error occurred.

create_from_options

View source

Creates the TextSummarizer object from text summarizer options.

Args
options Options for the text summarizer task.

Returns
TextSummarizer object that's created from options.

Raises
ValueError If failed to create TextSummarizer object from TextSummarizerOptions such as missing the model.
RuntimeError If other types of error occurred.

summarize

View source

Performs summarization on the input text.

Args
text The input text.

Returns
A TextSummarizerResult object that contains the summary.

Raises
ValueError If any of the input arguments is invalid.
RuntimeError If text summarization failed to run.

summarize_async

View source

Performs summarization on the input text asynchronously.

Args
text The input text.
result_callback A callback function that will be called with the TextSummarizerResult and an error message (if any). The callback signature is (result: Optional[TextSummarizerResult], error: Optional[str]) -> None.

Raises
ValueError If any of the input arguments is invalid, or if summarize_async is called before the previous call has finished.
RuntimeError If text summarization failed to run.

__enter__

View source

Returns self upon entering the runtime context.

__exit__

View source

Shuts down the MediaPipe task instance on exit of the context manager.