tkdehf2's picture
Create app.py
9db2041 verified
raw
history blame contribute delete
No virus
1.12 kB
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)