Spaces:
Runtime error
Runtime error
Danil
commited on
Commit
•
480ac43
1
Parent(s):
afc5f26
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import MBartTokenizer, MBartForConditionalGeneration
|
3 |
+
|
4 |
+
model_name = "IlyaGusev/mbart_ru_sum_gazeta"
|
5 |
+
tokenizer = MBartTokenizer.from_pretrained(model_name)
|
6 |
+
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def summarize(text):
|
9 |
+
input_ids = tokenizer.batch_encode_plus([text], return_tensors="pt", max_length=1024)["input_ids"].to(model.device)
|
10 |
+
summary_ids = model.generate(input_ids=input_ids, no_repeat_ngram_size=4)
|
11 |
+
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
12 |
+
|
13 |
+
gr.Interface(fn=summarize, inputs="text", outputs="text", description="Russian Summarizer").launch()
|