test
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
baseline_interactive.py
|
3 |
+
"""
|
4 |
+
import gradio as gr
|
5 |
+
import torch
|
6 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
7 |
+
from transformers import pipeline
|
8 |
+
|
9 |
+
model_name = "momo/rsp-sum"
|
10 |
+
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
11 |
+
tokenizer = MBart50TokenizerFast.from_pretrained(model_name, src_lang="ko_KR", tgt_lang="ko_KR")
|
12 |
+
|
13 |
+
# prefix = "translate English to German: "
|
14 |
+
|
15 |
+
def summarization(model_name, text):
|
16 |
+
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
17 |
+
summarizer("An apple a day, keeps the doctor away", min_length=50, max_length=150)
|
18 |
+
|
19 |
+
for result in summarizer(text):
|
20 |
+
print(result)
|
21 |
+
return result
|
22 |
+
|
23 |
+
if __name__ == '__main__':
|
24 |
+
|
25 |
+
#Create a gradio app with a button that calls predict()
|
26 |
+
app = gr.Interface(
|
27 |
+
fn=summarization,
|
28 |
+
inputs='text',
|
29 |
+
outputs='text',
|
30 |
+
title="News Summary Generator",
|
31 |
+
description="News Summary Generator"
|
32 |
+
)
|
33 |
+
app.launch()
|
34 |
+
|
35 |
+
# with torch.no_grad():
|
36 |
+
# while True:
|
37 |
+
# t = input("\nDocument: ")
|
38 |
+
# tokens = tokenizer(
|
39 |
+
# t,
|
40 |
+
# return_tensors="pt",
|
41 |
+
# truncation=True,
|
42 |
+
# padding=True,
|
43 |
+
# max_length=600
|
44 |
+
# )
|
45 |
+
|
46 |
+
# input_ids = tokens.input_ids.cuda()
|
47 |
+
# attention_mask = tokens.attention_mask.cuda()
|
48 |
+
|
49 |
+
# sample_output = model.generate(
|
50 |
+
# input_ids,
|
51 |
+
# max_length=150,
|
52 |
+
# num_beams=5,
|
53 |
+
# early_stopping=True,
|
54 |
+
# no_repeat_ngram_size=8,
|
55 |
+
# )
|
56 |
+
# # print("token:" + str(input_ids.detach().cpu()))
|
57 |
+
# # print("token:" + tokenizer.convert_ids_to_tokens(str(input_ids.detach().cpu())))
|
58 |
+
# print("Summary: " + tokenizer.decode(sample_output[0], skip_special_tokens=True))
|