Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import streamlit as st | |
| # Load pre-trained BART model for summarization | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| # Summarization function | |
| def summarize_text(text, max_length=150): | |
| """ | |
| Summarizes the given text using the pre-trained BART model. | |
| Args: | |
| - text (str): The input text to be summarized. | |
| - max_length (int): Maximum length of the summary. | |
| Returns: | |
| - summary_text (str): The summarized text. | |
| """ | |
| summary = summarizer(text, max_length=max_length, min_length=50, do_sample=False) | |
| return summary[0]['summary_text'] | |
| # Streamlit UI | |
| def run_streamlit_app(): | |
| """ | |
| This function runs the Streamlit app for text summarization. | |
| """ | |
| st.title("Text Summarizer") | |
| st.write("Enter your article and document below to get a summary.") | |
| # Text input field for user | |
| input_text = st.text_area("Enter the Text", height=220) | |
| # Button to generate summary | |
| if st.button("Summarize"): | |
| if input_text.strip(): | |
| with st.spinner('Summarizing...'): | |
| summary = summarize_text(input_text) | |
| st.subheader("Summary:") | |
| st.write(summary) | |
| else: | |
| st.warning("Please enter some text to summarize.") | |
| # If this script is being run locally or in an environment where Streamlit is supported, | |
| # this block will start the Streamlit app | |
| if __name__ == "__main__": | |
| run_streamlit_app() | |