File size: 2,106 Bytes
7fef0e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

def main():

    available_models = {
        "Google Pegasus": "suriya7/bart-finetuned-text-summarization",
        "Facebook Bart" :  "Azma-AI/bart-large-text-summarizer",    
    }

    history = []
    summary_read = ''

    if 'history' not in st.session_state:
        st.session_state['history'] = []

    def summarize_text(text, max_length, model, model_name ):
        global summary_read  

        summarizer = pipeline('summarization', model=model)
        
        summary = summarizer(text, max_length=max_length+10, min_length=max_length, do_sample=False)
        
        st.write(summary[0]['summary_text'])
        print(summary[0]['summary_text'])
        summary_read = summary[0]['summary_text']  

        st.session_state['history'].append({
            'original text' : text,
            'summary': summary[0]['summary_text'],
            'model': model_name,
            'word_limit': max_length-10,
            
        })

    st.title('Text Summarizer')
    text = st.text_area("Enter Text:", value='', height=None, max_chars=None, key=None)
    max_length = st.slider("Max Length:", min_value=10, max_value=100, step=1)
    model_name = st.selectbox("Choose a model:", list(available_models.keys()))
    model_choice = available_models[model_name] 

    col1, col2, col3, col4, col5 = st.columns([1,1,1,1,1])
    with col1:
        st.write(" ")  
    with col2:
        st.write(" ")  
    with col3:
        like = st.button('πŸ‘')
    with col4:
        dislike = st.button('πŸ‘Ž')
    with col5:
        st.write(" ")  

    if st.button('Summarize'):
        if text:
            max_length = max_length+10
            print(max_length)
            summarize_text(text, max_length, model_choice, model_name)
        else:
            st.write("Please enter text for summarization.")

    for i, item in enumerate(st.session_state['history']):
        st.sidebar.markdown(f'{i+1}.')
        for key, value in item.items():
            st.sidebar.markdown(f'{key}: {value}')

if __name__ == "__main__":
    main()