VoltIC commited on
Commit
33602b7
Β·
verified Β·
1 Parent(s): ff5dd8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -40
app.py CHANGED
@@ -1,16 +1,12 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # 1. Your Model Configuration
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. UI Setup
22
- st.set_page_config(page_title="AI TL;DR Tool", page_icon="πŸ“")
 
 
23
  st.title("πŸ“ Automated Text Summarizer")
24
- st.markdown("Generate a concise 2-3 sentence summary of any long article or legal document.")
25
 
26
- # Initialize the model
27
  try:
28
  summarizer = load_summarizer()
29
- st.success("βœ… Model loaded successfully!")
30
  except Exception as e:
31
- st.error(f"❌ Error loading model: {e}")
32
  st.stop()
33
 
34
- # 3. Input Area
35
- text_input = st.text_area("Paste your text here (News, Research, Legal, etc.):", height=300)
36
 
37
- # 4. Summarization Logic
38
- if st.button("Generate Summary"):
39
- if len(text_input.strip()) < 50:
40
- st.warning("Please enter a longer text (at least 50 characters) to summarize.")
 
 
 
 
 
 
 
 
41
  else:
42
- with st.spinner("🧠 AI is reading and condensing..."):
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.")