VoltIC commited on
Commit
29d500e
Β·
verified Β·
1 Parent(s): 153c1bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -32
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
- @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,
16
- subfolder="summarizer_model",
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.")
 
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'])