CSB261 commited on
Commit
bd7ce79
β€’
1 Parent(s): 7d0d80c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py CHANGED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ class MBTIAnalyzer:
4
+ def __init__(self):
5
+ self.questions = {
6
+ 'EI': [
7
+ "μ‚¬λžŒλ“€κ³Όμ˜ λͺ¨μž„이 λλ‚œ ν›„ 당신은 μ—λ„ˆμ§€κ°€ μΆ©μ „λ˜λ‚˜μš”, μ•„λ‹ˆλ©΄ μ†Œλͺ¨λ˜λ‚˜μš”?",
8
+ "νœ΄μ‹ μ‹œκ°„μ„ 혼자 λ³΄λ‚΄λŠ” 것을 μ’‹μ•„ν•˜λ‚˜μš”, μ•„λ‹ˆλ©΄ μΉœκ΅¬λ“€κ³Ό ν•¨κ»˜ λ³΄λ‚΄λŠ” 것을 더 μ’‹μ•„ν•˜λ‚˜μš”?",
9
+ "λͺ¨λ₯΄λŠ” μ‚¬λžŒλ“€κ³Ό μ‰½κ²Œ μΉœν•΄μ§€λ‚˜μš”, μ•„λ‹ˆλ©΄ μ‹œκ°„μ΄ κ±Έλ¦¬λ‚˜μš”?",
10
+ "λ‹€λ₯Έ μ‚¬λžŒκ³Ό ν•¨κ»˜ μ‹œκ°„μ„ λ³΄λ‚΄λŠ” 것을 μ¦κΈ°λ‚˜μš”, μ•„λ‹ˆλ©΄ 혼자 μžˆλŠ” μ‹œκ°„μ΄ 더 μ’‹λ‚˜μš”?",
11
+ "μ£Όλ§μ—λŠ” μ§‘μ—μ„œ μ‰¬λŠ” 것이 μ’‹λ‚˜μš”, μ•„λ‹ˆλ©΄ λ°–μ—μ„œ μ‚¬λžŒλ“€κ³Ό μ–΄μšΈλ¦¬λŠ” 것이 μ’‹λ‚˜μš”?"
12
+ ],
13
+ 'SN': [
14
+ "ν˜„μž¬μ˜ 사싀에 μ§‘μ€‘ν•˜λŠ” νŽΈμΈκ°€μš”, μ•„λ‹ˆλ©΄ 미래의 κ°€λŠ₯성에 더 관심이 μžˆλ‚˜μš”?",
15
+ "μ‹€μ œ κ²½ν—˜μ„ 톡해 λ°°μš°λŠ” 것을 μ„ ν˜Έν•˜λ‚˜μš”, μ•„λ‹ˆλ©΄ 이둠적 κ°œλ…μ„ λ°°μš°λŠ” 것을 μ„ ν˜Έν•˜λ‚˜μš”?",
16
+ "μ„ΈλΆ€ 사항에 신경을 많이 μ“°μ‹œλ‚˜μš”, μ•„λ‹ˆλ©΄ 큰 그림을 λ³΄λŠ” 것을 μ’‹μ•„ν•˜μ‹œλ‚˜μš”?",
17
+ "μ§κ΄€μ μœΌλ‘œ 결정을 잘 λ‚΄λ¦¬μ‹œλ‚˜μš”, μ•„λ‹ˆλ©΄ ꡬ체적인 정보λ₯Ό λ°”νƒ•μœΌλ‘œ 결정을 λ‚΄λ¦¬μ‹œλ‚˜μš”?",
18
+ "당신은 ν˜„μ‹€μ μΈ μ‚¬λžŒμΈκ°€μš”, μ•„λ‹ˆλ©΄ 이상적인 μ‚¬λžŒμΈκ°€μš”?"
19
+ ],
20
+ 'TF': [
21
+ "μ˜μ‚¬κ²°μ • μ‹œ 논리와 뢄석을 λ°”νƒ•μœΌλ‘œ 결정을 λ‚΄λ¦¬λ‚˜μš”, μ•„λ‹ˆλ©΄ μ‚¬λžŒλ“€μ˜ 감정을 κ³ λ €ν•˜μ—¬ 결정을 λ‚΄λ¦¬λ‚˜μš”?",
22
+ "κ°ˆλ“± μƒν™©μ—μ„œ 문제λ₯Ό λ…Όλ¦¬μ μœΌλ‘œ ν•΄κ²°ν•˜λŠ” 것이 μ€‘μš”ν•˜λ‹€κ³  μƒκ°ν•˜λ‚˜μš”, μ•„λ‹ˆλ©΄ μ„œλ‘œμ˜ 감정을 μ΄ν•΄ν•˜κ³  ν•΄κ²°ν•˜λŠ” 것이 μ€‘μš”ν•˜λ‹€κ³  μƒκ°ν•˜λ‚˜μš”?",
23
+ "μ‚¬λžŒλ“€κ³Όμ˜ κ΄€κ³„μ—μ„œ 곡정함이 μ€‘μš”ν•œκ°€μš”, μ•„λ‹ˆλ©΄ μ‘°ν™”κ°€ 더 μ€‘μš”ν•œκ°€μš”?",
24
+ "λΉ„νŒμ„ λ°›μœΌλ©΄ 기뢄이 λ‚˜μ˜μ‹ κ°€μš”, μ•„λ‹ˆλ©΄ κ°œμ„ μ˜ 기회둜 μƒκ°ν•˜μ‹œλ‚˜μš”?",
25
+ "결정을 내릴 λ•Œ 감정보닀 논리가 더 μ€‘μš”ν•˜λ‹€κ³  μƒκ°ν•˜μ‹œλ‚˜μš”?"
26
+ ],
27
+ 'JP': [
28
+ "κ³„νšμ μΈ 삢을 μ„ ν˜Έν•˜μ‹œλ‚˜μš”, μ•„λ‹ˆλ©΄ 즉ν₯적으둜 μ‚¬λŠ” 것을 μ„ ν˜Έν•˜μ‹œλ‚˜μš”?",
29
+ "마감 μ‹œκ°„μ΄ λ‹€κ°€μ˜¬ λ•Œ 일을 미리 끝내고 μ—¬μœ λ‘­κ²Œ μ‹œκ°„μ„ λ³΄λ‚΄λ‚˜μš”, μ•„λ‹ˆλ©΄ λ§‰νŒμ— λͺ°μ•„μ„œ ν•˜μ‹œλ‚˜μš”?",
30
+ "κ³„νšμ΄ λ³€κ²½λ˜λ©΄ 슀트레슀λ₯Ό λ°›λ‚˜μš”, μ•„λ‹ˆλ©΄ μœ μ—°ν•˜κ²Œ λŒ€μ²˜ν•˜μ‹œλ‚˜μš”?",
31
+ "μ‹œκ°„ν‘œλ‚˜ 일정을 μ² μ €νžˆ μ§€ν‚€μ‹œλ‚˜μš”, μ•„λ‹ˆλ©΄ κ·Έλ•Œκ·Έλ•Œ 상황에 맞게 ν–‰λ™ν•˜μ‹œλ‚˜μš”?",
32
+ "μΌμ •μ΄λ‚˜ κ³„νšμ΄ μžˆλŠ” 것이 더 마음이 νŽΈν•œκ°€μš”, μ•„λ‹ˆλ©΄ 자유둜운 것이 더 μ’‹λ‚˜μš”?"
33
+ ]
34
+ }
35
+ self.scores = {'E': 0, 'I': 0, 'S': 0, 'N': 0, 'T': 0, 'F': 0, 'J': 0, 'P': 0}
36
+
37
+ def ask_question(self, category, answer):
38
+ if answer == '1':
39
+ self.scores[category[0]] += 1
40
+ elif answer == '2':
41
+ self.scores[category[1]] += 1
42
+
43
+ def analyze(self, answers):
44
+ idx = 0
45
+ for category, questions in self.questions.items():
46
+ for _ in questions:
47
+ self.ask_question(category, answers[idx])
48
+ idx += 1
49
+ return self.get_result()
50
+
51
+ def calculate_percentage(self):
52
+ percentages = {}
53
+ for category in ['E', 'I', 'S', 'N', 'T', 'F', 'J', 'P']:
54
+ opposite = category[0] if category[0] in ['I', 'N', 'F', 'P'] else category[1]
55
+ total = self.scores[category] + self.scores[opposite]
56
+ if total == 0:
57
+ percentages[category] = 50
58
+ else:
59
+ percentages[category] = int((self.scores[category] / total) * 100)
60
+ return percentages
61
+
62
+ def get_result(self):
63
+ percentages = self.calculate_percentage()
64
+ result = ''
65
+ result += 'E' if percentages['E'] >= 50 else 'I'
66
+ result += 'S' if percentages['S'] >= 50 else 'N'
67
+ result += 'T' if percentages['T'] >= 50 else 'F'
68
+ result += 'J' if percentages['J'] >= 50 else 'P'
69
+
70
+ output = f"MBTI μœ ν˜•: {result}\n\nμ„ΈλΆ€ μ§€μˆ˜:\n"
71
+ for trait, percentage in percentages.items():
72
+ output += f"{trait}: {percentage}%\n"
73
+ return output
74
+
75
+ def mbti_interface(answers):
76
+ analyzer = MBTIAnalyzer()
77
+ return analyzer.analyze(answers)
78
+
79
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
80
+ questions = []
81
+ for key in ['EI', 'SN', 'TF', 'JP']:
82
+ for q in MBTIAnalyzer().questions[key]:
83
+ questions.append(gr.inputs.Radio(["1", "2"], label=q))
84
+
85
+ iface = gr.Interface(
86
+ fn=mbti_interface,
87
+ inputs=questions,
88
+ outputs="text",
89
+ title="MBTI 뢄석기",
90
+ description="20개 μ΄μƒμ˜ μ§ˆλ¬Έμ„ 톡해 λ‹Ήμ‹ μ˜ MBTI μœ ν˜•μ„ λΆ„μ„ν•©λ‹ˆλ‹€."
91
+ )
92
+
93
+ if __name__ == "__main__":
94
+ iface.launch()