Spaces:
Sleeping
Sleeping
Update app1.py
Browse files
app1.py
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
# Load summarization pipeline
|
| 5 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
-
|
| 7 |
-
def summarize_text(text, max_length=130, min_length=30):
|
| 8 |
-
"""
|
| 9 |
-
Summarizes the input text.
|
| 10 |
-
"""
|
| 11 |
-
if not text.strip():
|
| 12 |
-
return "Please enter some text to summarize."
|
| 13 |
-
|
| 14 |
-
summary = summarizer(
|
| 15 |
-
text,
|
| 16 |
-
max_length=max_length,
|
| 17 |
-
min_length=min_length,
|
| 18 |
-
do_sample=False
|
| 19 |
-
)[0]["summary_text"]
|
| 20 |
-
|
| 21 |
-
return summary
|
| 22 |
-
|
| 23 |
-
# Gradio Interface
|
| 24 |
-
demo = gr.Interface(
|
| 25 |
-
fn=summarize_text,
|
| 26 |
-
inputs=[
|
| 27 |
-
gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text"),
|
| 28 |
-
gr.Slider(50, 200, value=130, step=10, label="Max Summary Length"),
|
| 29 |
-
gr.Slider(20, 100, value=30, step=5, label="Min Summary Length")
|
| 30 |
-
],
|
| 31 |
-
outputs=gr.Textbox(label="Summary"),
|
| 32 |
-
title="Text Summarization App",
|
| 33 |
-
description="Enter a long piece of text and get a concise summary using BART."
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
if __name__ == "__main__":
|
| 37 |
-
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load summarization pipeline
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
def summarize_text(text, max_length=130, min_length=30):
|
| 8 |
+
"""
|
| 9 |
+
Summarizes the input text.
|
| 10 |
+
"""
|
| 11 |
+
if not text.strip():
|
| 12 |
+
return "Please enter some text to summarize."
|
| 13 |
+
|
| 14 |
+
summary = summarizer(
|
| 15 |
+
text,
|
| 16 |
+
max_length=max_length,
|
| 17 |
+
min_length=min_length,
|
| 18 |
+
do_sample=False
|
| 19 |
+
)[0]["summary_text"]
|
| 20 |
+
|
| 21 |
+
return summary
|
| 22 |
+
|
| 23 |
+
# Gradio Interface
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=summarize_text,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text"),
|
| 28 |
+
gr.Slider(50, 200, value=130, step=10, label="Max Summary Length"),
|
| 29 |
+
gr.Slider(20, 100, value=30, step=5, label="Min Summary Length")
|
| 30 |
+
],
|
| 31 |
+
outputs=gr.Textbox(label="Summary"),
|
| 32 |
+
title="Text Summarization App",
|
| 33 |
+
description="Enter a long piece of text and get a concise summary using BART."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
demo.launch()
|