Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip install transformers
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# ๊ฐ์ ๋ถ๋ฅ ํ์ดํ๋ผ์ธ ์์ฑ
|
5 |
+
classifier = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
6 |
+
|
7 |
+
# ๊ฐ์ ๋ถ๋ฅ ํจ์ ์ ์
|
8 |
+
def classify_emotion(text):
|
9 |
+
result = classifier(text)[0]
|
10 |
+
label = result['label']
|
11 |
+
score = result['score']
|
12 |
+
return label, score
|
13 |
+
|
14 |
+
# ์ผ๊ธฐ ์์ฑ ํจ์ ์ ์
|
15 |
+
def generate_diary(emotion):
|
16 |
+
prompts = {
|
17 |
+
"positive": "์ค๋์ ์ ๋ง ์ข์ ๋ ์ด์์ด์. ",
|
18 |
+
"negative": "์ค๋์ ํ๋ ํ๋ฃจ์์ด์. ",
|
19 |
+
"neutral": "์ค๋์ ๊ทธ๋ฅ ํ๋ฒํ ํ๋ฃจ์์ด์. "
|
20 |
+
}
|
21 |
+
prompt = prompts.get(emotion, "์ค๋์ ๊ธฐ๋ถ์ด ๋ณต์กํ ๋ ์ด์์ด์. ")
|
22 |
+
diary = prompt + "์ค๋์ ์ผ๊ธฐ๋ฅผ ๋ง์นฉ๋๋ค."
|
23 |
+
return diary
|
24 |
+
|
25 |
+
# ์ฌ์ฉ์ ์
๋ ฅ ๋ฐ๊ธฐ
|
26 |
+
user_input = input("์ค๋์ ๊ฐ์ ์ ํ ๋ฌธ์ฅ์ผ๋ก ํํํด์ฃผ์ธ์: ")
|
27 |
+
|
28 |
+
# ๊ฐ์ ๋ถ๋ฅ
|
29 |
+
emotion_label, _ = classify_emotion(user_input)
|
30 |
+
|
31 |
+
# ๊ฐ์ ๊ธฐ๋ฐ ์ผ๊ธฐ ์์ฑ
|
32 |
+
diary = generate_diary(emotion_label)
|
33 |
+
|
34 |
+
# ์์ฑ๋ ์ผ๊ธฐ ์ถ๋ ฅ
|
35 |
+
print("=== ์์ฑ๋ ์ผ๊ธฐ ===")
|
36 |
+
print(diary)
|