|
import gradio as gr |
|
import numpy as np |
|
|
|
|
|
questions = [ |
|
"๋๋ ์ฌ๋๋ค๊ณผ ์๊ฐ์ ๋ณด๋ด๋ ๊ฒ์ ์ฆ๊ธด๋ค.", |
|
"๋๋ ๊ตฌ์ฒด์ ์ด๊ณ ์ค์ฉ์ ์ธ ์ ๋ณด๋ฅผ ์ ํธํ๋ค.", |
|
"๋๋ ๋
ผ๋ฆฌ์ ์ธ ๊ฒฐ์ ์ ๋ด๋ฆฌ๋ ๊ฒ์ ์ค์ํ๊ฒ ์๊ฐํ๋ค.", |
|
"๋๋ ์ฒด๊ณ์ ์ด๊ณ ๊ณํ์ ์ธ ์ถ์ ์ข์ํ๋ค.", |
|
"๋๋ ์๋ก์ด ์์ด๋์ด๋ฅผ ํ๊ตฌํ๋ ๊ฒ์ ์ฆ๊ธด๋ค.", |
|
|
|
] |
|
|
|
|
|
mbti_descriptions = { |
|
"INTJ": { |
|
"์ฑ๊ฒฉ": "๋
๋ฆฝ์ ์ด๊ณ ์ ๋ต์ ์ธ ์ฌ๊ณ ๋ฅผ ๊ฐ์ง ์ฑํฅ.", |
|
"์ถ์ฒ ์ง์
": ["๋ฐ์ดํฐ ๋ถ์๊ฐ", "์ํํธ์จ์ด ๊ฐ๋ฐ์", "์ฐ๊ตฌ์"], |
|
"๊ถํฉ": { |
|
"์ข์": ("ENTP", "ํ์ ์ ์ด๊ณ ์ ์ฐํ ์ฌ๊ณ ๊ฐ ์ ๋ง์."), |
|
"๋์": ("ISFP", "๊ฐ์ ๊ณผ ๋
ผ๋ฆฌ์ ์ฐจ์ด๊ฐ ์ถฉ๋ํ ๊ฐ๋ฅ์ฑ.") |
|
} |
|
}, |
|
|
|
} |
|
|
|
|
|
options = ["๋งค์ฐ ์๋๋ค", "์๋๋ค", "๋ณดํต์ด๋ค", "๊ทธ๋ ๋ค", "๋งค์ฐ ๊ทธ๋ ๋ค"] |
|
|
|
def calculate_mbti(answers): |
|
scores = {"E/I": 0, "S/N": 0, "T/F": 0, "J/P": 0} |
|
for i, answer in enumerate(answers): |
|
if i % 4 == 0: |
|
scores["E/I"] += (answer - 3) |
|
elif i % 4 == 1: |
|
scores["S/N"] += (answer - 3) |
|
elif i % 4 == 2: |
|
scores["T/F"] += (answer - 3) |
|
elif i % 4 == 3: |
|
scores["J/P"] += (answer - 3) |
|
result = ( |
|
("I" if scores["E/I"] < 0 else "E") + |
|
("N" if scores["S/N"] < 0 else "S") + |
|
("F" if scores["T/F"] < 0 else "T") + |
|
("P" if scores["J/P"] < 0 else "J") |
|
) |
|
percentages = { |
|
"E/I": abs(scores["E/I"] / 20 * 100), |
|
"S/N": abs(scores["S/N"] / 20 * 100), |
|
"T/F": abs(scores["T/F"] / 20 * 100), |
|
"J/P": abs(scores["J/P"] / 20 * 100) |
|
} |
|
return result, percentages |
|
|
|
def analyze_mbti(answers): |
|
result, percentages = calculate_mbti(answers) |
|
description = mbti_descriptions.get(result, {}) |
|
์ฑ๊ฒฉ = description.get("์ฑ๊ฒฉ", "๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.") |
|
์ถ์ฒ์ง์
= description.get("์ถ์ฒ ์ง์
", []) |
|
๊ถํฉ = description.get("๊ถํฉ", {}) |
|
return { |
|
"MBTI ์ ํ": result, |
|
"์ฑ๊ฒฉ": ์ฑ๊ฒฉ, |
|
"์ถ์ฒ ์ง์
": ์ถ์ฒ์ง์
, |
|
"๊ถํฉ": ๊ถํฉ, |
|
"์ธ๋ถ ๋น์จ": percentages |
|
} |
|
|
|
|
|
def mbti_interface(*answers): |
|
answers = list(answers) |
|
result = analyze_mbti(answers) |
|
return result |
|
|
|
|
|
inputs = [gr.Radio(options, label=q) for q in questions] |
|
outputs = gr.JSON() |
|
|
|
iface = gr.Interface( |
|
fn=mbti_interface, |
|
inputs=inputs, |
|
outputs=outputs, |
|
title="MBTI ๋ถ์๊ธฐ", |
|
description="์ง๋ฌธ์ ๋ต๋ณํ๊ณ ์์ ์ MBTI ์ ํ์ ๋ถ์ํด ๋ณด์ธ์!" |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|