Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +24 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Initialize summarization pipeline
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
# Function to summarize input
|
| 8 |
+
def summarize_text(text):
|
| 9 |
+
if not text.strip():
|
| 10 |
+
return "⚠️ Please enter some text."
|
| 11 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 12 |
+
return summary
|
| 13 |
+
|
| 14 |
+
# Gradio Interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=summarize_text,
|
| 17 |
+
inputs=gr.Textbox(lines=15, placeholder="Paste article, essay, or book paragraph here..."),
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="📘 AI Text Summarizer",
|
| 20 |
+
description="Summarizes text using Hugging Face's facebook/bart-large-cnn model."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers==4.40.1
|
| 2 |
+
torch
|
| 3 |
+
gradio==5.34.1
|