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)