From 5ff0d17a2fb07653a3f5b9c9bf15b974e069b097 Mon Sep 17 00:00:00 2001 From: Peart-Guy Date: Mon, 14 Oct 2024 22:43:43 +0530 Subject: [PATCH 1/5] Text Summarization Model --- App.py | 13 ++++++++++++ models/text_sumarization/predict.py | 31 +++++++++++++++++++++++++++++ pages/Text Summarizer.py | 31 +++++++++++++++++++++++++++++ requirements.txt | 2 ++ 4 files changed, 77 insertions(+) create mode 100644 models/text_sumarization/predict.py create mode 100644 pages/Text Summarizer.py diff --git a/App.py b/App.py index dd8f9180..cc5ab1aa 100644 --- a/App.py +++ b/App.py @@ -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. + """ + ) \ No newline at end of file diff --git a/models/text_sumarization/predict.py b/models/text_sumarization/predict.py new file mode 100644 index 00000000..70fcae82 --- /dev/null +++ b/models/text_sumarization/predict.py @@ -0,0 +1,31 @@ +import streamlit as st +from transformers import pipeline + +# 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']) diff --git a/pages/Text Summarizer.py b/pages/Text Summarizer.py new file mode 100644 index 00000000..70fcae82 --- /dev/null +++ b/pages/Text Summarizer.py @@ -0,0 +1,31 @@ +import streamlit as st +from transformers import pipeline + +# 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']) diff --git a/requirements.txt b/requirements.txt index d43fe9e5..92f5ad14 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file From 7f86ba29dac2fb2710ff4067559f1f6f4b9f823f Mon Sep 17 00:00:00 2001 From: Yashasvini Sharma <100478608+yashasvini121@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:21:20 +0530 Subject: [PATCH 2/5] Update Text Summarizer.py --- pages/Text Summarizer.py | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/pages/Text Summarizer.py b/pages/Text Summarizer.py index 70fcae82..58a1a502 100644 --- a/pages/Text Summarizer.py +++ b/pages/Text Summarizer.py @@ -1,31 +1,19 @@ import streamlit as st -from transformers import pipeline +from models.text_sumarization.predict import generate_summary -# 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) +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..."): - # 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']) + 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) From 876b138e36ad5445dcb560727db7cb716bfe392b Mon Sep 17 00:00:00 2001 From: Yashasvini Sharma <100478608+yashasvini121@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:22:02 +0530 Subject: [PATCH 3/5] Update predict.py --- models/text_sumarization/predict.py | 36 ++++++++--------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/models/text_sumarization/predict.py b/models/text_sumarization/predict.py index 70fcae82..826801ce 100644 --- a/models/text_sumarization/predict.py +++ b/models/text_sumarization/predict.py @@ -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"] From 3b8b5c3483e2ed3a1d1ad3f0e4e248bbb728243f Mon Sep 17 00:00:00 2001 From: Yashasvini Sharma <100478608+yashasvini121@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:31:11 +0530 Subject: [PATCH 4/5] Update protobuf version from 5.28.2 to 4.25.5 in requirements --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 92f5ad14..79567a5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 @@ -139,4 +139,4 @@ webencodings==0.5.1 websocket-client==1.8.0 xgboost==2.1.1 transformers==4.45.2 -tf_keras==2.17.0 \ No newline at end of file +tf_keras==2.17.0 From cca96b3471b4a9b5e50377f706ec5e6ed73ad6a9 Mon Sep 17 00:00:00 2001 From: Yashasvini Sharma <100478608+yashasvini121@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:42:46 +0530 Subject: [PATCH 5/5] Remove numpy version in requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 79567a5c..ac7563bf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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