tkdehf2 commited on
Commit
9db2041
โ€ข
1 Parent(s): f379733

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
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)