File size: 1,268 Bytes
c71b2e8
8fff906
b17a76b
526d29a
8fff906
 
b17a76b
8fff906
 
 
 
526d29a
35d8013
526d29a
 
 
8fff906
526d29a
 
 
7f33eef
526d29a
c71b2e8
526d29a
 
 
 
 
 
 
c71b2e8
526d29a
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

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

def generate_summary(text):
    inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
    summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    return summary

def save_to_history(input_text, summary_text):
    with open("history.txt", "a") as file:
        file.write(f"Input: {input_text}\nSummary: {summary_text}\n\n")

# Streamlit app
st.set_page_config(page_title='Text Summarization App')
st.title('Text Summarization App')

txt_input = st.text_area('Enter your text', '', height=200)

if st.button('Generate Summary'):
    if txt_input:
        with st.spinner('Generating summary...'):
            summary = generate_summary(txt_input)
            save_to_history(txt_input, summary)
            st.subheader('Generated Summary:')
            st.write(summary)
    else:
        st.warning('Please enter some text to summarize.')