Upload app.py
#2
by
abdulhamed
- opened
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import EncoderDecoderModel, BertTokenizer
|
| 3 |
+
|
| 4 |
+
model = EncoderDecoderModel.from_pretrained("abdulhamed/AraBert-summarize")
|
| 5 |
+
tokenizer = BertTokenizer.from_pretrained("abdulhamed/AraBert-summarize")
|
| 6 |
+
|
| 7 |
+
def summarize_article(article):
|
| 8 |
+
input_ids = tokenizer(article, return_tensors="pt", truncation=True, padding=True).input_ids
|
| 9 |
+
generated = model.generate(input_ids)[0]
|
| 10 |
+
summary = tokenizer.decode(generated, skip_special_tokens=True)
|
| 11 |
+
return summary
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=summarize_article,
|
| 15 |
+
inputs=gr.Textbox(lines=10, label="Article"),
|
| 16 |
+
outputs=gr.Textbox(label="Summary"),
|
| 17 |
+
title="AraBERT Summarization"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
iface.launch()
|