Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Core Pkgs
|
2 |
+
import streamlit as st
|
3 |
+
from function import *
|
4 |
+
# EDA Pkgs
|
5 |
+
import pandas as pd
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
from wordcloud import WordCloud
|
8 |
+
# Utils
|
9 |
+
from datetime import datetime
|
10 |
+
warnings.filterwarnings("ignore")
|
11 |
+
|
12 |
+
# page info setup
|
13 |
+
menu_items = {
|
14 |
+
'Get help':'https://https://www.linkedin.com/in/ayomide-ishola-924014162/' ,
|
15 |
+
'Report a bug': 'https://www.linkedin.com/in/ayomide-ishola-924014162/',
|
16 |
+
'About': '''
|
17 |
+
## My Custom App
|
18 |
+
|
19 |
+
Some markdown to show in the About dialog.
|
20 |
+
'''
|
21 |
+
}
|
22 |
+
#page configuration
|
23 |
+
st.set_page_config(page_title="Article Summerizer", page_icon="./favicon/favicon.ico",menu_items=menu_items)
|
24 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
25 |
+
|
26 |
+
def main():
|
27 |
+
# This is used to hide the made with streamlit watermark
|
28 |
+
hide_streamlit_style = """
|
29 |
+
<style>
|
30 |
+
footer {visibility: hidden;}
|
31 |
+
</style>
|
32 |
+
"""
|
33 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
34 |
+
|
35 |
+
# Article Summerizer heading
|
36 |
+
st.markdown("<h1 style = 'color:green; align:center; font-size: 40px;'> Article Summerizer</h1>", unsafe_allow_html=True)
|
37 |
+
|
38 |
+
# control for Model Settings
|
39 |
+
st.sidebar.markdown("<h4 style = 'color:green; align:center; font-size: 20px;'> Model Settings</h1>", unsafe_allow_html=True)
|
40 |
+
max_length= st.sidebar.slider("Maximum length of the generated text is 500 tokens",min_value=100,max_value=500)
|
41 |
+
min_length= st.sidebar.slider("Minimum length of the generated text",min_value=30)
|
42 |
+
model_type = st.sidebar.selectbox("Model type", options=["Bart","T5"])
|
43 |
+
|
44 |
+
# This function is used to upload a .txt, .pdf, .docx file for summarization
|
45 |
+
upload_doc = st.file_uploader("Upload a .txt, .pdf, .docx file for summarization")
|
46 |
+
|
47 |
+
st.markdown("<h3 style='text-align: center; color: green;'>or</h3>",unsafe_allow_html=True)
|
48 |
+
|
49 |
+
#This function is used to Type your Message (text area)
|
50 |
+
plain_text = st.text_area("Type your Message",height=200)
|
51 |
+
|
52 |
+
# this is used to control the logic of the code
|
53 |
+
if upload_doc:
|
54 |
+
clean_text = preprocess_plain_text(extract_text_from_file(upload_doc))
|
55 |
+
else:
|
56 |
+
clean_text = preprocess_plain_text(plain_text)
|
57 |
+
|
58 |
+
summarize = st.button("Summarize")
|
59 |
+
|
60 |
+
# called on toggle button [summarize]
|
61 |
+
if summarize:
|
62 |
+
if model_type == "Bart":
|
63 |
+
text_to_summarize = clean_text
|
64 |
+
|
65 |
+
with st.spinner(
|
66 |
+
text="Loading Bart Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
|
67 |
+
summarizer_model = bart()
|
68 |
+
summarized_text = summarizer_model(text_to_summarize, max_length=max_length ,min_length=min_length)
|
69 |
+
summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
|
70 |
+
|
71 |
+
elif model_type == "T5":
|
72 |
+
text_to_summarize = clean_text
|
73 |
+
|
74 |
+
with st.spinner(
|
75 |
+
text="Loading T5 Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
|
76 |
+
summarizer_model = t5()
|
77 |
+
summarized_text = summarizer_model(text_to_summarize, max_length=max_length, min_length=min_length)
|
78 |
+
summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
|
79 |
+
|
80 |
+
res_col1 ,res_col2 = st.columns(2)
|
81 |
+
with res_col1:
|
82 |
+
st.subheader("Generated Text Visualization")
|
83 |
+
# Create and generate a word cloud image:
|
84 |
+
wordcloud = WordCloud().generate(summarized_text)
|
85 |
+
# Display the generated image:
|
86 |
+
plt.imshow(wordcloud, interpolation='bilinear')
|
87 |
+
plt.axis("off")
|
88 |
+
plt.show()
|
89 |
+
st.pyplot()
|
90 |
+
summary_downloader(summarized_text)
|
91 |
+
|
92 |
+
with res_col2:
|
93 |
+
st.subheader("Summarized Text Output")
|
94 |
+
st.success("Summarized Text")
|
95 |
+
st.write(summarized_text)
|
96 |
+
|
97 |
+
if __name__ == '__main__':
|
98 |
+
main()
|