Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Summarization Model #147

Merged
merged 5 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
yashasvini121 marked this conversation as resolved.
Show resolved Hide resolved
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)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
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
Loading