Spaces:
Sleeping
Sleeping
File size: 2,237 Bytes
32a82a5 f6b9930 0a909f3 f6b9930 0a909f3 f6b9930 0a909f3 |
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 47 48 49 50 |
import streamlit as st
import torch
from transformers import pipeline
from transformers import BartTokenizer, BartForConditionalGeneration
# Replace with your Hugging Face model repository path
model_repo_path = 'ASaboor/Bart_samsum'
# Load the model and tokenizer
model = BartForConditionalGeneration.from_pretrained(model_repo_path)
tokenizer = BartTokenizer.from_pretrained(model_repo_path)
# Initialize the summarization pipeline
summarizer = pipeline('summarization', model=model, tokenizer=tokenizer)
# Streamlit app layout
st.set_page_config(page_title="Text Summarization App", page_icon=":memo:", layout="wide")
st.title("Text Summarization App")
st.write("""
This app uses a fine-tuned BART model to generate summaries of your input text.
Enter the text you want to summarize in the box below and click "Summarize" to see the result.
""")
# Main layout
placeholder_text = ("It has been shown that vehicles contribute significantly to pollution levels and have a considerable impact on respiratory health, "
"particularly for those aged over fifty. Factories have also been shown to be significant contributors, with those living closest to "
"unfiltered petrochemical factories being the most at risk. Finally, one uncommonly considered polluter was also explored. This was the use "
"of volatile organic compounds (VOCs) in commercial paints which have a tendency to negatively affect the health of people in their own homes.")
# User input
st.subheader("Input Text")
text_input = st.text_area("Enter text to summarize", height=300, placeholder=placeholder_text)
# Summarize the text
if st.button("Summarize"):
if text_input:
with st.spinner("Generating summary..."):
try:
# Generate summary
summary = summarizer(text_input, max_length=150, min_length=30, do_sample=False)
# Display summary
st.subheader("Summary")
st.write(summary[0]['summary_text'])
except Exception as e:
st.error(f"An error occurred during summarization: {e}")
else:
st.warning("Please enter some text to summarize.")
|