File size: 1,095 Bytes
978d79a d17c171 |
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 |
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)
|