Spaces:
Running
Running
Adinda Panca Mochamad
Fix Day 2: orbit ring, duplicate name guard, format_panel cleanup, 4 test baru
925c1a7 | """JSON entities β Markdown entity detail panel.""" | |
| from __future__ import annotations | |
| _MOOD_EMOJI = { | |
| "mysterious": "π", | |
| "joyful": "βοΈ", | |
| "anxious": "β‘", | |
| "surreal": "π", | |
| "peaceful": "πΏ", | |
| } | |
| def format_panel_entitas(entities: dict) -> str: | |
| """Return a Markdown string summarising extracted dream entities.""" | |
| title = str(entities.get("title") or "Untitled Dream").strip() | |
| mood = str(entities.get("mood") or "mysterious") | |
| theme = str(entities.get("core_theme") or "").strip() | |
| characters = [c for c in (entities.get("characters") or []) if isinstance(c, dict)] | |
| places = [p for p in (entities.get("places") or []) if isinstance(p, dict)] | |
| symbols = [s for s in (entities.get("symbols") or []) if isinstance(s, dict)] | |
| emoji = _MOOD_EMOJI.get(mood, "β¦") | |
| lines: list[str] = [f"## {title}"] | |
| mood_line = f"{emoji} **{mood.capitalize()}**" | |
| if theme: | |
| mood_line += f" Β· _{theme}_" | |
| lines += [mood_line, ""] | |
| if characters: | |
| lines.append("**People**") | |
| for c in characters: | |
| name = str(c.get("name", "?")).strip() | |
| role = str(c.get("role", "")).strip() | |
| emo = str(c.get("emotion", "")).strip() | |
| detail_parts = [x for x in [role, emo] if x] | |
| detail = " Β· ".join(detail_parts) | |
| lines.append(f"- **{name}**" + (f" β {detail}" if detail else "")) | |
| lines.append("") | |
| if places: | |
| lines.append("**Places**") | |
| for p in places: | |
| name = str(p.get("name", "?")).strip() | |
| ptype = str(p.get("type", "")).strip() | |
| feeling = str(p.get("feeling", "")).strip() | |
| detail_parts = [x for x in [ptype, feeling] if x] | |
| detail = " Β· ".join(detail_parts) | |
| lines.append(f"- **{name}**" + (f" β {detail}" if detail else "")) | |
| lines.append("") | |
| if symbols: | |
| lines.append("**Images & symbols**") | |
| for s in symbols: | |
| name = str(s.get("name", "?")).strip() | |
| appearance = str(s.get("appearance", "")).strip() | |
| significance = str(s.get("significance", "")).strip() | |
| detail_parts = [p for p in [appearance, significance] if p] | |
| detail = " Β· ".join(detail_parts) | |
| lines.append(f"- **{name}**" + (f" β {detail}" if detail else "")) | |
| lines.append("") | |
| return "\n".join(lines).rstrip() | |