Spaces:
Runtime error
Runtime error
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) | |