Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,22 @@ from transformers import pipeline
|
|
| 3 |
|
| 4 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 5 |
|
| 6 |
-
def summarize_text(text
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return summary[0]['summary_text']
|
| 9 |
|
| 10 |
interface = gr.Interface(
|
| 11 |
fn=summarize_text,
|
| 12 |
-
inputs=
|
| 13 |
-
gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."),
|
| 14 |
-
gr.Slider(label="Min Length", minimum=10, maximum=50, step=1, value=10),
|
| 15 |
-
gr.Slider(label="Max Length", minimum=50, maximum=100, step=1, value=100)
|
| 16 |
-
],
|
| 17 |
outputs=gr.Textbox(label="Summarized Text"),
|
| 18 |
title="Text Summarizer",
|
| 19 |
-
description="This app uses the BART model to summarize your text
|
| 20 |
)
|
| 21 |
|
| 22 |
interface.launch()
|
|
|
|
| 3 |
|
| 4 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 5 |
|
| 6 |
+
def summarize_text(text):
|
| 7 |
+
word_count = len(text.split()) # حساب عدد الكلمات
|
| 8 |
+
if word_count < 10:
|
| 9 |
+
return "Error: The text should have at least 10 words."
|
| 10 |
+
elif word_count > 100:
|
| 11 |
+
return "Error: The text should have no more than 100 words."
|
| 12 |
+
|
| 13 |
+
summary = summarizer(text, min_length=10, max_length=100)
|
| 14 |
return summary[0]['summary_text']
|
| 15 |
|
| 16 |
interface = gr.Interface(
|
| 17 |
fn=summarize_text,
|
| 18 |
+
inputs=gr.Textbox(label="Enter Text", lines=10, placeholder="Paste your long text here..."),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
outputs=gr.Textbox(label="Summarized Text"),
|
| 20 |
title="Text Summarizer",
|
| 21 |
+
description="This app uses the BART model to summarize your text. The input text must be between 10 and 100 words."
|
| 22 |
)
|
| 23 |
|
| 24 |
interface.launch()
|