File size: 966 Bytes
3347488 f6f8985 3347488 f6f8985 3347488 f6f8985 3347488 f6f8985 3347488 f6f8985 3347488 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import adagio
from transformers import GPT2LMHeadModel, GPT2Tokenizer
def app():
adagio.set_title("์๋ ์ผ๊ธฐ ์์ฑ๊ธฐ")
keywords = adagio.text_input("5๊ฐ์ ํค์๋๋ฅผ ์
๋ ฅํ์ธ์ (์ผํ๋ก ๊ตฌ๋ถ)", "")
keyword_list = [kw.strip() for kw in keywords.split(",")]
if len(keyword_list) == 5 and adagio.button("์ผ๊ธฐ ์ฐ๊ธฐ"):
# ๋ชจ๋ธ ๋ฐ ํ ํฌ๋์ด์ ๋ก๋
model = GPT2LMHeadModel.from_pretrained("gpt2")
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
# ํค์๋ ๊ธฐ๋ฐ fine-tuning
input_ids = tokenizer.encode(" ".join(keyword_list), 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)
adagio.write(diary)
if __name__ == "__main__":
adagio.run(app) |