mbti / app.py
taeyeol's picture
Update app.py
e3cb813 verified
raw
history blame
2.91 kB
import gradio as gr
import numpy as np
# MBTI ์งˆ๋ฌธ ๋ฐ์ดํ„ฐ
questions = [
"๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค๊ณผ ์‹œ๊ฐ„์„ ๋ณด๋‚ด๋Š” ๊ฒƒ์„ ์ฆ๊ธด๋‹ค.",
"๋‚˜๋Š” ๊ตฌ์ฒด์ ์ด๊ณ  ์‹ค์šฉ์ ์ธ ์ •๋ณด๋ฅผ ์„ ํ˜ธํ•œ๋‹ค.",
"๋‚˜๋Š” ๋…ผ๋ฆฌ์ ์ธ ๊ฒฐ์ •์„ ๋‚ด๋ฆฌ๋Š” ๊ฒƒ์„ ์ค‘์š”ํ•˜๊ฒŒ ์ƒ๊ฐํ•œ๋‹ค.",
"๋‚˜๋Š” ์ฒด๊ณ„์ ์ด๊ณ  ๊ณ„ํš์ ์ธ ์‚ถ์„ ์ข‹์•„ํ•œ๋‹ค.",
"๋‚˜๋Š” ์ƒˆ๋กœ์šด ์•„์ด๋””์–ด๋ฅผ ํƒ๊ตฌํ•˜๋Š” ๊ฒƒ์„ ์ฆ๊ธด๋‹ค.",
# ์ถ”๊ฐ€ ์งˆ๋ฌธ ์ž‘์„ฑ (์ด 20๊ฐœ ์ด์ƒ)
]
# ์œ ํ˜•๋ณ„ ์„ค๋ช… ๋ฐ์ดํ„ฐ
mbti_descriptions = {
"INTJ": {
"์„ฑ๊ฒฉ": "๋…๋ฆฝ์ ์ด๊ณ  ์ „๋žต์ ์ธ ์‚ฌ๊ณ ๋ฅผ ๊ฐ€์ง„ ์„ฑํ–ฅ.",
"์ถ”์ฒœ ์ง์—…": ["๋ฐ์ดํ„ฐ ๋ถ„์„๊ฐ€", "์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์ž", "์—ฐ๊ตฌ์›"],
"๊ถํ•ฉ": {
"์ข‹์€": ("ENTP", "ํ˜์‹ ์ ์ด๊ณ  ์œ ์—ฐํ•œ ์‚ฌ๊ณ ๊ฐ€ ์ž˜ ๋งž์Œ."),
"๋‚˜์œ": ("ISFP", "๊ฐ์ •๊ณผ ๋…ผ๋ฆฌ์˜ ์ฐจ์ด๊ฐ€ ์ถฉ๋Œํ•  ๊ฐ€๋Šฅ์„ฑ.")
}
},
# ๋‹ค๋ฅธ ์œ ํ˜• ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€
}
# ์„ ํƒ์ง€๋ฅผ 5๋‹จ๊ณ„๋กœ ์„ค์ •
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
}
# Gradio ์ธํ„ฐํŽ˜์ด์Šค
def mbti_interface(*answers):
answers = list(answers)
result = analyze_mbti(answers)
return result
# ์งˆ๋ฌธ๊ณผ ์„ ํƒ์ง€๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Gradio UI ์ƒ์„ฑ
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()