File size: 4,769 Bytes
61f188a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752552c
61f188a
 
 
 
 
 
 
 
 
 
 
752552c
8279c98
61f188a
 
 
0f1bd20
61f188a
82036b8
61f188a
 
752552c
61f188a
 
 
 
64e025d
61f188a
 
 
 
 
 
 
752552c
61f188a
 
 
 
 
 
 
 
 
c6751f2
e7c886a
61f188a
 
 
 
 
 
 
e7c886a
439766d
 
82036b8
2cf8964
 
 
82036b8
 
e7c886a
439766d
 
522dca9
61f188a
752552c
61f188a
dca0014
61f188a
 
 
 
 
 
 
 
752552c
 
61f188a
 
 
 
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
# Core Pkgs
import streamlit as st
from function import *
# EDA Pkgs
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud
# Utils
from datetime import datetime
warnings.filterwarnings("ignore")

# page info setup
menu_items = {
	'Get help':'https://https://www.linkedin.com/in/ayomide-ishola-924014162/' ,
	'Report a bug': 'https://www.linkedin.com/in/ayomide-ishola-924014162/',
	'About': '''
	## My Custom App
	Some markdown to show in the About dialog.
	'''
}
#page configuration
st.set_page_config(page_title="Article Summariser", page_icon="./favicon/favicon.ico",menu_items=menu_items)
st.set_option('deprecation.showPyplotGlobalUse', False)

def main():
        # This is used to hide the made with streamlit watermark
        hide_streamlit_style = """
                <style>
                footer {visibility: hidden;}
                </style>
                """
        st.markdown(hide_streamlit_style, unsafe_allow_html=True)

        # Article Summariser heading
        st.markdown("<h1 style = 'color:green; align:center; font-size: 40px;'> Article Summariser</h1>", unsafe_allow_html=True)
        
        # control for Model Settings
        st.sidebar.markdown("<h4 style = 'color:green; align:center; font-size: 20px;'> Model Settings</h1>", unsafe_allow_html=True)
        max_length= st.sidebar.slider("Maximum length of the generated text",min_value=100,max_value=500)
        min_length= st.sidebar.slider("Minimum length of the generated text",min_value=30)
        model_type = st.sidebar.selectbox("Model type", options=["Bart","T5", "SSR"])
        
        # This function is used to upload a .txt, .pdf, .docx file for summarization
        upload_doc = st.file_uploader("Upload a .txt, .pdf, .docx file for summarisation")
        
        st.markdown("<h3 style='text-align: center; color: green;'>or</h3>",unsafe_allow_html=True)

        #This function is used to Type your Message (text area)
        plain_text = st.text_area("Type your text below",height=200)

        # this is used to control the logic of the code
        if upload_doc:
            clean_text = preprocess_plain_text(extract_text_from_file(upload_doc))
        else:
            clean_text = preprocess_plain_text(plain_text)
            
        summarize = st.button("Summarise")        
        
        # called on toggle button [summarize]
        if summarize:
            if model_type == "Bart":
                text_to_summarize = clean_text

                with st.spinner(
                    text="Loading Bart Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
                    summarizer_model = bart()
                    summarized_text = summarizer_model(text_to_summarize, max_length=max_length ,min_length=min_length)
                    summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
            
            elif model_type == "T5":
                text_to_summarize = clean_text

                with st.spinner(
                    text="Loading T5 Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
                    summarizer_model = t5()
                    summarized_text = summarizer_model(text_to_summarize, max_length=max_length, min_length=min_length)
                    summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text]) 
                    
            elif model_type == "SSR":
                text_to_summarize = clean_text

                with st.spinner(
                    text="Loading SSR Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
                    summarizer_model = ssr()
                    summarized_text = summarizer_model(text_to_summarize, max_length=max_length, min_length=min_length)
                    summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])                     

            res_col1 ,res_col2 = st.columns(2)
            with res_col1:
                st.subheader("Generated Text Visualisation")
                # Create and generate a word cloud image:
                wordcloud = WordCloud().generate(summarized_text)
                # Display the generated image:
                plt.imshow(wordcloud, interpolation='bilinear')
                plt.axis("off")
                plt.show()
                st.pyplot()
                summary_downloader(summarized_text)   
                
            with res_col2:
                st.subheader("Summarised Text Output")
                st.success("Summarised Text")
                st.write(summarized_text)

if __name__ == '__main__':
	main()