|
import streamlit as st |
|
import torch |
|
from transformers import pipeline |
|
from transformers import BartTokenizer, BartForConditionalGeneration |
|
|
|
|
|
model_repo_path = 'ASaboor/Bart_samsum' |
|
|
|
|
|
model = BartForConditionalGeneration.from_pretrained(model_repo_path) |
|
tokenizer = BartTokenizer.from_pretrained(model_repo_path) |
|
|
|
|
|
summarizer = pipeline('summarization', model=model, tokenizer=tokenizer) |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
text_input = st.text_area("Enter text to summarize", height=300, placeholder="Paste your text here...") |
|
|
|
|
|
if st.button("Summarize"): |
|
if text_input: |
|
with st.spinner("Generating summary..."): |
|
try: |
|
|
|
summary = summarizer(text_input, max_length=150, min_length=30, do_sample=False) |
|
|
|
|
|
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.") |
|
|
|
|
|
st.markdown(""" |
|
--- |
|
Made with ❤️ using [Streamlit](https://streamlit.io) and [Hugging Face Transformers](https://huggingface.co/transformers/). |
|
""") |
|
|