ThreatLevelD
Launch frontend demo: Implemented live MEC MVP demo with dynamic emotion processing
7b8b1dc
| # core/hei_inference.py | |
| import yaml | |
| import datetime | |
| from core.codex_informer import CodexInformer | |
| class HEIInference: | |
| def __init__(self, codex_informer): | |
| """Fallback interpreter for low-confidence signals""" | |
| # Load SAL triggers and meta mappings | |
| self.sal_triggers = self.load_yaml('config/sal_triggers.yaml') | |
| self.meta_mappings = self.load_yaml('config/meta_mappings.yaml') | |
| # Store reference to CodexInformer for emotion resolution | |
| self.codex_informer = codex_informer | |
| def load_yaml(self, path): | |
| with open(path, 'r', encoding='utf-8') as f: | |
| return yaml.safe_load(f) | |
| def lookup_meta_mapping(self, meta_marker): | |
| for meta in self.meta_mappings or []: | |
| if meta.get('marker') == meta_marker: | |
| return meta | |
| return None | |
| def detect_low_signal(self, failed_esil_packet): | |
| # Base pseudo-ESIL packet | |
| pseudo = { | |
| 'pseudo_esil_packet_id': f"PSUESP-{datetime.datetime.now().isoformat()}", | |
| 'detected_tokens': failed_esil_packet.get('tokens', []), | |
| 'sal_trigger_flags': [], | |
| 'meta_inference': None, | |
| 'reasoning_flags': [], | |
| 'timestamp': datetime.datetime.now().isoformat() | |
| } | |
| # SAL trigger matching | |
| for token in pseudo['detected_tokens']: | |
| for trigger in (self.sal_triggers.get('sal_triggers') or []): | |
| if isinstance(trigger, dict) and 'trigger' in trigger: | |
| if trigger['trigger'].lower() in token.lower(): | |
| pseudo['sal_trigger_flags'].append(trigger['flag']) | |
| pseudo['reasoning_flags'].append(f"SAL_MATCH-{trigger['flag']}") | |
| # META mapping | |
| meta_marker = failed_esil_packet.get('meta_marker') | |
| if meta_marker: | |
| meta = self.lookup_meta_mapping(meta_marker) | |
| if meta: | |
| pseudo['meta_inference'] = { | |
| 'marker': meta['marker'], | |
| 'blend': meta['inferred_blend'], | |
| 'comment': meta['comment'] | |
| } | |
| pseudo['reasoning_flags'].append(f"META_INFER-{meta['marker']}") | |
| # Resolve emotion data via CodexInformer | |
| raw_code = failed_esil_packet.get('primary_emotion_code', '') | |
| emotion_data = self.codex_informer.resolve_emotion_family(raw_code) | |
| emotion_family = emotion_data.get('emotion_family', 'Unknown') | |
| arc = emotion_data.get('arc', 'Unknown') | |
| resonance = emotion_data.get('resonance', 'Unknown') | |
| # Fallback for hidden emotion | |
| if emotion_family == 'Unknown': | |
| emotion_family = 'Hidden Emotion Detected' | |
| pseudo['emotion_family'] = emotion_family | |
| pseudo['arc'] = arc | |
| pseudo['resonance'] = resonance | |
| # Audit log | |
| self.log_audit(pseudo) | |
| return pseudo | |
| def log_audit(self, packet): | |
| print("---- HEI Inference Audit Log ----") | |
| print(f"Packet ID: {packet['pseudo_esil_packet_id']}") | |
| print(f"Timestamp: {packet['timestamp']}") | |
| print(f"Detected Tokens: {packet['detected_tokens']}") | |
| print(f"SAL Trigger Flags: {packet['sal_trigger_flags']}") | |
| if packet.get('meta_inference'): | |
| print(f"META Inference: {packet['meta_inference']}") | |
| print(f"Reasoning Flags: {packet['reasoning_flags']}") | |
| print("----------------------------------\n") | |