forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
23 lines (18 loc) · 822 Bytes
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.text_rank import TextRankSummarizer
from sumy.utils import get_stop_words
def summarize_text(text, num_sentences=3):
parser = PlaintextParser.from_string(text, Tokenizer("english"))
summarizer = TextRankSummarizer()
summarizer.stop_words = get_stop_words("english")
summary = summarizer(parser.document, num_sentences)
return "\n".join([str(sentence) for sentence in summary])
def main():
text = input("Enter the longer piece of text: ")
num_sentences = int(input("Enter the number of sentences for summary: "))
summary = summarize_text(text, num_sentences)
print("\nSummary:")
print(summary)
if __name__ == "__main__":
main()