Performs summarization on text.
mp.tasks.text.TextSummarizer(
lib: serial_dispatcher.SerialDispatcher, handle: ctypes.c_void_p
)
Methods
close
View source
close()
Shuts down the MediaPipe task instance.
create_from_model_path
View source
@classmethod
create_from_model_path(
model_path: str
) -> 'TextSummarizer'
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
@classmethod
create_from_options(
options: mp.tasks.text.TextSummarizerOptions
) -> 'TextSummarizer'
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
summarize(
text: str
) -> mp.tasks.text.TextSummarizerResult
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
summarize_async(
text: str,
result_callback: Callable[[Optional[TextSummarizerResult], Optional[str]], None]
) -> None
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
__enter__()
Returns self upon entering the runtime context.
__exit__
View source
__exit__(
unused_exc_type, unused_exc_value, unused_traceback
)
Shuts down the MediaPipe task instance on exit of the context manager.