Spaces:
Sleeping
Sleeping
File size: 2,347 Bytes
83bfdc3 6a366d4 83bfdc3 6a366d4 83bfdc3 6a366d4 83bfdc3 6a366d4 538f034 6a366d4 538f034 83bfdc3 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 538f034 6a366d4 83bfdc3 538f034 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 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)
|