Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load summarization pipeline | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| def summarize_text(text, max_length=130, min_length=30): | |
| """ | |
| Summarizes the input text. | |
| """ | |
| if not text.strip(): | |
| return "Please enter some text to summarize." | |
| summary = summarizer( | |
| text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| do_sample=False | |
| )[0]["summary_text"] | |
| return summary | |
| # Gradio Interface | |
| demo = gr.Interface( | |
| fn=summarize_text, | |
| inputs=[ | |
| gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text"), | |
| gr.Slider(50, 200, value=130, step=10, label="Max Summary Length"), | |
| gr.Slider(20, 100, value=30, step=5, label="Min Summary Length") | |
| ], | |
| outputs=gr.Textbox(label="Summary"), | |
| title="Text Summarization App", | |
| description="Enter a long piece of text and get a concise summary using BART." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |