-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f86ba2
commit 876b138
Showing
1 changed file
with
9 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,13 @@ | ||
import streamlit as st | ||
from transformers import pipeline | ||
import streamlit as st | ||
|
||
# Title of the web app | ||
st.title("Text Summarization Tool") | ||
|
||
# Load the summarization model | ||
@st.cache_resource(show_spinner=True) # Cache the model loading for faster performance | ||
def load_summarizer(): | ||
return pipeline("summarization", model="t5-small") | ||
|
||
summarizer = load_summarizer() | ||
|
||
# Instructions for users | ||
st.write("Enter the text you'd like to summarize (minimum 50 words).") | ||
|
||
# Create a text area for the user to input text | ||
user_input = st.text_area("Input Text", height=200) | ||
|
||
# A button to initiate the summarization process | ||
if st.button("Summarize"): | ||
if len(user_input.split()) < 50: | ||
st.warning("Please enter at least 50 words for summarization.") | ||
else: | ||
# Show a spinner while the summarization is being processed | ||
with st.spinner("Summarizing..."): | ||
# Generate the summary | ||
summary = summarizer(user_input, max_length=150, min_length=30, do_sample=False) | ||
# Display the summarized text | ||
st.subheader("Summary:") | ||
st.write(summary[0]['summary_text']) | ||
"""Load and cache the text summarization pipeline model.""" | ||
return pipeline("summarization", model="t5-small") | ||
|
||
def generate_summary(text: str) -> str: | ||
"""Generate a summary for the given input text.""" | ||
summarizer = load_summarizer() | ||
summary = summarizer(text, max_length=150, min_length=30, do_sample=False) | ||
return summary[0]["summary_text"] |