UjjwalVIT's picture
Text-Summary.png
30d91a5
import streamlit as st
import sumy
# using sumy library for summarization
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lex_rank import LexRankSummarizer
from sumy.summarizers.text_rank import TextRankSummarizer
from sumy.nlp.tokenizers import Tokenizer
import pandas as pd
import matplotlib.pyplot as plt
# import seaborn
from transformers import BartForConditionalGeneration, BartTokenizer
from transformers import T5ForConditionalGeneration, T5Tokenizer
from rouge import Rouge
import altair as at
import torch
from Text_analysis import *
from Metadata import *
from app_utils import *
from PIL import Image
HTML_BANNER = """
<div style="background-color:lightgreen;padding:10px;border-radius:10px">
<h1 style="color:white;text-align:center;">Summary app </h1>
</div>
"""
def load_image(file):
img = Image.open(file)
return img
def main():
menu=['Summarization','Text-Analysis','Meta-Data']
choice=st.sidebar.selectbox("Menu",menu)
if choice=='Summarization':
stc.html(HTML_BANNER)
st.image(load_image('Text-Summary.png'))
st.subheader('summarization')
raw_text=st.text_area("Enter the text you want to summarize")
if st.button("Summarize"):
with st.expander("Original Text"):
st.write(raw_text)
c1, c2 = st.columns(2)
with c1:
with st.expander("LexRank Summary"):
try:
summary = sumy_summarizer(raw_text)
document_len={"Original":len(raw_text),
"Summary":len(summary)
}
st.write(document_len)
st.write(summary)
st.info("Rouge Score")
score=evaluate_summary(summary,raw_text)
st.write(score.T)
st.subheader(" ")
score['metrics']=score.index
c=at.Chart(score).mark_bar().encode(
x='metrics',y='rouge-1'
)
st.altair_chart(c)
except:
st.warning('Insufficient data')
with c2:
with st.expander("TextRank Summary"):
try:
text_summary=sumy_text_summarizer(raw_text)
document_len={"Original":len(raw_text),
"Summary":len(summary)
}
st.write(document_len)
st.write(text_summary)
st.info("Rouge Score")
score=evaluate_summary(text_summary,raw_text)
st.write(score.T)
st.subheader(" ")
score['metrics']=score.index
c=at.Chart(score).mark_bar().encode(
x='metrics',y='rouge-1'
)
st.altair_chart(c)
except:
st.warning('Insufficient data')
st.subheader("Bart Sumary")
with st.expander("Bart Summary"):
try:
bart_summ = bart_summary(raw_text)
document_len={"Original":len(raw_text),
"Summary":len(summary)
}
st.write(document_len)
st.write(bart_summ)
st.info("Rouge Score")
score=evaluate_summary(bart_summ,raw_text)
st.write(score.T)
st.subheader(" ")
score['metrics']=score.index
c=at.Chart(score).mark_bar().encode(
x='metrics',y='rouge-1'
)
st.altair_chart(c)
except:
st.warning('Insufficient data')
st.subheader("T5 Sumarization")
with st.expander("T5 Summary"):
try:
T5_sum = T5_summary(raw_text)
document_len={"Original":len(raw_text),
"Summary":len(summary)
}
st.write(document_len)
st.write(T5_sum)
st.info("Rouge Score")
score=evaluate_summary(T5_sum,raw_text)
st.write(score.T)
st.subheader(" ")
score['metrics']=score.index
c=at.Chart(score).mark_bar().encode(
x='metrics',y='rouge-1'
)
st.altair_chart(c)
except:
st.warning('Insufficient data')
elif choice=='Text-Analysis':
text_analysis()
else:
metadata()
if __name__=='__main__':
main()