Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
| 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 |
-
#
|
| 10 |
return pipeline(
|
| 11 |
"summarization",
|
| 12 |
model=MODEL_ID,
|
|
@@ -14,35 +17,30 @@ def load_summarizer():
|
|
| 14 |
framework="pt"
|
| 15 |
)
|
| 16 |
|
| 17 |
-
# 2. Page
|
| 18 |
st.set_page_config(page_title="AI Summarizer", page_icon="π")
|
| 19 |
|
| 20 |
-
|
| 21 |
-
st.title("π Automated Text Summarizer")
|
| 22 |
-
st.write("The model is loading. Please wait a moment...")
|
| 23 |
|
| 24 |
-
#
|
|
|
|
| 25 |
try:
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
-
st.
|
| 30 |
st.stop()
|
| 31 |
|
| 32 |
-
# 4.
|
| 33 |
-
|
| 34 |
|
| 35 |
if st.button("Summarize"):
|
| 36 |
-
if
|
| 37 |
-
with st.spinner("
|
| 38 |
-
|
| 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(
|
| 47 |
else:
|
| 48 |
-
st.warning("Please
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# 1. Silencing TensorFlow & Streamlit startup "noise"
|
| 6 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 7 |
|
|
|
|
| 8 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 9 |
|
| 10 |
@st.cache_resource
|
| 11 |
def load_summarizer():
|
| 12 |
+
# Adding subfolder ensures we target the right directory
|
| 13 |
return pipeline(
|
| 14 |
"summarization",
|
| 15 |
model=MODEL_ID,
|
|
|
|
| 17 |
framework="pt"
|
| 18 |
)
|
| 19 |
|
| 20 |
+
# 2. Page Configuration
|
| 21 |
st.set_page_config(page_title="AI Summarizer", page_icon="π")
|
| 22 |
|
| 23 |
+
st.title("π AI Text Summarizer")
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# 3. Handling the "Bare Mode" Startup
|
| 26 |
+
# This check ensures the UI only tries to render when the environment is ready
|
| 27 |
try:
|
| 28 |
+
with st.status("π Initializing AI Engine...", expanded=True) as status:
|
| 29 |
+
st.write("Downloading model weights (1.6GB)...")
|
| 30 |
+
summarizer = load_summarizer()
|
| 31 |
+
status.update(label="β
AI Engine Ready!", state="complete", expanded=False)
|
| 32 |
except Exception as e:
|
| 33 |
+
st.info("The app is currently warming up. Please refresh in 1 minute.")
|
| 34 |
st.stop()
|
| 35 |
|
| 36 |
+
# 4. Main App Interface
|
| 37 |
+
input_text = st.text_area("Paste your article or document below:", height=300)
|
| 38 |
|
| 39 |
if st.button("Summarize"):
|
| 40 |
+
if input_text.strip():
|
| 41 |
+
with st.spinner("Processing..."):
|
| 42 |
+
summary = summarizer(input_text, max_length=100, min_length=30)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
st.subheader("Summary")
|
| 44 |
+
st.write(summary[0]['summary_text'])
|
| 45 |
else:
|
| 46 |
+
st.warning("Please provide some text to summarize.")
|