<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L161-L335) |

Performs summarization on text.

```python
mp.tasks.text.TextSummarizer(
    lib: serial_dispatcher.SerialDispatcher, handle: ctypes.c_void_p
)
```

## Methods

### `close`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L318-L324)

```python
close()
```

Shuts down the MediaPipe task instance.

### `create_from_model_path`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L207-L225)

```python
@classmethod
create_from_model_path(
    model_path: str
) -> `mp.tasks.text.TextSummarizer`
```

Creates a `TextSummarizer` object from model path.

<br />

<br />

<br />

| Args ||
|---|---|
| `model_path` | Path to the model. |

<br />

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

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

<br />

### `create_from_options`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L227-L253)

```python
@classmethod
create_from_options(
    options: `mp.tasks.text.TextSummarizerOptions`
) -> `mp.tasks.text.TextSummarizer`
```

Creates the `TextSummarizer` object from text summarizer options.

<br />

<br />

<br />

| Args ||
|---|---|
| `options` | Options for the text summarizer task. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `TextSummarizer` object that's created from `options`. ||

<br />

<br />

<br />

<br />

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

<br />

### `summarize`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L255-L282)

```python
summarize(
    text: str
) -> `mp.tasks.text.TextSummarizerResult`
```

Performs summarization on the input `text`.

<br />

<br />

<br />

| Args ||
|---|---|
| `text` | The input text. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `TextSummarizerResult` object that contains the summary. ||

<br />

<br />

<br />

<br />

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

<br />

### `summarize_async`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L284-L316)

```python
summarize_async(
    text: str,
    result_callback: Callable[[Optional[`mp.tasks.text.TextSummarizerResult`], Optional[str]], None]
) -> None
```

Performs summarization on the input `text` asynchronously.

<br />

<br />

<br />

| 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`. |

<br />

<br />

<br />

<br />

| 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. |

<br />

### `__enter__`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L326-L328)

```python
__enter__()
```

Returns `self` upon entering the runtime context.

### `__exit__`

[View source](https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/tasks/python/text/text_summarizer.py#L330-L332)

```python
__exit__(
    unused_exc_type, unused_exc_value, unused_traceback
)
```

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