Download app.py from SG34/MBTI_Test: direct link, hf CLI and curl.
- Browser
- Download file 8.28 kB
-
https://huggingface.co/spaces/SG34/MBTI_Test/resolve/main/app.py
- Command line
-
hf download hf://spaces/SG34/MBTI_Test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SG34/MBTI_Test/resolve/main/app.py
8.28 kB
| import gradio as gr | |
| import numpy as np | |
| import pandas as pd | |
| # MBTI μ νλ³ μ±κ²© μ€λͺ λ° μ§μ μΆμ² | |
| mbti_descriptions = { | |
| 'INTJ': { | |
| 'description': 'λ 립μ μ΄λ©° μ λ΅μ μ¬κ³ λ₯Ό κ°μ§ μ¬λμ λλ€. 볡μ‘ν λ¬Έμ λ₯Ό ν΄κ²°νλ λ° λ₯μν©λλ€.', | |
| 'careers': ['κ³Όνμ', 'μμ§λμ΄', 'κ΅μ', 'μμ¬'] | |
| }, | |
| 'INFJ': { | |
| 'description': 'μ°½μμ μ΄λ©° μ¬λ € κΉμ μ΄μμ£Όμμμ λλ€. μ¬λλ€μκ² κΉμ κ΄μ¬μ κ°μ§λ©° λ³νλ₯Ό μΆκ΅¬ν©λλ€.', | |
| 'careers': ['μλ΄κ°', 'μκ°', 'κ΅μ¬', 'μμ κ°'] | |
| }, | |
| 'INTP': { | |
| 'description': 'λ Όλ¦¬μ μ΄λ©° λΆμμ μΈ μ±κ²©μ κ°μ§ μ¬λμ λλ€. μ§μ νꡬλ₯Ό μ¦κΈ°λ©° μλ‘μ΄ μ΄λ‘ μ κ°λ°νλ λ° ν₯λ―Έλ₯Ό λλλλ€.', | |
| 'careers': ['μ² νμ', 'νλ‘κ·Έλλ¨Έ', 'μ°κ΅¬μ', 'λ°μ΄ν° λΆμκ°'] | |
| }, | |
| 'INFP': { | |
| 'description': 'μ΄μμ μ΄λ©° κΉμ λ΄λ©΄μ κ°μΉλ₯Ό κ°μ§ μ¬λμ λλ€. μμ μ μ λ μ λ°νμΌλ‘ μΈμμ λ λμ κ³³μΌλ‘ λ§λ€κ³ μ ν©λλ€.', | |
| 'careers': ['μκ°', 'μλ΄κ°', 'μμ κ°', 'μ¬λ¦¬νμ'] | |
| }, | |
| 'ENTJ': { | |
| 'description': 'μμ κ° μκ³ λ¦¬λμμ΄ κ°ν μ±κ²©μ κ°μ§ μ¬λμ λλ€. μ‘°μ§μ μ΄λκ³ λͺ©νλ₯Ό λ¬μ±νλ λ° νμν λ₯λ ₯μ κ°μ§κ³ μμ΅λλ€.', | |
| 'careers': ['κ²½μμ', 'λ³νΈμ¬', '컨μ€ν΄νΈ', 'νλ‘μ νΈ λ§€λμ '] | |
| }, | |
| 'ENFJ': { | |
| 'description': 'νμΈμ μ΄ν΄νκ³ λλ λ° λ°μ΄λ μ±κ²©μ λλ€. μ¬λλ€κ³Όμ μνΈμμ©μ ν΅ν΄ μλμ§λ₯Ό μ»μΌλ©°, 리λμμ λ°νν©λλ€.', | |
| 'careers': ['κ΅μ¬', 'μλ΄κ°', 'HR μ λ¬Έκ°', 'μ μΉκ°'] | |
| }, | |
| 'ENTP': { | |
| 'description': 'νμ μ μ΄λ©° ν λ‘ μ μ¦κΈ°λ μ±κ²©μ λλ€. λ€μν μμ΄λμ΄λ₯Ό νꡬνκ³ λμ μ μ¦κΉλλ€.', | |
| 'careers': ['κΈ°μ κ°', 'λ³νΈμ¬', '컨μ€ν΄νΈ', 'κΈ°νμ'] | |
| }, | |
| 'ENFP': { | |
| 'description': 'μ΄μ μ μ΄κ³ μ°½μμ μΈ μ±κ²©μ κ°μ§ μ¬λμ λλ€. μλ‘μ΄ κ°λ₯μ±μ λν΄ μ΄λ € μμΌλ©°, μ¬λλ€κ³Όμ κ΅λ₯λ₯Ό μ¦κΉλλ€.', | |
| 'careers': ['ν보 μ λ¬Έκ°', 'λ§μΌν μ λ¬Έκ°', 'μκ°', '컨μ€ν΄νΈ'] | |
| }, | |
| 'ISTJ': { | |
| 'description': 'μ λ’°ν μ μμΌλ©° μ± μκ°μ΄ κ°ν μ±κ²©μ λλ€. μ¬μ€κ³Ό μΈλΆ μ¬νμ μ€μνλ©°, κ³νμ λ°λΌ μΌμ μνν©λλ€.', | |
| 'careers': ['νκ³μ¬', 'λ³νΈμ¬', '곡무μ', 'μμ§λμ΄'] | |
| }, | |
| 'ISFJ': { | |
| 'description': 'λ°λ»νκ³ νμ μ μΈ μ±κ²©μ κ°μ§ μ¬λμ λλ€. νμΈμ λκ³ μ§μνλ λ° κΈ°μ¨μ λλΌλ©°, μμ μ μΈ νκ²½μ μ νΈν©λλ€.', | |
| 'careers': ['κ°νΈμ¬', 'κ΅μ¬', 'μ¬ν볡μ§μ¬', 'κ΄λ¦¬μ'] | |
| }, | |
| 'ESTJ': { | |
| 'description': 'μ€μ©μ μ΄λ©° μ‘°μ§μ μΈ μ±κ²©μ κ°μ§ μ¬λμ λλ€. κ·μΉκ³Ό μ μ°¨λ₯Ό μ€μμνλ©°, ν¨μ¨μ μΌλ‘ μΌμ μΆμ§ν©λλ€.', | |
| 'careers': ['κ²½μμ', '곡무μ', 'λ²λ₯ κ°', 'νλ‘μ νΈ λ§€λμ '] | |
| }, | |
| 'ESFJ': { | |
| 'description': 'μ¬κ΅μ μ΄κ³ μΉμ ν μ±κ²©μ κ°μ§ μ¬λμ λλ€. λ€λ₯Έ μ¬λλ€κ³Όμ κ΄κ³λ₯Ό μ€μνλ©°, 곡λ체λ₯Ό μν΄ λ΄μ¬ν©λλ€.', | |
| 'careers': ['κ΅μ¬', 'κ°νΈμ¬', 'μ΄λ²€νΈ νλλ', 'νλ§€ κ΄λ¦¬μ'] | |
| }, | |
| 'ISTP': { | |
| 'description': 'λ Όλ¦¬μ μ΄λ©° λ¬Έμ ν΄κ²°μ λ₯ν μ±κ²©μ λλ€. μλ‘μ΄ κΈ°μ μ λ°°μ°κ³ μ€ννλ κ²μ μ’μν©λλ€.', | |
| 'careers': ['μμ§λμ΄', 'νμΌλΏ', 'μ λΉμ¬', 'μμ¬κ΄'] | |
| }, | |
| 'ISFP': { | |
| 'description': 'κ°κ°μ μ΄κ³ μμ μ μΈ μ±κ²©μ κ°μ§ μ¬λμ λλ€. μμ μ κ°μ μ νννλ κ²μ μ€μμνλ©°, μμ λ‘μ΄ νκ²½μ μ νΈν©λλ€.', | |
| 'careers': ['μμ κ°', 'λμμ΄λ', 'μμ κ°', 'μ¬μ§μκ°'] | |
| }, | |
| 'ESTP': { | |
| 'description': 'μ κ·Ήμ μ΄λ©° λͺ¨νμ μ¦κΈ°λ μ±κ²©μ λλ€. νμ€μ μΈ λ¬Έμ λ₯Ό λΉ λ₯΄κ² ν΄κ²°νκ³ , μνμ κ°μνλ κ²μ λλ €μνμ§ μμ΅λλ€.', | |
| 'careers': ['κΈ°μ κ°', 'μ€ν¬μΈ μ½μΉ', 'κ²½μ°°κ΄', 'μμ μ λ¬Έκ°'] | |
| }, | |
| 'ESFP': { | |
| 'description': 'νλ°νκ³ μ¬κ΅μ μΈ μ±κ²©μ κ°μ§ μ¬λμ λλ€. μ¬λλ€κ³Ό μ΄μΈλ¦¬λ©° μ¦κ±°μμ μ°Ύκ³ , νμ₯μμμ κ²½νμ μ€μμν©λλ€.', | |
| 'careers': ['λ°°μ°', 'μμ κ°', 'μ΄λ²€νΈ νλλ', 'ν보 μ λ¬Έκ°'] | |
| } | |
| } | |
| # μ€λ¬Έ μ§λ¬Έ μμ± | |
| questions = [ | |
| "κ³νμ μΈμ°λ κ²μ μ νΈνμλκΉ?", | |
| "κ²°μ μ λ΄λ¦΄ λ κ°μ λ³΄λ€ λ Όλ¦¬μ μΈ μ΄μ λ₯Ό λ μ€μν©λκΉ?", | |
| "ν° λͺ¨μλ³΄λ€ μκ·λͺ¨ λͺ¨μμ΄ λ νΈμνλ€κ³ λλΌμλκΉ?", | |
| "μ°½μμ μΈ μμ΄λμ΄λ₯Ό μκ°νλ κ²μ μ’μνμλκΉ?", | |
| "μΈλΆ μ¬νμ μ£Όμλ₯Ό κΈ°μΈμ΄λ κ²μ μ€μνκ² μκ°νμλκΉ?", | |
| "λΉνμ μΈ νΌλλ°±μ λ°μμ λ κ·Έκ²μ κ°μ μ κΈ°νλ‘ μκ°νμλκΉ?", | |
| "μμ μ κ°μ μ λ―Όκ°ν νΈμ λκΉ?", | |
| "μ ν΄μ§ μ μ°¨λ₯Ό λ°λ₯΄λ κ²μ μ€μνκ² μκ°νμλκΉ?", | |
| "μ£Όλ³ μ¬λλ€κ³Ό μ½κ² μ΄μΈλ¦΄ μ μμ΅λκΉ?", | |
| "λ―Έλμ κ°λ₯μ±μ λν΄ μμ£Ό μκ°ν©λκΉ?", | |
| "λ¬Έμ λ₯Ό ν΄κ²°ν λ κ°μ μ μΈ μΈ‘λ©΄μ κ³ λ €ν©λκΉ?", | |
| "μ¦ν₯μ μΈ κ²°μ μ μμ£Ό λ΄λ¦½λκΉ?", | |
| "νΌμλ§μ μκ°μ΄ νμνλ€κ³ λλλκΉ?", | |
| "ꡬ체μ μΈ μ¬μ€λ³΄λ€ ν° κ·Έλ¦Όμ 보λ κ²μ μ νΈν©λκΉ?", | |
| "λ€λ₯Έ μ¬λλ€κ³Όμ κ°λ±μ νΌνλ €κ³ λ Έλ ₯ν©λκΉ?", | |
| "λ§μ§λ§ μκ°κΉμ§ μΌμ λ―Έλ£¨μ§ μμΌλ €κ³ λ Έλ ₯ν©λκΉ?", | |
| "λ€λ₯Έ μ¬λκ³Όμ μμ¬μν΅μμ μλμ§λ₯Ό μ»μ΅λκΉ?", | |
| "μ§κ΄λ³΄λ€λ νμ€μ κΈ°λ°ν κ²°μ μ λ΄λ¦½λκΉ?", | |
| "λ Όλ¦¬μ λΆμμ ν΅ν΄ κ²°μ μ λ΄λ¦¬λ νΈμ λκΉ?", | |
| "κ³ν보λ€λ μν©μ λ°λΌ μ μ°νκ² νλνλ νΈμ λκΉ?" | |
| ] | |
| # μλ΅μ μ«μλ‘ λ³ννκΈ° μν ν¨μ | |
| def convert_answer_to_score(answer): | |
| return 1 if answer == "μ" else 0 | |
| # MBTI κ²°κ³Ό κ³μ° ν¨μ | |
| def calculate_mbti(answers): | |
| # μλ΅ μ μ λ³ν | |
| scores = [convert_answer_to_score(a) for a in answers] | |
| # μμ MBTI κ²°κ³Ό κ³μ° λ°©μ (μ€μ λ‘μ§μ λ 볡μ‘ν μ μμ) | |
| ei_score = sum(scores[:5]) / 5 * 100 # 첫 5κ°μ μ§λ¬Έμ΄ E/Iμ κ΄λ ¨λ¨ | |
| sn_score = sum(scores[5:10]) / 5 * 100 # λ€μ 5κ°λ S/Nμ κ΄λ ¨λ¨ | |
| tf_score = sum(scores[10:15]) / 5 * 100 # λ€μ 5κ°λ T/Fμ κ΄λ ¨λ¨ | |
| jp_score = sum(scores[15:20]) / 5 * 100 # λ§μ§λ§ 5κ°λ J/Pμ κ΄λ ¨λ¨ | |
| ei_type = 'E' if ei_score > 50 else 'I' | |
| sn_type = 'S' if sn_score > 50 else 'N' | |
| tf_type = 'T' if tf_score > 50 else 'F' | |
| jp_type = 'J' if jp_score > 50 else 'P' | |
| mbti_result = f"{ei_type}{sn_type}{tf_type}{jp_type}" | |
| description = mbti_descriptions[mbti_result]['description'] | |
| careers = ", ".join(mbti_descriptions[mbti_result]['careers']) | |
| return ei_score, sn_score, tf_score, jp_score, mbti_result, description, careers | |
| # Gradio μΈν°νμ΄μ€ μ€μ | |
| def mbti_interface(*answers): | |
| # λ―Έμλ΅ μ²΄ν¬ | |
| if None in answers: | |
| return "<p style='color: red;'>λͺ¨λ μ§λ¬Έμ λ΅λ³ν΄ μ£ΌμΈμ.</p>" | |
| ei_score, sn_score, tf_score, jp_score, mbti_result, description, careers = calculate_mbti(answers) | |
| result_html = f""" | |
| <h2>λΉμ μ MBTI μ ν: {mbti_result}</h2> | |
| <p><strong>E/I λΉμ¨:</strong> E: {ei_score:.1f}% / I: {100 - ei_score:.1f}%</p> | |
| <p><strong>S/N λΉμ¨:</strong> S: {sn_score:.1f}% / N: {100 - sn_score:.1f}%</p> | |
| <p><strong>T/F λΉμ¨:</strong> T: {tf_score:.1f}% / F: {100 - tf_score:.1f}%</p> | |
| <p><strong>J/P λΉμ¨:</strong> J: {jp_score:.1f}% / P: {100 - jp_score:.1f}%</p> | |
| <h3>μ±κ²© μ€λͺ </h3> | |
| <p>{description}</p> | |
| <h3>μΆμ² μ§μ </h3> | |
| <p>{careers}</p> | |
| """ | |
| return result_html | |
| # Gradio μ± μΈν°νμ΄μ€ μ€μ | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# MBTI νλ³κΈ°") | |
| inputs = [gr.Radio(["μ", "μλμ"], label=q) for q in questions] | |
| submit = gr.Button("결과 보기") | |
| outputs = gr.HTML(label="MBTI κ²°κ³Ό") | |
| submit.click(mbti_interface, inputs, outputs) | |
| # μ€ν | |
| if __name__ == "__main__": | |
| demo.launch() |