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