MsNeeraj commited on
Commit
410a45d
Β·
verified Β·
1 Parent(s): be1021a
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ # Load summarization pipeline
6
+ model_id = "sshleifer/distilbart-cnn-12-3"
7
+ pipe = pipeline("summarization", model=model_id)
8
+
9
+ # Define summarization function
10
+ def summarize_text_gradio(input_text):
11
+ if not input_text or len(input_text.strip()) < 140:
12
+ return "⚠️ Please enter at least 140 characters to generate a summary."
13
+ summary = pipe(input_text)[0]['summary_text']
14
+ return summary
15
+
16
+ # Use Gradio Blocks for better layout control
17
+ with gr.Blocks(theme="default") as demo:
18
+ gr.Markdown("# πŸ“ Text Summarization Web App AI")
19
+ gr.Markdown(
20
+ """
21
+ This WebPage allows you to summarizes long articles or texts using a pretrained transformer model.
22
+ Enter your text below (minimum 140 characters) and click **Submit** to generate a summary in 3 sec
23
+ """
24
+ )
25
+
26
+ with gr.Row():
27
+ input_box = gr.Textbox(label="Input Text", lines=15, placeholder="Paste your long text here...")
28
+ with gr.Row():
29
+ output_box = gr.Textbox(label="🧾 Summary", lines=10)
30
+
31
+ summarize_button = gr.Button("πŸ” Summarize")
32
+
33
+ summarize_button.click(fn=summarize_text_gradio, inputs=input_box, outputs=output_box)
34
+
35
+ # Footer with links at the bottom
36
+ gr.Markdown("---")
37
+ gr.Markdown(
38
+ """
39
+ #### πŸ‘€ Created by Neeraj Sharma
40
+ πŸ“¬ [LinkedIn](https://www.linkedin.com/in/neeraj-sharma-6017b854/) | πŸ› οΈ [GitHub](https://github.com/MissNeerajSharma)
41
+ """,
42
+ elem_id="footer",
43
+ )
44
+
45
+ demo.launch()