Ashrafb commited on
Commit
43e22f3
·
1 Parent(s): ce003c0

Upload app.py

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