Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,65 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# Load summarization
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
def summarize_text(text):
|
| 9 |
if not text.strip():
|
| 10 |
-
return "β οΈ
|
| 11 |
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 12 |
return summary
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
title = "π
|
| 16 |
description = """
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
"""
|
| 20 |
|
|
|
|
| 21 |
examples = [
|
| 22 |
-
["India is
|
| 23 |
-
["Climate change
|
| 24 |
-
["
|
| 25 |
]
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
gr.Markdown(f"# {title}")
|
| 29 |
gr.Markdown(description)
|
| 30 |
|
| 31 |
with gr.Row():
|
| 32 |
with gr.Column():
|
| 33 |
input_text = gr.Textbox(
|
| 34 |
-
label="
|
| 35 |
-
placeholder="
|
| 36 |
-
lines=
|
| 37 |
show_copy_button=True
|
| 38 |
)
|
| 39 |
-
submit_btn = gr.Button("
|
| 40 |
with gr.Column():
|
| 41 |
output = gr.Textbox(
|
| 42 |
-
label="
|
| 43 |
lines=12,
|
| 44 |
-
interactive=False
|
|
|
|
| 45 |
)
|
| 46 |
|
|
|
|
| 47 |
submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output)
|
| 48 |
|
|
|
|
| 49 |
gr.Examples(
|
| 50 |
examples=examples,
|
| 51 |
inputs=input_text,
|
| 52 |
outputs=output,
|
| 53 |
fn=summarize_text,
|
| 54 |
-
label="
|
| 55 |
)
|
| 56 |
|
| 57 |
-
#
|
| 58 |
if __name__ == "__main__":
|
| 59 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Load the summarization model from Hugging Face
|
| 5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
+
# Define what the app does when someone enters text
|
| 8 |
def summarize_text(text):
|
| 9 |
if not text.strip():
|
| 10 |
+
return "β οΈ Oops! Looks like you forgot to enter some text."
|
| 11 |
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 12 |
return summary
|
| 13 |
|
| 14 |
+
# Friendly title and helpful description
|
| 15 |
+
title = "π Smart Text Summarizer"
|
| 16 |
description = """
|
| 17 |
+
Tired of reading long paragraphs? Paste any article, essay, or block of text here,
|
| 18 |
+
and this tool will give you a clear, to-the-point summary using AI.
|
| 19 |
+
Great for studying, writing, or just saving time!
|
| 20 |
"""
|
| 21 |
|
| 22 |
+
# Some examples to help users get started
|
| 23 |
examples = [
|
| 24 |
+
["India is known for its cultural diversity, historical landmarks, and varied geography..."],
|
| 25 |
+
["Climate change continues to impact our planet, causing rising temperatures and extreme weather events..."],
|
| 26 |
+
["Artificial Intelligence has evolved over decades, starting from simple rule-based systems to powerful models like GPT..."]
|
| 27 |
]
|
| 28 |
|
| 29 |
+
# Build the interface
|
| 30 |
+
with gr.Blocks(css=".gradio-container {background-color: #f0f4f8;} textarea {font-size: 16px;}") as demo:
|
| 31 |
gr.Markdown(f"# {title}")
|
| 32 |
gr.Markdown(description)
|
| 33 |
|
| 34 |
with gr.Row():
|
| 35 |
with gr.Column():
|
| 36 |
input_text = gr.Textbox(
|
| 37 |
+
label="βοΈ Paste your text here",
|
| 38 |
+
placeholder="Drop in an article, essay, or book paragraph...",
|
| 39 |
+
lines=14,
|
| 40 |
show_copy_button=True
|
| 41 |
)
|
| 42 |
+
submit_btn = gr.Button("πͺ Summarize it!", variant="primary")
|
| 43 |
with gr.Column():
|
| 44 |
output = gr.Textbox(
|
| 45 |
+
label="β
Here's your summary",
|
| 46 |
lines=12,
|
| 47 |
+
interactive=False,
|
| 48 |
+
show_copy_button=True
|
| 49 |
)
|
| 50 |
|
| 51 |
+
# Button action
|
| 52 |
submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output)
|
| 53 |
|
| 54 |
+
# Example use cases
|
| 55 |
gr.Examples(
|
| 56 |
examples=examples,
|
| 57 |
inputs=input_text,
|
| 58 |
outputs=output,
|
| 59 |
fn=summarize_text,
|
| 60 |
+
label="π Try one of these examples"
|
| 61 |
)
|
| 62 |
|
| 63 |
+
# Run the app
|
| 64 |
if __name__ == "__main__":
|
| 65 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|