Update app.py
Browse files
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()
|