Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
3 |
+
|
4 |
+
model_name = "facebook/bart-large-cnn"
|
5 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
6 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def summarize_text(text):
|
9 |
+
inputs = tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
|
10 |
+
summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=128, early_stopping=True)
|
11 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
12 |
+
return summary
|
13 |
+
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=summarize_text,
|
16 |
+
inputs="text",
|
17 |
+
outputs="text",
|
18 |
+
title="BART Summarizer",
|
19 |
+
description="Enter text to get a summary using Facebook BART."
|
20 |
+
)
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|