| import gradio as gr |
| from transformers import pipeline |
|
|
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
| def summarize_text(text): |
| word_count = len(text.split()) |
| if word_count < 10: |
| return "Error: The text should have at least 10 words." |
| elif word_count > 100: |
| return "Error: The text should have no more than 100 words." |
| |
| summary = summarizer(text, min_length=10, max_length=100) |
| return summary[0]['summary_text'] |
|
|
| interface = gr.Interface( |
| fn=summarize_text, |
| inputs=gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."), |
| outputs=gr.Textbox(label="Summarized Text"), |
| title="Text Summarizer", |
| description="This app uses the BART model to summarize your text. The input text must be between 10 and 100 words." |
| ) |
|
|
| interface.launch() |
|
|