Summarization / app.py
llmahmad's picture
Update app.py
12392a6 verified
# import os
# os.system('pip install streamlit transformers torch')
# import streamlit as st
# from transformers import BartTokenizer, BartForConditionalGeneration
# # Load the model and tokenizer
# model_name = 'facebook/bart-large-cnn'
# tokenizer = BartTokenizer.from_pretrained(model_name)
# model = BartForConditionalGeneration.from_pretrained(model_name)
# def summarize_text(text):
# inputs = tokenizer(text, return_tensors="pt", truncation=True, padding="longest")
# summary_ids = model.generate(
# inputs["input_ids"],
# max_length=150,
# min_length=30,
# length_penalty=2.0,
# num_beams=4,
# early_stopping=True
# )
# summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
# return summary
# st.title("Text Summarization with Fine-Tuned Model")
# st.write("Enter text to generate a summary using the fine-tuned summarization model.")
# text = st.text_area("Input Text", height=200)
# if st.button("Summarize"):
# if text:
# with st.spinner("Summarizing..."):
# summary = summarize_text(text)
# st.success("Summary Generated")
# st.write(summary)
# else:
# st.warning("Please enter some text to summarize.")
# if __name__ == "__main__":
# st.set_option('deprecation.showfileUploaderEncoding', False)
# st.markdown(
# """
# <style>
# .reportview-container {
# flex-direction: row;
# justify-content: center.
# }
# </style>
# """,
# unsafe_allow_html=True
# )
import os
os.system('pip install streamlit transformers torch')
import streamlit as st
from transformers import pipeline
# Load the summarization pipeline
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
def summarize_text(text):
summary = summarizer(text, max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
return summary[0]['summary_text']
st.title("Text Summarization with Fine-Tuned Model")
st.write("Enter text to generate a summary using the fine-tuned summarization model.")
text = st.text_area("Input Text", height=200)
if st.button("Summarize"):
if text:
with st.spinner("Summarizing..."):
summary = summarize_text(text)
st.success("Summary Generated")
st.write(summary)
else:
st.warning("Please enter some text to summarize.")
if __name__ == "__main__":
st.set_option('deprecation.showfileUploaderEncoding', False)
st.markdown(
"""
<style>
.reportview-container {
flex-direction: row;
justify-content: center.
}
</style>
""",
unsafe_allow_html=True
)