VoltIC commited on
Commit
ff5dd8c
·
verified ·
1 Parent(s): a06b0e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -5
app.py CHANGED
@@ -1,14 +1,63 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
4
  MODEL_ID = "VoltIC/Automated-Text-Summarizer"
5
 
6
  @st.cache_resource
7
  def load_summarizer():
8
- # No subfolder needed anymore!
9
- return pipeline("summarization", model=MODEL_ID, framework="pt")
 
 
 
 
 
 
 
 
 
10
 
11
- summarizer = load_summarizer()
 
 
 
12
 
13
- st.title("AI Text Summarizer")
14
- # ... rest of your code ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,
17
+ subfolder="summarizer_model",
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.")