Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,34 +4,26 @@ import torch
|
|
| 4 |
import requests
|
| 5 |
from PIL import Image
|
| 6 |
from io import BytesIO
|
| 7 |
-
# Import necessary libraries
|
| 8 |
from transformers import pipeline
|
| 9 |
import torch
|
| 10 |
|
| 11 |
-
# Load the BART model for summarization using Hugging Face's pipeline
|
| 12 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 13 |
|
| 14 |
-
# Prediction function
|
| 15 |
def summarize_text(input_text):
|
| 16 |
-
|
| 17 |
if not input_text.strip():
|
| 18 |
return {"Error": "Please input some text"}
|
| 19 |
-
|
| 20 |
-
# Use the summarizer to generate the summary
|
| 21 |
summary = summarizer(input_text, max_length=150, min_length=50, do_sample=False)
|
| 22 |
-
|
| 23 |
-
return summary[0]['summary_text']
|
| 24 |
|
| 25 |
-
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=summarize_text,
|
| 28 |
inputs=gr.Textbox(label="Enter Text to Summarize", lines=5),
|
| 29 |
outputs=gr.Label(label="Summary"),
|
| 30 |
-
title="Text
|
| 31 |
description="This app uses the `facebook/bart-large-cnn` model to summarize the text you input.",
|
| 32 |
allow_flagging="never"
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
demo.launch()
|
| 37 |
-
|
|
|
|
| 4 |
import requests
|
| 5 |
from PIL import Image
|
| 6 |
from io import BytesIO
|
|
|
|
| 7 |
from transformers import pipeline
|
| 8 |
import torch
|
| 9 |
|
|
|
|
| 10 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 11 |
|
|
|
|
| 12 |
def summarize_text(input_text):
|
| 13 |
+
|
| 14 |
if not input_text.strip():
|
| 15 |
return {"Error": "Please input some text"}
|
| 16 |
+
|
|
|
|
| 17 |
summary = summarizer(input_text, max_length=150, min_length=50, do_sample=False)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
return summary[0]['summary_text']
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=summarize_text,
|
| 22 |
inputs=gr.Textbox(label="Enter Text to Summarize", lines=5),
|
| 23 |
outputs=gr.Label(label="Summary"),
|
| 24 |
+
title="Text Summarization",
|
| 25 |
description="This app uses the `facebook/bart-large-cnn` model to summarize the text you input.",
|
| 26 |
allow_flagging="never"
|
| 27 |
)
|
| 28 |
|
| 29 |
+
demo.launch()
|
|
|
|
|
|