File size: 5,075 Bytes
37fc8cc
 
60502ac
 
37fc8cc
4d0fa50
37fc8cc
60502ac
 
 
256cbd2
7d9500e
 
60502ac
2df8887
7d9500e
9c5248b
ba6b10b
 
4d0fa50
 
ecfe56e
ba6b10b
60502ac
db3725f
60502ac
e69e8d6
 
 
 
 
72c6f28
e69e8d6
72c6f28
ecfe56e
60502ac
a585275
1fff449
 
 
8a41675
7cb54c9
60502ac
8a41675
1fff449
e69e8d6
a3dd0a5
ecfe56e
fb820ae
885bf46
ecfe56e
4d0fa50
 
885bf46
4d0fa50
e69e8d6
885bf46
2df3a81
878dc62
4d0fa50
3ce064f
77c5edf
3ce064f
 
 
 
 
ecfe56e
60502ac
 
ecfe56e
 
878dc62
 
ecfe56e
878dc62
4d0fa50
 
60502ac
878dc62
256cbd2
 
 
 
 
 
d6c20bd
878dc62
 
d19a175
72c6f28
2df3a81
ecfe56e
 
 
 
 
 
 
7d9500e
ecfe56e
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 10 02:08:50 2021
@author: puran
"""

import streamlit as st
import torch 
#import transformers 
from transformers import pipeline

image = Image.open('hb.jpg')

#from transformers import 
st.header("KNU- Abstractive Summarizer Machine!")
st.image(image, caption='Welcome to KNU Summarizer')



plms =["facebook/bart-large-cnn", "google/pegasus-xsum", "t5-small" ]

def load_plms(model_name):
    #model_name = "google/pegasus-xsum"
    summarizer = pipeline(task="summarization", model=model_name) 
    
    return summarizer    

def load_zeroshot_classifier():
    
    classifier = pipeline("zero-shot-classification",
                         model="facebook/bart-large-mnli")
    
    return classifier
    
def get_summarizer(summarizer, sequence:str, maximum_tokens:int, minimum_tokens:int):
	output = summarizer(sequence, num_beams=4, max_length=maximum_tokens, min_length=minimum_tokens, do_sample=False)
	return output[0].get('summary_text')



ARTICLE ="""New York (CNN)
When Liana Barrientos was 23 years old, she got married in Westchester County, New York.A year later, she got married again in Westchester County, but to a different man and without divorcing her first husband.Only 18 days after that marriage, she got hitched yet again. Then, Barrientos declared "I do" five more times, sometimes only within two weeks of each other.In 2010, she married once more, this time in the Bronx. In an application for a marriage license, she stated it was her "first and only" marriage.Barrientos, now 39, is facing two criminal counts of "offering a false instrument for filing in the first degree," referring to her false statements on the 2010 marriage license application, according to court documents.
Prosecutors said the marriages were part of an immigration scam. On Friday, she pleaded not guilty at State Supreme Court in the Bronx, according to her attorney, Christopher Wright, who declined to comment further. After leaving court, Barrientos was arrested and charged with theft of service and criminal trespass for allegedly sneaking into the New York subway through an emergency exit, said Detective Annette Markowski, a police spokeswoman. In total, Barrientos has been married 10 times, with nine of her marriages occurring between 1999 and 2002. All occurred either in Westchester County, Long Island, New Jersey or the Bronx. She is believed to still be married to four men, and at one time, she was married to eight men at once, prosecutors say. Prosecutors said the immigration scam involved some of her husbands, who filed for permanent residence status shortly after the marriages. Any divorces happened only after such filings were approved. It was unclear whether any of the men will be prosecuted.
 The case was referred to the Bronx District Attorney\'s Office by Immigration and Customs Enforcement and the Department of Homeland Security\'s Investigation Division. Seven of the men are from so-called "red-flagged" countries, including Egypt, Turkey, Georgia, Pakistan and Mali. Her eighth husband, Rashid Rajput, was deported in 2006 to his native Pakistan after an investigation by the Joint Terrorism Task Force. If convicted, Barrientos faces up to four years in prison.  Her next court appearance is scheduled for May 18."""

 
with st.spinner(' (1) / (3) Loading BART Pretrained Model (_please allow for 30 seconds_)...'):
    summarizer_1 = load_plms(plms[0])   

with st.spinner(' (2) / (3) Loading Google-PEGASUS Pretrained Model (_please allow for 30 seconds_)...'):
    summarizer_2 = load_plms(plms[1])   
    #summarizer_3 = load_plms(plms[2]) 
    
with st.spinner(' (3) / (3) Loading Pretraining Classifier'):
    classifier = load_zeroshot_classifier()
    
    st.success("All Loadings are done!")
 



st.markdown("### Information")
st.write("__Inputs__: Text your input article!!")
st.write("__Outputs__: Summarizing output text by State-of-the-art NLP summarization Models! ")



with st.form(key="input_area"):
    display_text = ARTICLE + "\n\n" 
    text_input = st.text_area("Input any text you want to summaryize & classify here (keep in mind very long text will take a while to process):", display_text)
    submit_button = st.form_submit_button(label='SUBMIT')



output_text = []



if submit_button:
    with st.spinner('On summarizing !...wait a second please..'):
        
        get_1 = get_summarizer(summarizer_1, text_input, 150, 5)
        get_2 = get_summarizer(summarizer_2, text_input, 150, 5)
        
        output_text.append(get_1)
        output_text.append(get_2)
        #output_text.append(get_summarizer(summarizer_3, text_input, 150, 5))
   
    
    st.markdown("### Outputs are here !:  ")
    
    for i in range(2):
        st.markdown("**"+ plms[i] +"s Output:  **  ")
        st.text(output_text[i])
        st.success(f"{i+1} of 3 are done!")
        
    st.success("Congrats!!! ALL DONE!")
    st.balloons()
    
    balloon_button = st.button(label='More Balloon?')

    if balloon_button:    
        st.balloons()