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