-
Notifications
You must be signed in to change notification settings - Fork 72
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
Showing
4 changed files
with
49 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from transformers import pipeline | ||
import streamlit as st | ||
|
||
@st.cache_resource(show_spinner=True) # Cache the model loading for faster performance | ||
def load_summarizer(): | ||
"""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"] |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import streamlit as st | ||
from models.text_sumarization.predict import generate_summary | ||
|
||
st.title("Text Summarization Tool") | ||
|
||
st.write("Enter the text you'd like to summarize (minimum 50 words).") | ||
|
||
user_input = st.text_area("Input Text", height=250) | ||
|
||
# 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..."): | ||
summary = generate_summary(user_input) # Call the function from predict.py | ||
st.subheader("Summary:") | ||
st.code(summary, language="text", wrap_lines=True) |
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