tkdehf2 commited on
Commit
978d79a
ยท
verified ยท
1 Parent(s): edede22

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ # ๊ฐ์ • ๋ถ„๋ฅ˜ ํŒŒ์ดํ”„๋ผ์ธ ์ƒ์„ฑ
4
+ classifier = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")
5
+
6
+ # ๊ฐ์ • ๋ถ„๋ฅ˜ ํ•จ์ˆ˜ ์ •์˜
7
+ def classify_emotion(text):
8
+ result = classifier(text)[0]
9
+ label = result['label']
10
+ score = result['score']
11
+ return label, score
12
+
13
+ # ์ผ๊ธฐ ์ƒ์„ฑ ํ•จ์ˆ˜ ์ •์˜
14
+ def generate_diary(emotion):
15
+ prompts = {
16
+ "positive": "์˜ค๋Š˜์€ ์ •๋ง ์ข‹์€ ๋‚ ์ด์—ˆ์–ด์š”. ",
17
+ "negative": "์˜ค๋Š˜์€ ํž˜๋“  ํ•˜๋ฃจ์˜€์–ด์š”. ",
18
+ "neutral": "์˜ค๋Š˜์€ ๊ทธ๋ƒฅ ํ‰๋ฒ”ํ•œ ํ•˜๋ฃจ์˜€์–ด์š”. "
19
+ }
20
+ prompt = prompts.get(emotion, "์˜ค๋Š˜์€ ๊ธฐ๋ถ„์ด ๋ณต์žกํ•œ ๋‚ ์ด์—ˆ์–ด์š”. ")
21
+ diary = prompt + "์˜ค๋Š˜์˜ ์ผ๊ธฐ๋ฅผ ๋งˆ์นฉ๋‹ˆ๋‹ค."
22
+ return diary
23
+
24
+ # ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ›๊ธฐ
25
+ user_input = input("์˜ค๋Š˜์˜ ๊ฐ์ •์„ ํ•œ ๋ฌธ์žฅ์œผ๋กœ ํ‘œํ˜„ํ•ด์ฃผ์„ธ์š”: ")
26
+
27
+ # ๊ฐ์ • ๋ถ„๋ฅ˜
28
+ emotion_label, _ = classify_emotion(user_input)
29
+
30
+ # ๊ฐ์ • ๊ธฐ๋ฐ˜ ์ผ๊ธฐ ์ƒ์„ฑ
31
+ diary = generate_diary(emotion_label)
32
+
33
+ # ์ƒ์„ฑ๋œ ์ผ๊ธฐ ์ถœ๋ ฅ
34
+ print("=== ์ƒ์„ฑ๋œ ์ผ๊ธฐ ===")
35
+ print(diary)