from transformers import pipeline import gradio as gr # Load the summarization model from Hugging Face summarizer = pipeline("summarization", model="facebook/bart-large-cnn") # Define what the app does when someone enters text def summarize_text(text): if not text.strip(): return "⚠️ Oops! Looks like you forgot to enter some text." summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text'] return summary # Friendly title and helpful description title = "📘 Smart Text Summarizer" description = """ Tired of reading long paragraphs? Paste any article, essay, or block of text here, and this tool will give you a clear, to-the-point summary using AI. Great for studying, writing, or just saving time! """ # Some examples to help users get started examples = [ ["India is known for its cultural diversity, historical landmarks, and varied geography..."], ["Climate change continues to impact our planet, causing rising temperatures and extreme weather events..."], ["Artificial Intelligence has evolved over decades, starting from simple rule-based systems to powerful models like GPT..."] ] # Build the interface with gr.Blocks(css=".gradio-container {background-color: #f0f4f8;} textarea {font-size: 16px;}") as demo: gr.Markdown(f"# {title}") gr.Markdown(description) with gr.Row(): with gr.Column(): input_text = gr.Textbox( label="✍️ Paste your text here", placeholder="Drop in an article, essay, or book paragraph...", lines=14, show_copy_button=True ) submit_btn = gr.Button("🪄 Summarize it!", variant="primary") with gr.Column(): output = gr.Textbox( label="✅ Here's your summary", lines=12, interactive=False, show_copy_button=True ) # Button action submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output) # Example use cases gr.Examples( examples=examples, inputs=input_text, outputs=output, fn=summarize_text, label="🔍 Try one of these examples" ) # Run the app if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860)