|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
|
|
def generate_response_with_summarizer(txt): |
|
try: |
|
|
|
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 |
|
|
|
|
|
st.set_page_config(page_title='π¦π Text Summarization App') |
|
st.title('π¦π Text Summarization App') |
|
|
|
|
|
txt_input = st.text_area('Enter your text', '', height=200) |
|
|
|
|
|
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) |
|
|
|
|
|
if response: |
|
st.info(response) |
|
|
|
|
|
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. |
|
""") |
|
|