CoolFace
Apppublic

Mohitha/Text-Summarization

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1import gradio as gr2from transformers import PreTrainedTokenizerFast, BartForConditionalGeneration3 4model_name = "ainize/kobart-news"5tokenizer = PreTrainedTokenizerFast.from_pretrained(model_name)6model = BartForConditionalGeneration.from_pretrained(model_name)7 8# 원문을 받아서 요약문을 반환9def summ(input_text):  # 매개변수명을 txt에서 input_text로 변경10  input_ids = tokenizer.encode(input_text, return_tensors="pt")11  summary_text_ids = model.generate(12    input_ids=input_ids,13    bos_token_id=model.config.bos_token_id,14    eos_token_id=model.config.eos_token_id,15    length_penalty=2.0,16    max_length=142,17    min_length=56,18    num_beams=4)19  return tokenizer.decode(summary_text_ids[0], skip_special_tokens=True)20 21interface = gr.Interface(summ,22                        [gr.Textbox(label="original text")],23                        [gr.Textbox(label="summary")])24 25interface.launch()26