issam9 commited on
Commit
467473c
1 Parent(s): 31475cc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sumy.parsers.plaintext import PlaintextParser
2
+ from sumy.parsers.html import HtmlParser
3
+ from sumy.nlp.tokenizers import Tokenizer
4
+ from sumy.nlp.stemmers import Stemmer
5
+ from sumy.utils import get_stop_words
6
+
7
+ import gradio as gr
8
+
9
+ import nltk
10
+ nltk.download('punkt')
11
+
12
+
13
+ def summarize(algorithm, language, sentence_count, input_type, input_):
14
+ if algorithm == 'LSA':
15
+ from sumy.summarizers.lsa import LsaSummarizer as Summarizer
16
+ if algorithm =='text-rank':
17
+ from sumy.summarizers.text_rank import TextRankSummarizer as Summarizer
18
+ if algorithm =='lex-rank':
19
+ from sumy.summarizers.lex_rank import LexRankSummarizer as Summarizer
20
+ if algorithm =='edmundson':
21
+ from sumy.summarizers.edmundson import EdmundsonSummarizer as Summarizer
22
+ if algorithm =='luhn':
23
+ from sumy.summarizers.luhn import LuhnSummarizer as Summarizer
24
+ if algorithm =='kl-sum':
25
+ from sumy.summarizers.kl import KLSummarizer as Summarizer
26
+ if algorithm =='random':
27
+ from sumy.summarizers.random import RandomSummarizer as Summarizer
28
+ if algorithm =='reduction':
29
+ from sumy.summarizers.reduction import ReductionSummarizer as Summarizer
30
+
31
+ if input_type=="URL":
32
+ parser = HtmlParser.from_url(input_, Tokenizer(language))
33
+ if input_type=="text":
34
+ parser = PlaintextParser.from_string(input_, Tokenizer(language))
35
+
36
+ stemmer = Stemmer(language)
37
+ summarizer = Summarizer(stemmer)
38
+ stop_words = get_stop_words(language)
39
+
40
+ if algorithm=='edmundson':
41
+ summarizer.null_words = stop_words
42
+ summarizer.bonus_words = parser.significant_words
43
+ summarizer.stigma_words = parser.stigma_words
44
+ else:
45
+ summarizer.stop_words = stop_words
46
+
47
+ summary_sentences = summarizer(parser.document, sentence_count)
48
+ summary = ' '.join([str(sentence) for sentence in summary_sentences])
49
+
50
+ return summary
51
+
52
+
53
+ iface = gr.Interface(
54
+ summarize,
55
+ [
56
+ gr.inputs.Dropdown(["LSA", "luhn", "edmundson", "text-rank", "lex-rank", "random", "reduction", "kl-sum"]),
57
+ gr.inputs.Textbox(1, default="english"),
58
+ gr.inputs.Number(default=5),
59
+ gr.inputs.Radio(["URL", "text"], default="URL"),
60
+ gr.inputs.Textbox(5),
61
+ ],
62
+ "text",
63
+ examples=[
64
+ ["LSA", 'english', 5, "URL", "https://en.wikipedia.org/wiki/Automatic_summarization"]
65
+ ],
66
+ )
67
+
68
+ iface.launch()