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.')