diff --git a/.github/workflows/validate-pr.yaml b/.github/workflows/validate-pr.yaml index c5f6f0d0..885586f5 100644 --- a/.github/workflows/validate-pr.yaml +++ b/.github/workflows/validate-pr.yaml @@ -44,7 +44,7 @@ jobs: - name: Test Streamlit App run: | pip install streamlit - streamlit run app.py --server.headless true --browser.gatherUsageStats false & + streamlit run App.py --server.headless true --browser.gatherUsageStats false & sleep 10 # Wait for the app to start curl --retry 5 --retry-delay 5 http://localhost:8501 env: diff --git a/App.py b/App.py index 96c85563..c55aeb24 100644 --- a/App.py +++ b/App.py @@ -111,7 +111,6 @@ """ ) - #Insurance Cost Predictor with st.expander("Insurance Cost Predictor - More Information"): st.subheader("Introduction") @@ -142,3 +141,15 @@ - **Charges**: The insurance cost (the target variable to be predicted). """ ) +#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. + """ + ) diff --git a/models/text_sumarization/predict.py b/models/text_sumarization/predict.py new file mode 100644 index 00000000..826801ce --- /dev/null +++ b/models/text_sumarization/predict.py @@ -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"] diff --git a/pages/Text Summarizer.py b/pages/Text Summarizer.py new file mode 100644 index 00000000..58a1a502 --- /dev/null +++ b/pages/Text Summarizer.py @@ -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) diff --git a/requirements.txt b/requirements.txt index d43fe9e5..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 @@ -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 @@ -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