File size: 2,984 Bytes
5295f9d ec915c6 5295f9d 240985f 5295f9d 3d20156 5295f9d 06ef4fc cb98948 5295f9d ec915c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | import streamlit as st
from sumy.parsers.plaintext import PlaintextParser
from sumy.parsers.html import HtmlParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
import nltk
nltk.download('punkt')
def summarize(method, language, sentence_count, input_type, input_):
if method== 'LSA':
from sumy.summarizers.lsa import LsaSummarizer as Summarizer
if method=='text-rank':
from sumy.summarizers.text_rank import TextRankSummarizer as Summarizer
if method=='lex-rank':
from sumy.summarizers.lex_rank import LexRankSummarizer as Summarizer
if method=='edmundson':
from sumy.summarizers.edmundson import EdmundsonSummarizer as Summarizer
if method=='luhn':
from sumy.summarizers.luhn import LuhnSummarizer as Summarizer
if method=='kl-sum':
from sumy.summarizers.kl import KLSummarizer as Summarizer
if method=='random':
from sumy.summarizers.random import RandomSummarizer as Summarizer
if method=='reduction':
from sumy.summarizers.reduction import ReductionSummarizer as Summarizer
if input_type=="URL":
parser = HtmlParser.from_url(input_, Tokenizer(language))
else:
parser = PlaintextParser.from_string(input_, Tokenizer(language))
stemmer = Stemmer(language)
summarizer = Summarizer(stemmer)
stop_words = get_stop_words(language)
if method=='edmundson':
summarizer.null_words = stop_words
summarizer.bonus_words = parser.significant_words
summarizer.stigma_words = parser.stigma_words
else:
summarizer.stop_words = stop_words
summary_sentences = summarizer(parser.document, sentence_count)
summary = ' '.join([str(sentence) for sentence in summary_sentences])
return summary
title = "AIconvert AI text summarization"
description = """
The summary can be extracted either from url link or plain text. .
"""
methods = ["LSA", "luhn", "edmundson", "text-rank", "lex-rank", "random", "reduction", "kl-sum"]
supported_languages = ["english", "french", "arabic", "chinese", "czech", "german", "italian", "hebrew",
"japanese", "portuguese", "slovak", "spanish", "ukrainian", "greek"]
# Streamlit UI
st.title("AIconvert AI text summarization")
st.markdown('<style>h1{color: Crimson; text-align: center;}</style>', unsafe_allow_html=True)
st.markdown(description)
method = st.selectbox("Select Summarization Method", methods)
language = st.selectbox("Select Language", supported_languages)
sentence_count = st.number_input("Number of Sentences", min_value=1, value=7)
input_type = st.radio("Input Type", ["URL", "Text"])
if input_type == "URL":
input_ = st.text_input("Enter URL")
else:
input_ = st.text_area("Enter Text", height=200)
if st.button("Summarize"):
summary = summarize(method, language, sentence_count, input_type, input_)
st.subheader("Summary")
st.write(summary) |