Chetan Ganatra
Apply app.py
f1eb948
import streamlit as st
from transformers import BartForConditionalGeneration, BartTokenizer
# Load the pre-trained model and tokenizer for BART-large-CNN
model_name = "facebook/bart-large-cnn"
model = BartForConditionalGeneration.from_pretrained(model_name)
tokenizer = BartTokenizer.from_pretrained(model_name)
# Set up the Streamlit app
st.title("Text Summarization with BART-large-CNN")
st.write("Enter text below and get a summary using Hugging Face's BART model!")
# Input Text Box
input_text = st.text_area("Enter text to summarize:", height=200)
# Summarization
if input_text:
# Tokenize the input text
inputs = tokenizer(input_text, return_tensors="pt", max_length=1024, truncation=True)
# Generate the summary
summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=200, early_stopping=True)
# Decode the summary back into text
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
# Display the summary
st.subheader("Summary:")
st.write(summary)