|
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) |
|
|