File size: 2,208 Bytes
c71b2e8
8fff906
b17a76b
8844977
8fff906
 
b17a76b
61d2cd7
861222f
 
61d2cd7
861222f
 
61d2cd7
861222f
 
61d2cd7
861222f
 
 
4ac653d
8844977
 
 
7f33eef
8844977
61d2cd7
c71b2e8
af41dd6
4ac653d
8844977
61d2cd7
 
 
 
8844977
61d2cd7
 
 
 
 
861222f
61d2cd7
c71b2e8
61d2cd7
8844977
61d2cd7
8844977
 
 
af41dd6
61d2cd7
8844977
 
 
61d2cd7
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")

def summarize_text(text):
    try:
        # Tokenize input with truncation to fit model requirements
        inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
        
        # Generate summary
        summary_ids = model.generate(inputs['input_ids'], max_length=150, num_beams=4, early_stopping=True)
        summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
        
        return summary
    except Exception as e:
        st.error(f"An error occurred: {e}")
        return ""

# Initialize session state for input history if it doesn't exist
if 'input_history' not in st.session_state:
    st.session_state['input_history'] = []

# Streamlit interface
st.title("Text Summarizer")

# User text inputs
bulk_text = st.text_area("Enter the bulk text (e.g., client calls, meeting transcripts)", height=300)

if st.button("Summarize Text"):
    if bulk_text:
        with st.spinner("Generating summary..."):
            summary = summarize_text(bulk_text)
            
            if summary:
                # Save the input and summary to the session state history
                st.session_state['input_history'].append({"text": bulk_text, "summary": summary})
                st.subheader("Summary:")
                st.write(summary)
            else:
                st.warning("No summary was generated. Please check the input and try again.")
    else:
        st.warning("Please enter the bulk text.")

# Display the history of inputs and summaries
if st.session_state['input_history']:
    st.subheader("History")
    for i, entry in enumerate(st.session_state['input_history']):
        st.write(f"**Input {i+1} (Text):** {entry['text']}")
        st.write(f"**Summary {i+1}:** {entry['summary']}")
        st.write("---")

# Instructions for using the app
st.write("Enter your bulk text and click 'Summarize Text' to get a summary of the text.")