Skip to content

Commit

Permalink
Add Text Summarization Model
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvini121 authored Oct 19, 2024
2 parents 5c96bbd + cca96b3 commit 246f52a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
13 changes: 13 additions & 0 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,16 @@
- **GLD**: The price of SPDR Gold Shares (GLD), which is the target variable representing gold prices.
"""
)

#Text Summarization Section

st.write(
"- *Text Summarizer*: Save time with concise, professional summaries of lengthy texts—tailored to meet your needs and streamline your reading experience."
)
with st.expander("Text Summarizer - More Information"):
st.subheader("Introduction")
st.write(
"""
Many struggle with summarizing large texts or learning from lengthy materials. This model simplifies the process, offering concise summaries that enhance understanding and speed up learning—perfect for students and professionals alike.
"""
)
13 changes: 13 additions & 0 deletions models/text_sumarization/predict.py
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"]
19 changes: 19 additions & 0 deletions pages/Text Summarizer.py
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)
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ matplotlib-inline==0.1.7
mdurl==0.1.2
mistune==3.0.2
narwhals==1.8.1
numpy==2.1.1
numpy
openpyxl==3.1.5
overrides==7.7.0
packaging==24.1
Expand All @@ -78,7 +78,7 @@ pluggy==1.5.0
prometheus_client==0.20.0
prompt_toolkit==3.0.47
prophet==1.1.6
protobuf==5.28.2
protobuf==4.25.5
psutil==6.0.0
pure_eval==0.2.3
pyarrow==17.0.0
Expand Down Expand Up @@ -138,3 +138,5 @@ webcolors==24.8.0
webencodings==0.5.1
websocket-client==1.8.0
xgboost==2.1.1
transformers==4.45.2
tf_keras==2.17.0

0 comments on commit 246f52a

Please sign in to comment.