File size: 4,954 Bytes
575adcc 6177ad7 575adcc 6177ad7 575adcc 6177ad7 575adcc 6177ad7 163e67a 6177ad7 575adcc 48beee2 575adcc 48beee2 575adcc 48beee2 575adcc 48beee2 575adcc |
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
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 *
HTML_BANNER = """
<div style="background-color:lightgreen;padding:10px;border-radius:10px">
<h1 style="color:white;text-align:center;">Summary app </h1>
</div>
"""
def main():
menu=['Summarization','Text-Analysis','Meta-Data']
choice=st.sidebar.selectbox("Menu",menu)
if choice=='Summarization':
stc.html(HTML_BANNER)
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"):
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)
elif choice=='Text-Analysis':
text_analysis()
else:
metadata()
if __name__=='__main__':
main()
|