Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
# 질문 데이터
|
| 6 |
+
QUESTIONS = {
|
| 7 |
+
"NS": [
|
| 8 |
+
"쉬운 일보다는 도전적인 일이 더 좋다.",
|
| 9 |
+
"새로운 것을 시도하는 데 흥미를 느낀다.",
|
| 10 |
+
"변화를 즐긴다.",
|
| 11 |
+
"계획을 세우지 않고 즉흥적으로 행동하는 경향이 있다.",
|
| 12 |
+
],
|
| 13 |
+
"HA": [
|
| 14 |
+
"종종 실제보다 일이 더 어렵거나 위험하다고 예상한다.",
|
| 15 |
+
"미래에 어떤 일이 잘못될까 봐 자주 걱정한다.",
|
| 16 |
+
"낯선 사람을 만날 때, 매우 수줍어하며 위축된다.",
|
| 17 |
+
"피로감을 쉽게 느낀다.",
|
| 18 |
+
],
|
| 19 |
+
# 추가 질문 NS, HA, RD, PS, SD, CO, ST 구성
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# 규준 점수 데이터
|
| 23 |
+
STANDARD_SCORES = {
|
| 24 |
+
"NS": {"M": 20, "SD": 5},
|
| 25 |
+
"HA": {"M": 18, "SD": 4},
|
| 26 |
+
"RD": {"M": 22, "SD": 6},
|
| 27 |
+
"PS": {"M": 19, "SD": 4},
|
| 28 |
+
"SD": {"M": 24, "SD": 6},
|
| 29 |
+
"CO": {"M": 26, "SD": 5},
|
| 30 |
+
"ST": {"M": 18, "SD": 5},
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
# 점수 계산 함수
|
| 34 |
+
def calculate_scores(responses):
|
| 35 |
+
results = {}
|
| 36 |
+
for scale, questions in QUESTIONS.items():
|
| 37 |
+
raw_score = sum(responses[scale]) # 원점수 합계
|
| 38 |
+
mean = STANDARD_SCORES[scale]["M"]
|
| 39 |
+
sd = STANDARD_SCORES[scale]["SD"]
|
| 40 |
+
t_score = 50 + 10 * (raw_score - mean) / sd
|
| 41 |
+
percentile = (raw_score - mean + 2 * sd) / (4 * sd) * 100
|
| 42 |
+
results[scale] = {
|
| 43 |
+
"원점수": raw_score,
|
| 44 |
+
"T점수": round(t_score, 2),
|
| 45 |
+
"백분위": round(percentile, 2),
|
| 46 |
+
}
|
| 47 |
+
return results
|
| 48 |
+
|
| 49 |
+
# 결과 시각화
|
| 50 |
+
def visualize_results(results):
|
| 51 |
+
scales = list(results.keys())
|
| 52 |
+
t_scores = [results[scale]["T점수"] for scale in scales]
|
| 53 |
+
|
| 54 |
+
plt.figure(figsize=(8, 4))
|
| 55 |
+
plt.bar(scales, t_scores, color="skyblue")
|
| 56 |
+
plt.axhline(50, color="gray", linestyle="--", label="평균 T점수")
|
| 57 |
+
plt.title("TCI 척도별 T점수")
|
| 58 |
+
plt.xlabel("척도")
|
| 59 |
+
plt.ylabel("T점수")
|
| 60 |
+
plt.legend()
|
| 61 |
+
plt.tight_layout()
|
| 62 |
+
|
| 63 |
+
# 그래프를 이미지로 반환
|
| 64 |
+
plt.savefig("results.png")
|
| 65 |
+
return "results.png"
|
| 66 |
+
|
| 67 |
+
# Gradio 인터페이스
|
| 68 |
+
def tci_app(name, gender, age, **responses):
|
| 69 |
+
user_responses = {scale: [responses[f"{scale}_{i}"] for i in range(len(QUESTIONS[scale]))] for scale in QUESTIONS}
|
| 70 |
+
scores = calculate_scores(user_responses)
|
| 71 |
+
graph_path = visualize_results(scores)
|
| 72 |
+
|
| 73 |
+
report = f"이름: {name}\n성별: {gender}\n연령: {age}\n\n"
|
| 74 |
+
report += "TCI 결과:\n"
|
| 75 |
+
for scale, data in scores.items():
|
| 76 |
+
report += f"{scale}: 원점수={data['원점수']}, T점수={data['T점수']}, 백분위={data['백분위']}\n"
|
| 77 |
+
|
| 78 |
+
return report, graph_path
|
| 79 |
+
|
| 80 |
+
# Gradio UI 구성
|
| 81 |
+
inputs = [
|
| 82 |
+
gr.Textbox(label="이름"),
|
| 83 |
+
gr.Radio(label="성별", choices=["남성", "여성"]),
|
| 84 |
+
gr.Number(label="연령"),
|
| 85 |
+
]
|
| 86 |
+
|
| 87 |
+
for scale, questions in QUESTIONS.items():
|
| 88 |
+
for i, question in enumerate(questions):
|
| 89 |
+
inputs.append(gr.Slider(0, 4, step=1, label=f"{scale}_{i+1}: {question}"))
|
| 90 |
+
|
| 91 |
+
outputs = [
|
| 92 |
+
gr.Textbox(label="결과 보고서", lines=10),
|
| 93 |
+
gr.Image(label="결과 그래프"),
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
app = gr.Interface(fn=tci_app, inputs=inputs, outputs=outputs, title="TCI 기질 분석기")
|
| 97 |
+
app.launch()
|