Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,34 @@
|
|
| 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 |
-
|
| 11 |
-
|
| 12 |
-
# Adding subfolder ensures we target the right directory
|
| 13 |
-
return pipeline(
|
| 14 |
-
"summarization",
|
| 15 |
-
model=MODEL_ID,
|
| 16 |
-
subfolder="summarizer_model",
|
| 17 |
-
framework="pt"
|
| 18 |
-
)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
st.title("π
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
# This check ensures the UI only tries to render when the environment is ready
|
| 27 |
try:
|
| 28 |
-
with st.
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
status.update(label="β
AI Engine Ready!", state="complete", expanded=False)
|
| 32 |
except Exception as e:
|
| 33 |
-
st.
|
| 34 |
st.stop()
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
input_text = st.text_area("Paste
|
| 38 |
-
|
| 39 |
if st.button("Summarize"):
|
| 40 |
-
if input_text
|
| 41 |
-
with st.spinner("
|
| 42 |
-
|
| 43 |
st.subheader("Summary")
|
| 44 |
-
st.write(
|
| 45 |
-
else:
|
| 46 |
-
st.warning("Please provide some text to summarize.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# 1. Config
|
| 5 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 6 |
|
| 7 |
+
# 2. Page Config (Must be first)
|
| 8 |
+
st.set_page_config(page_title="AI Summarizer", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# 3. Cached Loader
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def load_model():
|
| 13 |
+
# We use the subfolder since that's where your files are
|
| 14 |
+
return pipeline("summarization", model=MODEL_ID, subfolder="summarizer_model", framework="pt")
|
| 15 |
|
| 16 |
+
st.title("π Automated Text Summarizer")
|
| 17 |
|
| 18 |
+
# 4. Error-Resistant Loading
|
|
|
|
| 19 |
try:
|
| 20 |
+
with st.spinner("Downloading AI Model (1.6GB)... This may take 3-5 minutes on first run."):
|
| 21 |
+
summarizer = load_model()
|
| 22 |
+
st.success("AI Model Loaded!")
|
|
|
|
| 23 |
except Exception as e:
|
| 24 |
+
st.warning("The model is still downloading in the background. Please wait 2 minutes and refresh.")
|
| 25 |
st.stop()
|
| 26 |
|
| 27 |
+
# 5. UI
|
| 28 |
+
input_text = st.text_area("Paste text here:", height=250)
|
|
|
|
| 29 |
if st.button("Summarize"):
|
| 30 |
+
if input_text:
|
| 31 |
+
with st.spinner("Summarizing..."):
|
| 32 |
+
output = summarizer(input_text, max_length=100, min_length=30, do_sample=False)
|
| 33 |
st.subheader("Summary")
|
| 34 |
+
st.write(output[0]['summary_text'])
|
|
|
|
|
|