Provide a code to use it.

#1
by Sidharthkr - opened

Provide a code to use it. Google colab one

class TextSummarizer:
    def __init__(self):
        self.api_token = <HF_TOKEN>
        self.model = "sudeepshouche/autotrain-flan-t5-small-tweet-summarizer-61544146005"

    def summarize(self, content):
        api_url = f"https://api-inference.huggingface.co/models/{self.model}"
        headers = {"Authorization": f"Bearer {self.api_token}"}
        payload = {"inputs": content}

        try:
            response = requests.post(api_url, headers=headers, json=payload)
            response.raise_for_status()
            return response.json()
        except requests.RequestException as e:
            print(f"Error during summarization: {e}")
            # logging.error(f"Error during summarization: {e}")
            return [{'summary_text': content}]

content = <CONTENT_TO_SUMMARIZE>
output = TextSummarizer().summarize(content)
print (output[0]["summary_text"] )

Sign up or log in to comment