Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration | |
model_name = 'ainize/kobart-news' | |
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name) | |
model = BartForConditionalGeneration.from_pretrained(model_name) | |
def summ(txt): | |
input_ids = tokenizer.encode(txt, return_tensors="pt") | |
summary_text_ids = model.generate( | |
input_ids=input_ids, | |
bos_token_id=model.config.bos_token_id, # BOS는 Beginning of Sentence | |
eos_token_id=model.config.eos_token_id, # EOS는 End of Sentence | |
length_penalty=2.0, # 요약을 얼마나 짧게 할지 | |
max_length=142, # 최대 142 토큰으로 요약 | |
min_length=56, # 최소 56 토큰보다는 더 나옴 | |
num_beams=4 # beam search | |
) | |
return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True) | |
interface = gr.Interface(summ, | |
[gr.Textbox(label="original text")], # gradio를 이용해서 gui | |
[gr.Textbox(label="summary")]) | |
interface.launch() # share가 True일 경우, link가 하나 나옴 |