File size: 1,557 Bytes
410a45d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import torch
import gradio as gr
from transformers import pipeline

# Load summarization pipeline
model_id = "sshleifer/distilbart-cnn-12-3"
pipe = pipeline("summarization", model=model_id)

# Define summarization function
def summarize_text_gradio(input_text):
    if not input_text or len(input_text.strip()) < 140:
        return "⚠️ Please enter at least 140 characters to generate a summary."
    summary = pipe(input_text)[0]['summary_text']
    return summary

# Use Gradio Blocks for better layout control
with gr.Blocks(theme="default") as demo:
    gr.Markdown("# πŸ“ Text Summarization Web App AI")
    gr.Markdown(
        """
        This WebPage allows you to summarizes long articles or texts using a pretrained transformer model.
        Enter your text below (minimum 140 characters) and click **Submit** to generate a summary in 3 sec
        """
    )

    with gr.Row():
        input_box = gr.Textbox(label="Input Text", lines=15, placeholder="Paste your long text here...")
    with gr.Row():
        output_box = gr.Textbox(label="🧾 Summary", lines=10)

    summarize_button = gr.Button("πŸ” Summarize")

    summarize_button.click(fn=summarize_text_gradio, inputs=input_box, outputs=output_box)

    # Footer with links at the bottom
    gr.Markdown("---")
    gr.Markdown(
        """
        #### πŸ‘€ Created by Neeraj Sharma  
        πŸ“¬ [LinkedIn](https://www.linkedin.com/in/neeraj-sharma-6017b854/) | πŸ› οΈ [GitHub](https://github.com/MissNeerajSharma)
        """,
        elem_id="footer",
    )

demo.launch()