Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# 1.
|
| 5 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 6 |
|
| 7 |
@st.cache_resource
|
| 8 |
def load_summarizer():
|
| 9 |
-
|
| 10 |
-
Loads the summarization pipeline from the Hugging Face Hub.
|
| 11 |
-
Using 'subfolder' because the model files are nested in 'summarizer_model'.
|
| 12 |
-
Using 'framework="pt"' to ensure PyTorch is used (avoids Keras 3 errors).
|
| 13 |
-
"""
|
| 14 |
return pipeline(
|
| 15 |
"summarization",
|
| 16 |
model=MODEL_ID,
|
|
@@ -18,46 +14,35 @@ def load_summarizer():
|
|
| 18 |
framework="pt"
|
| 19 |
)
|
| 20 |
|
| 21 |
-
# 2.
|
| 22 |
-
st.set_page_config(page_title="AI
|
|
|
|
|
|
|
| 23 |
st.title("π Automated Text Summarizer")
|
| 24 |
-
st.
|
| 25 |
|
| 26 |
-
#
|
| 27 |
try:
|
| 28 |
summarizer = load_summarizer()
|
| 29 |
-
st.success("
|
| 30 |
except Exception as e:
|
| 31 |
-
st.error(f"
|
| 32 |
st.stop()
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
text_input = st.text_area("Paste your
|
| 36 |
|
| 37 |
-
|
| 38 |
-
if
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
-
|
| 43 |
-
try:
|
| 44 |
-
# Setting max_length to ~80-100 usually results in 2-3 sentences
|
| 45 |
-
summary = summarizer(
|
| 46 |
-
text_input,
|
| 47 |
-
max_length=100,
|
| 48 |
-
min_length=30,
|
| 49 |
-
do_sample=False
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
st.divider()
|
| 53 |
-
st.subheader("Final Summary")
|
| 54 |
-
st.write(summary[0]['summary_text'])
|
| 55 |
-
|
| 56 |
-
# Optional: Add a copy button for the user
|
| 57 |
-
st.button("Copy to Clipboard", on_click=lambda: st.write("Copying functionality requires a custom component, but you can highlight and copy above!"))
|
| 58 |
-
|
| 59 |
-
except Exception as e:
|
| 60 |
-
st.error(f"An error occurred during summarization: {e}")
|
| 61 |
-
|
| 62 |
-
st.divider()
|
| 63 |
-
st.caption("Powered by BART-Large-CNN via Hugging Face Transformers.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# 1. Configuration
|
| 5 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 6 |
|
| 7 |
@st.cache_resource
|
| 8 |
def load_summarizer():
|
| 9 |
+
# Use subfolder because your files are in 'summarizer_model'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
return pipeline(
|
| 11 |
"summarization",
|
| 12 |
model=MODEL_ID,
|
|
|
|
| 14 |
framework="pt"
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# 2. Page Config (MUST be the first Streamlit command)
|
| 18 |
+
st.set_page_config(page_title="AI Summarizer", page_icon="π")
|
| 19 |
+
|
| 20 |
+
# 3. App Title & UI
|
| 21 |
st.title("π Automated Text Summarizer")
|
| 22 |
+
st.write("The model is loading. Please wait a moment...")
|
| 23 |
|
| 24 |
+
# Load the model
|
| 25 |
try:
|
| 26 |
summarizer = load_summarizer()
|
| 27 |
+
st.success("Model Ready!")
|
| 28 |
except Exception as e:
|
| 29 |
+
st.error(f"Waiting for model files... {e}")
|
| 30 |
st.stop()
|
| 31 |
|
| 32 |
+
# 4. Input and Logic
|
| 33 |
+
text_input = st.text_area("Paste your article here:", height=300)
|
| 34 |
|
| 35 |
+
if st.button("Summarize"):
|
| 36 |
+
if text_input.strip():
|
| 37 |
+
with st.spinner("Summarizing..."):
|
| 38 |
+
# length_penalty helps keep the summary concise (2-3 sentences)
|
| 39 |
+
result = summarizer(
|
| 40 |
+
text_input,
|
| 41 |
+
max_length=100,
|
| 42 |
+
min_length=30,
|
| 43 |
+
do_sample=False
|
| 44 |
+
)
|
| 45 |
+
st.subheader("Summary")
|
| 46 |
+
st.write(result[0]['summary_text'])
|
| 47 |
else:
|
| 48 |
+
st.warning("Please enter some text.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|