File size: 1,509 Bytes
39b8e7a
 
 
 
fea6bf0
39b8e7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
from transformers import pipeline
import streamlit as st

# Load pre-trained BART model for summarization
summarizer = pipeline("summarization", model="ranwakhaled/fine-tuned-T5-for-Arabic-summarization")

# 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()