Spaces:
Sleeping
Sleeping
| # app.py | |
| from transformers import pipeline | |
| import gradio as gr | |
| # Load the summarization pipeline | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| # Define summarization function | |
| def summarize_text(text): | |
| if not text or len(text.strip()) == 0: | |
| return "⚠️ Please enter some text to summarize." | |
| summary = summarizer( | |
| text, | |
| max_length=130, | |
| min_length=30, | |
| do_sample=False | |
| ) | |
| return summary[0]['summary_text'] | |
| # Gradio Interface | |
| demo = gr.Interface( | |
| fn=summarize_text, | |
| inputs=gr.Textbox( | |
| lines=12, | |
| placeholder="✍️ Paste your article, paragraph, or research text here..." | |
| ), | |
| outputs=gr.Textbox(label="🧠 Generated Summary"), | |
| title="Text Summarizer using Hugging Face 🤗", | |
| description="Enter any paragraph or document, and get a concise summary using the BART model.", | |
| examples=[ | |
| ["The Hugging Face Transformers library provides general-purpose architectures for NLP tasks such as text classification, information extraction, question answering, summarization, translation, and text generation. It allows easy use of pre-trained models and fine-tuning for custom datasets."] | |
| ] | |
| ) | |
| # Launch app | |
| if __name__ == "__main__": | |
| demo.launch() |