File size: 1,119 Bytes
9db2041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pip install transformers
from transformers import pipeline

# ๊ฐ์ • ๋ถ„๋ฅ˜ ํŒŒ์ดํ”„๋ผ์ธ ์ƒ์„ฑ
classifier = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")

# ๊ฐ์ • ๋ถ„๋ฅ˜ ํ•จ์ˆ˜ ์ •์˜
def classify_emotion(text):
    result = classifier(text)[0]
    label = result['label']
    score = result['score']
    return label, score

# ์ผ๊ธฐ ์ƒ์„ฑ ํ•จ์ˆ˜ ์ •์˜
def generate_diary(emotion):
    prompts = {
        "positive": "์˜ค๋Š˜์€ ์ •๋ง ์ข‹์€ ๋‚ ์ด์—ˆ์–ด์š”. ",
        "negative": "์˜ค๋Š˜์€ ํž˜๋“  ํ•˜๋ฃจ์˜€์–ด์š”. ",
        "neutral": "์˜ค๋Š˜์€ ๊ทธ๋ƒฅ ํ‰๋ฒ”ํ•œ ํ•˜๋ฃจ์˜€์–ด์š”. "
    }
    prompt = prompts.get(emotion, "์˜ค๋Š˜์€ ๊ธฐ๋ถ„์ด ๋ณต์žกํ•œ ๋‚ ์ด์—ˆ์–ด์š”. ")
    diary = prompt + "์˜ค๋Š˜์˜ ์ผ๊ธฐ๋ฅผ ๋งˆ์นฉ๋‹ˆ๋‹ค."
    return diary

# ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ›๊ธฐ
user_input = input("์˜ค๋Š˜์˜ ๊ฐ์ •์„ ํ•œ ๋ฌธ์žฅ์œผ๋กœ ํ‘œํ˜„ํ•ด์ฃผ์„ธ์š”: ")

# ๊ฐ์ • ๋ถ„๋ฅ˜
emotion_label, _ = classify_emotion(user_input)

# ๊ฐ์ • ๊ธฐ๋ฐ˜ ์ผ๊ธฐ ์ƒ์„ฑ
diary = generate_diary(emotion_label)

# ์ƒ์„ฑ๋œ ์ผ๊ธฐ ์ถœ๋ ฅ
print("=== ์ƒ์„ฑ๋œ ์ผ๊ธฐ ===")
print(diary)