Spaces:
Runtime error
Runtime error
File size: 5,023 Bytes
c20a951 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# 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")
st.set_option('deprecation.showPyplotGlobalUse', False)
def main():
menu = ["Home","Storage","About"]
create_table()
choice = st.sidebar.selectbox("Menu",menu)
if choice == "Home":
st.title("Demo")
st.sidebar.subheader("Tuning/Settings")
# max_length= st.sidebar.slider("Maximum length of the generated text ",30,100)
# top_k= st.sidebar.slider(" limits the sampled tokens to the top k values ",1,100)
# temperature= st.sidebar.slider("Controls the craziness of the text ",0.7,100.0)
model_type = st.sidebar.selectbox("Model type", options=["Bart","T5"])
upload_doc = st.file_uploader("Upload a .txt, .pdf, .docx file for summarization")
st.markdown("<h3 style='text-align: center; color: red;'>OR</h3>",unsafe_allow_html=True,)
plain_text = st.text_area("Type your Message...",height=200)
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("Summarize...")
# 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=100, min_length=30)
summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
st.success("Data Submitted for model retraining")
postdate = datetime.now()
# Add Data To Database
add_data(text_to_summarize,summarized_text,postdate)
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=100, min_length=30)
summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
st.success("Data Submitted for model retraining")
postdate = datetime.now()
# Add Data To Database
add_data(text_to_summarize,summarized_text,postdate)
# else:
# text_to_summarize = clean_text
# with st.spinner(
# text="Loading Pegasus Model and Extracting summary. This might take a few seconds depending on the length of your text..."):
# summarizer_model = pegasus()
# summarized_text = summarizer_model(text_to_summarize, max_length=100, min_length=30)
# # summarized_text = ' '.join([summ['summary_text'] for summ in summarized_text])
# st.success("Data Submitted for model retraining")
# postdate = datetime.now()
# # Add Data To Database
# # add_data(text_to_summarize,summarized_text,postdate)
res_col1 ,res_col2 = st.columns(2)
with res_col1:
st.subheader("Generated Text Visualization")
# 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("Summarized Text Output")
st.success("Summarized Text")
st.write(summarized_text)
elif choice == "Storage":
st.title("Manage & Monitor Results")
# stored_data = view_all_data()
# new_df = pd.DataFrame(stored_data,columns=["text_to_summarize","summarized_text","postdate"])
# st.dataframe(new_df)
# new_df['postdate'] = pd.to_datetime(new_df['postdate'])
else:
st.subheader("About")
# html_temp ="""<div>
# <p></p>
# <p></p>
# </div>"""
# st.markdown(html_temp, unsafe_allow_html=True)
if __name__ == '__main__':
main() |