Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the summarization model (it will download automatically)
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
# Define a function that takes text and returns a summary
|
| 8 |
+
def summarize_text(text):
|
| 9 |
+
if len(text.strip()) == 0:
|
| 10 |
+
return "Please enter some text to summarize."
|
| 11 |
+
# Summarize!
|
| 12 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 13 |
+
return summary[0]['summary_text']
|
| 14 |
+
|
| 15 |
+
# Create the Gradio interface
|
| 16 |
+
demo = gr.Interface(
|
| 17 |
+
fn=summarize_text,
|
| 18 |
+
inputs=gr.Textbox(
|
| 19 |
+
placeholder="Enter text here to summarize...",
|
| 20 |
+
lines=8,
|
| 21 |
+
label="Input Text"
|
| 22 |
+
),
|
| 23 |
+
outputs=gr.Textbox(label="Summary"),
|
| 24 |
+
title="📝 AI Text Summarizer",
|
| 25 |
+
description="Paste any article, email, or text and get a concise summary instantly!",
|
| 26 |
+
theme="soft"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Launch the app
|
| 30 |
+
demo.launch()
|