ar08 commited on
Commit
0dec546
·
verified ·
1 Parent(s): 07dc544

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -1,22 +1,36 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Load the summarizer model
5
- summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-6-6")
 
 
 
 
6
 
7
- # Define the function for Gradio to use
8
  def summarize_article(text):
9
- summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
 
 
 
 
 
10
  return summary[0]['summary_text']
11
 
12
- # Gradio interface
 
 
 
 
 
 
13
  iface = gr.Interface(
14
  fn=summarize_article,
15
- inputs=gr.Textbox(lines=20, label="Enter News Article 📄"),
16
- outputs=gr.Textbox(label="Summary "),
17
- title="Article Summarizer 📰",
18
- description="Paste your article and get a short summary! Powered by facebook/bart-large-cnn."
19
  )
20
 
21
- # Launch the app
22
  iface.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ # Use the pipeline with optimized settings (no sampling, smaller batch)
5
+ summarizer = pipeline(
6
+ "summarization",
7
+ model="sshleifer/distilbart-cnn-6-6",
8
+ # force CPU (if not using GPU)
9
+ )
10
 
11
+ # Function with higher max length and lower min length for longer summaries
12
  def summarize_article(text):
13
+ summary = summarizer(
14
+ text,
15
+ max_length=250, # ✨ allow longer output
16
+ min_length=100, # 🚨 ensure decent length
17
+ do_sample=False, # ⚡ makes it deterministic and faster
18
+ )
19
  return summary[0]['summary_text']
20
 
21
+ # Sample input
22
+ default_article = """New York (CNN)When Liana Barrientos was 23 years old, she got married...""" # [TRIMMED for brevity]
23
+
24
+ # Generate summary once to display as default
25
+ default_summary = summarize_article(default_article)
26
+
27
+ # Gradio interface (read-only)
28
  iface = gr.Interface(
29
  fn=summarize_article,
30
+ inputs=gr.Textbox(lines=20, label="Article (Read Only)", value=default_article, interactive=False),
31
+ outputs=gr.Textbox(label="Summary (Read Only)", value=default_summary, interactive=False),
32
+ title="⚡ Fast Article Summarizer (CPU Optimized)",
33
+ description="Fast summarization with longer output using CPU only. Inputs and outputs are read-only."
34
  )
35
 
 
36
  iface.launch()