Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
class MBTIAnalyzer:
|
| 4 |
def __init__(self):
|
|
@@ -35,10 +36,13 @@ class MBTIAnalyzer:
|
|
| 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 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def analyze(self, answers):
|
| 44 |
idx = 0
|
|
@@ -67,25 +71,36 @@ class MBTIAnalyzer:
|
|
| 67 |
result += 'T' if percentages['T'] >= 50 else 'F'
|
| 68 |
result += 'J' if percentages['J'] >= 50 else 'P'
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
def mbti_interface(*answers):
|
| 76 |
analyzer = MBTIAnalyzer()
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
|
| 79 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 80 |
questions = []
|
| 81 |
for key in ['EI', 'SN', 'TF', 'JP']:
|
| 82 |
for q in MBTIAnalyzer().questions[key]:
|
| 83 |
-
questions.append(gr.Radio(["
|
| 84 |
|
| 85 |
iface = gr.Interface(
|
| 86 |
fn=mbti_interface,
|
| 87 |
inputs=questions,
|
| 88 |
-
outputs="
|
| 89 |
title="MBTI ๋ถ์๊ธฐ",
|
| 90 |
description="20๊ฐ ์ด์์ ์ง๋ฌธ์ ํตํด ๋น์ ์ MBTI ์ ํ์ ๋ถ์ํฉ๋๋ค."
|
| 91 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
|
| 4 |
class MBTIAnalyzer:
|
| 5 |
def __init__(self):
|
|
|
|
| 36 |
self.scores = {'E': 0, 'I': 0, 'S': 0, 'N': 0, 'T': 0, 'F': 0, 'J': 0, 'P': 0}
|
| 37 |
|
| 38 |
def ask_question(self, category, answer):
|
| 39 |
+
# ์ ์๋ฅผ 5๋จ๊ณ๋ก ๊ณ์ฐํฉ๋๋ค. ๋งค์ฐ ๊ทธ๋ ๋ค: 2, ๊ทธ๋ ๋ค: 1, ๋ณดํต์ด๋ค: 0, ์๋๋ค: -1, ๋งค์ฐ ์๋๋ค: -2
|
| 40 |
+
scale = {"๋งค์ฐ ๊ทธ๋ ๋ค": 2, "๊ทธ๋ ๋ค": 1, "๋ณดํต์ด๋ค": 0, "์๋๋ค": -1, "๋งค์ฐ ์๋๋ค": -2}
|
| 41 |
+
score = scale[answer]
|
| 42 |
+
if score > 0:
|
| 43 |
+
self.scores[category[0]] += score
|
| 44 |
+
elif score < 0:
|
| 45 |
+
self.scores[category[1]] -= score
|
| 46 |
|
| 47 |
def analyze(self, answers):
|
| 48 |
idx = 0
|
|
|
|
| 71 |
result += 'T' if percentages['T'] >= 50 else 'F'
|
| 72 |
result += 'J' if percentages['J'] >= 50 else 'P'
|
| 73 |
|
| 74 |
+
return result, percentages
|
| 75 |
+
|
| 76 |
+
def plot_result(self, percentages):
|
| 77 |
+
labels = list(percentages.keys())
|
| 78 |
+
sizes = list(percentages.values())
|
| 79 |
+
|
| 80 |
+
fig, ax = plt.subplots()
|
| 81 |
+
ax.barh(labels, sizes, color='skyblue')
|
| 82 |
+
ax.set_xlim(0, 100)
|
| 83 |
+
ax.set_xlabel('Percentage (%)')
|
| 84 |
+
ax.set_title('MBTI Result Distribution')
|
| 85 |
+
|
| 86 |
+
return fig
|
| 87 |
|
| 88 |
def mbti_interface(*answers):
|
| 89 |
analyzer = MBTIAnalyzer()
|
| 90 |
+
result, percentages = analyzer.analyze(answers)
|
| 91 |
+
fig = analyzer.plot_result(percentages)
|
| 92 |
+
return result, fig
|
| 93 |
|
| 94 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 95 |
questions = []
|
| 96 |
for key in ['EI', 'SN', 'TF', 'JP']:
|
| 97 |
for q in MBTIAnalyzer().questions[key]:
|
| 98 |
+
questions.append(gr.Radio(["๋งค์ฐ ๊ทธ๋ ๋ค", "๊ทธ๋ ๋ค", "๋ณดํต์ด๋ค", "์๋๋ค", "๋งค์ฐ ์๋๋ค"], label=q))
|
| 99 |
|
| 100 |
iface = gr.Interface(
|
| 101 |
fn=mbti_interface,
|
| 102 |
inputs=questions,
|
| 103 |
+
outputs=[gr.Textbox(label="MBTI ์ ํ ๊ฒฐ๊ณผ"), gr.Plot(label="๊ฒฐ๊ณผ ์ฐจํธ")],
|
| 104 |
title="MBTI ๋ถ์๊ธฐ",
|
| 105 |
description="20๊ฐ ์ด์์ ์ง๋ฌธ์ ํตํด ๋น์ ์ MBTI ์ ํ์ ๋ถ์ํฉ๋๋ค."
|
| 106 |
)
|