Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,25 @@
|
|
1 |
-
|
|
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
#
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
3 |
import gradio as gr
|
4 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead, TranslationPipeline
|
5 |
+
|
6 |
+
model = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")
|
7 |
+
tokenizer = BartTokenizer.from_pretrained("facebook/bart-large-cnn")
|
8 |
+
|
9 |
+
def article_summarization(translated_text):
|
10 |
+
input_ = str(text) + ' </s>'
|
11 |
+
# generate summary
|
12 |
+
input_ids = tokenizer.encode(translated_text, return_tensors='pt')
|
13 |
+
summary_ids = model.generate(input_ids,
|
14 |
+
min_length=20,
|
15 |
+
max_length=12000)
|
16 |
+
|
17 |
+
summary_text = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
18 |
+
return(summary_text)
|
19 |
+
|
20 |
+
|
21 |
+
#iface = gr.Interface(fn=article_summarization,title="Summarization in English",description="facebook/bart-large-cnn for summarization in English", inputs=(lines=50,['text']), outputs=["text"])
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=article_summarization,title="Summarization in English",description="facebook/bart-large-cnn for summarization in English", inputs=gr.inputs.Textbox(lines=50, placeholder="Enter newpaper article to be summarized"), outputs=["text"])
|
24 |
+
|
25 |
+
iface.launch()
|