Spaces:
Sleeping
Sleeping
Commit
•
01e9bc7
1
Parent(s):
8ba4c77
base code
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import BartForConditionalGeneration, BartTokenizer, pipeline
|
4 |
+
|
5 |
+
# Load the model and tokenizer using the authentication token
|
6 |
+
model = BartForConditionalGeneration.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
7 |
+
tokenizer = BartTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
8 |
+
|
9 |
+
# Create the summarization pipeline with the loaded model and tokenizer
|
10 |
+
get_completion = pipeline("summarization", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
def summarize(input):
|
13 |
+
output = get_completion(input)
|
14 |
+
return output[0]['summary_text']
|
15 |
+
|
16 |
+
demo = gr.Interface(fn=summarize,
|
17 |
+
inputs=[gr.Textbox(label="Text to summarize", lines=6)],
|
18 |
+
outputs=[gr.Textbox(label="Result", lines=3)],
|
19 |
+
title="Text summarization with distilbart-cnn",
|
20 |
+
description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
|
21 |
+
)
|
22 |
+
|
23 |
+
demo.launch(inline=False)
|