diary / app.py
tkdehf2's picture
Update app.py
3347488 verified
raw
history blame
966 Bytes
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)