Mohamed-Sami
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from summarization_methods import summary_with_lsa
|
2 |
+
from summarization_methods import summary_with_text_rank
|
3 |
+
from summarization_methods import summary_with_text_reduction
|
4 |
+
from summarization_methods import summary_with_tfidf
|
5 |
+
import gradio as gr
|
6 |
+
from enum import Enum
|
7 |
+
|
8 |
+
class SummarizationMehods(Enum):
|
9 |
+
LSA = 0
|
10 |
+
TextRank = 1
|
11 |
+
TextReduction = 2
|
12 |
+
TfIdf = 3
|
13 |
+
|
14 |
+
|
15 |
+
def summary(text , num_sentences=3 , method = SummarizationMehods(0).name):
|
16 |
+
if method.casefold() == SummarizationMehods(0).name.casefold():
|
17 |
+
summary = summary_with_lsa(text , num_sentences)
|
18 |
+
elif method.casefold()==SummarizationMehods(1).name.casefold():
|
19 |
+
summary = summary_with_text_rank(text , num_sentences )
|
20 |
+
elif method.casefold() == SummarizationMehods(2).name.casefold():
|
21 |
+
summary = summary_with_text_reduction(text , num_sentences)
|
22 |
+
|
23 |
+
elif method.casefold() == SummarizationMehods(3).name.casefold():
|
24 |
+
summary = summary_with_tfidf(text , num_sentences)
|
25 |
+
|
26 |
+
return summary
|
27 |
+
|
28 |
+
demo = gr.Interface(
|
29 |
+
fn=summary,
|
30 |
+
|
31 |
+
inputs=[gr.TextArea() , gr.Slider(minimum=1 , maximum=10 , step=1) ,
|
32 |
+
gr.Dropdown(choices=[SummarizationMehods(0).name ,SummarizationMehods(1).name ,
|
33 |
+
SummarizationMehods(2).name , SummarizationMehods(3).name])],
|
34 |
+
outputs=gr.Text()
|
35 |
+
)
|
36 |
+
|
37 |
+
if __name__ == '__main__':
|
38 |
+
|
39 |
+
demo.launch()
|