|
import gradio as gr |
|
from transformers import GPT2LMHeadModel, GPT2Tokenizer |
|
|
|
|
|
model = GPT2LMHeadModel.from_pretrained("gpt2") |
|
tokenizer = GPT2Tokenizer.from_pretrained("gpt2") |
|
|
|
def generate_diary(keywords): |
|
|
|
input_ids = tokenizer.encode(" ".join(keywords), return_tensors="pt") |
|
output = model.generate(input_ids, max_length=500, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=5) |
|
|
|
|
|
diary = tokenizer.decode(output[0], skip_special_tokens=True) |
|
return diary |
|
|
|
def app(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# ์๋ ์ผ๊ธฐ ์์ฑ๊ธฐ") |
|
|
|
with gr.Row(): |
|
keywords = gr.Textbox(label="5๊ฐ์ ํค์๋๋ฅผ ์
๋ ฅํ์ธ์ (์ผํ๋ก ๊ตฌ๋ถ)") |
|
generate_btn = gr.Button("์ผ๊ธฐ ์ฐ๊ธฐ") |
|
|
|
diary = gr.Textbox(label="์์ฑ๋ ์ผ๊ธฐ") |
|
|
|
generate_btn.click(generate_diary, inputs=keywords, outputs=diary) |
|
|
|
demo.launch() |
|
|
|
if __name__ == "__main__": |
|
app() |