import streamlit as st from transformers import AutoModelForSeq2SeqLM, AutoTokenizer # Load pre-trained model and tokenizer tokenizer = AutoTokenizer.from_pretrained("avisena/bart-base-job-info-summarizer") model = AutoModelForSeq2SeqLM.from_pretrained("avisena/bart-base-job-info-summarizer") # Streamlit app st.title("Text Summarization App") # Text input text_input = st.text_area("Enter the text to summarize:", height=200) # Summarize button if st.button("Summarize"): if text_input: # Tokenize input text inputs = tokenizer.encode(text_input, return_tensors="pt", max_length=1024, truncation='do_not_truncate') # Generate summary summary_ids = model.generate( inputs, max_length=200, # Maximum length of the summary min_length=30, # Minimum length of the summary length_penalty=0.98, # Penalty for longer sequences num_beams=6, # Number of beams for beam search top_p=3.7, early_stopping=True, temperature=1.4, do_sample=True ) # Decode summary summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, max_length=512, truncation='do_not_truncate') # Display the summarized text st.subheader("Summary") st.write(summary) else: st.warning("Please enter some text to summarize.")