Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the summarization pipeline
|
5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
+
|
7 |
+
# Define the summarization function
|
8 |
+
def summarize_text(input_text):
|
9 |
+
if not input_text.strip():
|
10 |
+
return "Please provide some text to summarize."
|
11 |
+
try:
|
12 |
+
summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
|
13 |
+
return summary[0]["summary_text"]
|
14 |
+
except Exception as e:
|
15 |
+
return f"Error: {str(e)}"
|
16 |
+
|
17 |
+
# Create the Gradio interface
|
18 |
+
demo = gr.Interface(
|
19 |
+
fn=summarize_text,
|
20 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
21 |
+
outputs=gr.Textbox(label="Summarized Text"),
|
22 |
+
title="Text Summarizer",
|
23 |
+
description="Summarize long articles or paragraphs using the `facebook/bart-large-cnn` model."
|
24 |
+
)
|
25 |
+
|
26 |
+
# Launch the app
|
27 |
+
if __name__ == "__main__":
|
28 |
+
demo.launch()
|