File size: 1,442 Bytes
5e2e02c
af547e1
5e2e02c
af547e1
 
5e2e02c
af547e1
 
 
 
 
 
5e2e02c
 
 
 
267005e
af547e1
 
5e2e02c
267005e
5e2e02c
 
267005e
5e2e02c
 
 
9f29f51
af547e1
 
5e2e02c
267005e
5e2e02c
 
 
af547e1
 
5e2e02c
af547e1
 
5e2e02c
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
import streamlit as st
from transformers import pipeline

# Initialize summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# Function to generate response using the summarizer
def generate_response_with_summarizer(txt):
    try:
        # Generate summary
        summary = summarizer(txt, max_length=130, min_length=30, do_sample=False)
        return summary[0]['summary_text']
    except Exception as e:
        st.error(f"An error occurred during summarization: {str(e)}")
        return None

# Page title and layout
st.set_page_config(page_title='πŸ¦œπŸ”— Text Summarization App')
st.title('πŸ¦œπŸ”— Text Summarization App')

# Text input area for user to input text
txt_input = st.text_area('Enter your text', '', height=200)

# Form to accept the user's text input for summarization
response = None
with st.form('summarize_form', clear_on_submit=True):
    submitted = st.form_submit_button('Submit')
    if submitted and txt_input:
        with st.spinner('Summarizing...'):
            response = generate_response_with_summarizer(txt_input)

# Display the response if available
if response:
    st.info(response)

# Instructions for using the summarization app
st.subheader("Hugging Face Summarization")
st.write("""
This app uses Hugging Face's `facebook/bart-large-cnn` model to summarize input text.
The model provides concise summaries by capturing the main points of the text.
""")