| import torch |
| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| model_id = "sshleifer/distilbart-cnn-12-3" |
| pipe = pipeline("summarization", model=model_id) |
|
|
| |
| 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 |
|
|
| |
| 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) |
|
|
| |
| 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() |
|
|