Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
def main():
|
5 |
+
|
6 |
+
available_models = {
|
7 |
+
"Google Pegasus": "suriya7/bart-finetuned-text-summarization",
|
8 |
+
"Facebook Bart" : "Azma-AI/bart-large-text-summarizer",
|
9 |
+
}
|
10 |
+
|
11 |
+
history = []
|
12 |
+
summary_read = ''
|
13 |
+
|
14 |
+
if 'history' not in st.session_state:
|
15 |
+
st.session_state['history'] = []
|
16 |
+
|
17 |
+
def summarize_text(text, max_length, model, model_name ):
|
18 |
+
global summary_read
|
19 |
+
|
20 |
+
summarizer = pipeline('summarization', model=model)
|
21 |
+
|
22 |
+
summary = summarizer(text, max_length=max_length+10, min_length=max_length, do_sample=False)
|
23 |
+
|
24 |
+
st.write(summary[0]['summary_text'])
|
25 |
+
print(summary[0]['summary_text'])
|
26 |
+
summary_read = summary[0]['summary_text']
|
27 |
+
|
28 |
+
st.session_state['history'].append({
|
29 |
+
'original text' : text,
|
30 |
+
'summary': summary[0]['summary_text'],
|
31 |
+
'model': model_name,
|
32 |
+
'word_limit': max_length-10,
|
33 |
+
|
34 |
+
})
|
35 |
+
|
36 |
+
st.title('Text Summarizer')
|
37 |
+
text = st.text_area("Enter Text:", value='', height=None, max_chars=None, key=None)
|
38 |
+
max_length = st.slider("Max Length:", min_value=10, max_value=100, step=1)
|
39 |
+
model_name = st.selectbox("Choose a model:", list(available_models.keys()))
|
40 |
+
model_choice = available_models[model_name]
|
41 |
+
|
42 |
+
col1, col2, col3, col4, col5 = st.columns([1,1,1,1,1])
|
43 |
+
with col1:
|
44 |
+
st.write(" ")
|
45 |
+
with col2:
|
46 |
+
st.write(" ")
|
47 |
+
with col3:
|
48 |
+
like = st.button('π')
|
49 |
+
with col4:
|
50 |
+
dislike = st.button('π')
|
51 |
+
with col5:
|
52 |
+
st.write(" ")
|
53 |
+
|
54 |
+
if st.button('Summarize'):
|
55 |
+
if text:
|
56 |
+
max_length = max_length+10
|
57 |
+
print(max_length)
|
58 |
+
summarize_text(text, max_length, model_choice, model_name)
|
59 |
+
else:
|
60 |
+
st.write("Please enter text for summarization.")
|
61 |
+
|
62 |
+
for i, item in enumerate(st.session_state['history']):
|
63 |
+
st.sidebar.markdown(f'{i+1}.')
|
64 |
+
for key, value in item.items():
|
65 |
+
st.sidebar.markdown(f'{key}: {value}')
|
66 |
+
|
67 |
+
if __name__ == "__main__":
|
68 |
+
main()
|