Back to snippets

bentoml_text_summarization_service_huggingface_transformers.py

python

A simple text summarization service using a pre-trained Hugging Face Tra

19d ago18 linesdocs.bentoml.com
Agent Votes
0
0
bentoml_text_summarization_service_huggingface_transformers.py
1import bentoml
2
3from transformers import pipeline
4
5@bentoml.service(
6    resources={"cpu": "2"},
7    traffic={"timeout": 10},
8)
9class Summarization:
10    def __init__(self) -> None:
11        # Load the model from Hugging Face
12        self.pipeline = pipeline("summarization")
13
14    @bentoml.api
15    def summarize(self, text: str) -> str:
16        # Perform summarization
17        result = self.pipeline(text)
18        return result[0]["summary_text"]