VoltIC commited on
Commit
29576a5
Β·
verified Β·
1 Parent(s): d16f3ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -18
app.py CHANGED
@@ -1,12 +1,17 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Your verified Model ID
 
 
 
 
 
5
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
6
 
7
  @st.cache_resource
8
  def load_summarizer():
9
- # This worked in your logs!
10
  return pipeline(
11
  "summarization",
12
  model=MODEL_ID,
@@ -14,20 +19,33 @@ def load_summarizer():
14
  framework="pt"
15
  )
16
 
17
- st.set_page_config(page_title="AI TL;DR", page_icon="πŸ“")
18
- st.title("πŸ“ Automated Text Summarizer")
19
-
20
- # Load the model (The logs prove this is working now!)
21
- summarizer = load_summarizer()
22
-
23
- text_input = st.text_area("Paste long text here:", height=300)
24
 
25
- if st.button("Summarize"):
26
- if text_input.strip():
27
- with st.spinner("AI is thinking..."):
28
- # length_penalty=2.0 helps keep it to 2-3 sentences
29
- summary = summarizer(text_input, max_length=100, min_length=30, length_penalty=2.0)
30
- st.success("Summary Generated!")
31
- st.markdown(f"### Result:\n{summary[0]['summary_text']}")
32
- else:
33
- st.warning("Please enter text first.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # 1. Page Config MUST be first to tell HF the app is "alive"
5
+ st.set_page_config(page_title="AI Summarizer", page_icon="πŸ“")
6
+
7
+ st.title("πŸ“ Automated Text Summarizer")
8
+
9
+ # 2. Configuration
10
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
11
 
12
  @st.cache_resource
13
  def load_summarizer():
14
+ # This function handles the heavy lifting
15
  return pipeline(
16
  "summarization",
17
  model=MODEL_ID,
 
19
  framework="pt"
20
  )
21
 
22
+ # 3. Deferred Loading Logic
23
+ # This allows the UI to render BEFORE the model finishes downloading
24
+ if 'model_ready' not in st.session_state:
25
+ st.session_state.model_ready = False
 
 
 
26
 
27
+ if not st.session_state.model_ready:
28
+ with st.status("πŸ“₯ Downloading AI Model (1.6GB)...", expanded=True) as status:
29
+ st.write("This only happens on the first run. Please wait 2-3 minutes.")
30
+ try:
31
+ summarizer = load_summarizer()
32
+ st.session_state.model_ready = True
33
+ status.update(label="βœ… Model Loaded!", state="complete", expanded=False)
34
+ st.rerun()
35
+ except Exception as e:
36
+ st.error("Model is still transferring from Hub. Refreshing in 30 seconds...")
37
+ st.stop()
38
+ else:
39
+ # 4. The actual interface (only shows once model_ready is True)
40
+ summarizer = load_summarizer()
41
+
42
+ input_text = st.text_area("Paste your article here:", height=300)
43
+
44
+ if st.button("Summarize"):
45
+ if input_text.strip():
46
+ with st.spinner("AI is condensing your text..."):
47
+ summary = summarizer(input_text, max_length=100, min_length=30)
48
+ st.subheader("Summary")
49
+ st.write(summary[0]['summary_text'])
50
+ else:
51
+ st.warning("Please enter text first.")