ghostai1 commited on
Commit
afe9c02
·
verified ·
1 Parent(s): bcf90bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 📝 Text Summarization Demo | CPU-only HF Space
2
+
3
+ from transformers import pipeline
4
+ import gradio as gr
5
+
6
+ # Load a distilled BART summarization model on CPU
7
+ summarizer = pipeline(
8
+ "summarization",
9
+ model="sshleifer/distilbart-cnn-12-6",
10
+ device=-1 # force CPU
11
+ )
12
+
13
+ def summarize(text: str, max_length: int, min_length: int):
14
+ if not text.strip():
15
+ return ""
16
+ # run the summarization pipeline
17
+ summary = summarizer(
18
+ text,
19
+ max_length=max_length,
20
+ min_length=min_length,
21
+ do_sample=False
22
+ )[0]["summary_text"]
23
+ return summary
24
+
25
+ with gr.Blocks(title="📝 Text Summarization") as demo:
26
+ gr.Markdown(
27
+ "# 📝 Text Summarizer\n"
28
+ "Paste in any article, report, or long-form text and get a concise summary—**100% CPU**."
29
+ )
30
+
31
+ with gr.Row():
32
+ text_in = gr.Textbox(lines=10, placeholder="Enter your text here…", label="Input Text")
33
+ max_slider = gr.Slider(20, 200, value=100, step=10, label="Max Summary Length")
34
+ min_slider = gr.Slider(10, 100, value=30, step=5, label="Min Summary Length")
35
+
36
+ run_btn = gr.Button("Summarize 🔍", variant="primary")
37
+ summary_out = gr.Textbox(lines=5, label="Summary", interactive=False)
38
+
39
+ run_btn.click(
40
+ summarize,
41
+ inputs=[text_in, max_slider, min_slider],
42
+ outputs=summary_out
43
+ )
44
+
45
+ if __name__ == "__main__":
46
+ demo.launch(server_name="0.0.0.0")