import json
def create_backend_view_html(persona):
"""Create HTML representation of the backend view of the persona"""
if not persona:
return "
페르소나가 아직 생성되지 않았습니다.
"
name = persona.get("기본정보", {}).get("이름", "Unknown")
# 백엔드 기본 정보
basic_info = persona.get("기본정보", {})
basic_info_html = ""
for key, value in basic_info.items():
basic_info_html += f"| {key} | {value} |
"
# 1. 성격 변수 요약
personality_summary = persona.get("성격요약", {})
summary_html = ""
if personality_summary:
summary_html += ""
for category, value in personality_summary.items():
if isinstance(value, (int, float)):
summary_html += f"""
"""
summary_html += "
"
# 2. 성격 매트릭스 (5차원 빅5 시각화)
big5_html = ""
if "성격특성" in persona:
# 빅5 매핑 (기존 특성에서 변환)
big5 = {
"외향성(Extraversion)": persona.get("성격특성", {}).get("외향성", 50),
"친화성(Agreeableness)": persona.get("성격특성", {}).get("온기", 50),
"성실성(Conscientiousness)": persona.get("성격특성", {}).get("신뢰성", 50),
"신경증(Neuroticism)": 100 - persona.get("성격특성", {}).get("안정성", 50) if "안정성" in persona.get("성격특성", {}) else 50,
"개방성(Openness)": persona.get("성격특성", {}).get("창의성", 50)
}
big5_html = ""
for trait, value in big5.items():
big5_html += f"""
"""
big5_html += "
"
# 3. 유머 매트릭스
humor_matrix = persona.get("유머매트릭스", {})
humor_html = ""
if humor_matrix:
warmth_vs_wit = humor_matrix.get("warmth_vs_wit", 50)
self_vs_observational = humor_matrix.get("self_vs_observational", 50)
subtle_vs_expressive = humor_matrix.get("subtle_vs_expressive", 50)
humor_html = f"""
"""
# 4. 매력적 결함과 모순적 특성
flaws_html = ""
contradictions_html = ""
flaws = persona.get("매력적결함", [])
if flaws:
flaws_html = ""
for flaw in flaws:
flaws_html += f"- {flaw}
"
flaws_html += "
"
contradictions = persona.get("모순적특성", [])
if contradictions:
contradictions_html = ""
for contradiction in contradictions:
contradictions_html += f"- {contradiction}
"
contradictions_html += "
"
# 6. 프롬프트 템플릿 (있는 경우)
prompt_html = ""
if "프롬프트" in persona:
prompt_text = persona.get("프롬프트", "")
prompt_html = f"""
"""
# 7. 완전한 백엔드 JSON (접이식)
try:
# 내부 상태 객체 제거 (JSON 변환 불가)
json_persona = {k: v for k, v in persona.items() if k not in ["personality_profile", "humor_matrix"]}
persona_json = json.dumps(json_persona, ensure_ascii=False, indent=2)
json_preview = f"""
전체 백엔드 데이터 (JSON)
{persona_json}
"""
except Exception as e:
json_preview = f"JSON 변환 오류: {str(e)}
"
# 8. 전체 HTML 조합
html = f"""
성격 요약 (Big 5)
{big5_html}
유머 매트릭스 (3차원)
{humor_html}
매력적 결함
{flaws_html}
모순적 특성
{contradictions_html}
{prompt_html}
전체 백엔드 데이터
{json_preview}
"""
return html