Skip to content

Instantly share code, notes, and snippets.

@aaditkamat
Created June 26, 2024 14:49
Show Gist options
  • Save aaditkamat/86132a11b06cfe5497fe793474d9f221 to your computer and use it in GitHub Desktop.
Save aaditkamat/86132a11b06cfe5497fe793474d9f221 to your computer and use it in GitHub Desktop.
Summarize any text in 13 sentences using Sumy
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lsa import LsaSummarizer
with open('transcript.txt') as in_file:
text = in_file.read()
parser = PlaintextParser.from_string(text, Tokenizer("english"))
summarizer = LsaSummarizer()
num_sentences = 13
summary = summarizer(parser.document, num_sentences) # The number '3' indicates the number of sentences in the summary
with open('summarized_transcript.txt', mode='w') as out_file:
for sentence in summary:
out_file.write(str(sentence) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment