""" YSenseAI Wisdom Canvas Demo v4.5-Beta A demonstration of the Story-First UX for ethical AI training data collection. """ import gradio as gr import hashlib import uuid import json from datetime import datetime def generate_attribution(story, author_name): timestamp = datetime.utcnow().isoformat() + "Z" content_hash = hashlib.sha256(story.encode('utf-8')).hexdigest() did = f"did:ysense:{uuid.uuid4().hex[:16]}" return { "did": did, "content_hash": content_hash, "author": author_name or "Anonymous", "timestamp": timestamp, "version": "v4.5-beta", "protocol": "Z-Protocol v2.0" } def analyze_perception_layers(story): word_count = len(story.split()) sentences = story.split('.') return { "narrative": f"A personal story with {len(sentences)} key moments, exploring meaningful experiences.", "somatic": "Physical presence and embodied experience are woven throughout the narrative.", "attention": "The author's focus reveals what matters most in this moment of reflection.", "synesthetic": "Sensory details paint a vivid picture of the experience.", "temporal": f"The story unfolds across time, with {word_count} words capturing the journey." } def distill_essence(story, layers): words = story.lower().split() common = {'about', 'there', 'would', 'could', 'should', 'their', 'these', 'those', 'which', 'where', 'being'} meaningful = [w.strip('.,!?') for w in words if len(w) > 5 and w not in common][:3] if len(meaningful) < 3: meaningful = ["wisdom", "growth", "journey"] return { "essence": " ".join(meaningful[:3]).title(), "meaning": "These words capture the core themes of your story.", "wisdom_type": "personal growth" } def calculate_quality_metrics(story, layers, essence): word_count = len(story.split()) sentence_count = len([s for s in story.split('.') if s.strip()]) metrics = { "authenticity": min(100, 50 + (word_count // 10)), "emotional_depth": min(100, 60 + len(layers.get("somatic", "")) // 2), "narrative_clarity": min(100, 70 if sentence_count > 3 else 50), "cultural_richness": min(100, 55 + (word_count // 20)), "wisdom_density": min(100, 65 if essence.get("wisdom_type") else 45), "training_value": 0 } metrics["training_value"] = sum(list(metrics.values())[:-1]) // 5 return metrics def process_story(story, author_name, consent_research, consent_commercial, consent_derivative, consent_attribution): if not story or len(story.strip()) < 50: return "Please write at least 50 characters to analyze.", "", "", "", "", "" attribution = generate_attribution(story, author_name) attribution_display = f"""### Attribution Record | Field | Value | |-------|-------| | **DID** | `{attribution['did']}` | | **Content Hash** | `{attribution['content_hash'][:32]}...` | | **Author** | {attribution['author']} | | **Timestamp** | {attribution['timestamp']} | | **Protocol** | {attribution['protocol']} |""" layers = analyze_perception_layers(story) layers_display = f"""### 5-Layer Perception Analysis **Narrative Layer**: {layers.get('narrative', 'N/A')} **Somatic Layer**: {layers.get('somatic', 'N/A')} **Attention Layer**: {layers.get('attention', 'N/A')} **Synesthetic Layer**: {layers.get('synesthetic', 'N/A')} **Temporal Layer**: {layers.get('temporal', 'N/A')}""" essence = distill_essence(story, layers) essence_display = f"""### 3-Word Essence # {essence.get('essence', 'Wisdom Awaits You')} **Meaning:** {essence.get('meaning', 'Your story holds unique wisdom.')} **Wisdom Type:** {essence.get('wisdom_type', 'personal growth').title()}""" metrics = calculate_quality_metrics(story, layers, essence) metrics_display = f"""### Quality Metrics | Metric | Score | |--------|-------| | Authenticity | {metrics['authenticity']}% | | Emotional Depth | {metrics['emotional_depth']}% | | Narrative Clarity | {metrics['narrative_clarity']}% | | Cultural Richness | {metrics['cultural_richness']}% | | Wisdom Density | {metrics['wisdom_density']}% | | **Training Value** | **{metrics['training_value']}%** |""" consent_types = [] if consent_research: consent_types.append("Research Use") if consent_commercial: consent_types.append("Commercial Training") if consent_derivative: consent_types.append("Derivative Works") if consent_attribution: consent_types.append("Public Attribution") if not consent_types: consent_types.append("No consent granted") consent_display = f"""### Z-Protocol v2.0 Consent {chr(10).join(['- ' + c for c in consent_types])} **Consent Hash:** `{hashlib.sha256(str(consent_types).encode()).hexdigest()[:16]}` **Revocable:** Yes""" export_data = { "attribution": attribution, "layers": layers, "essence": essence, "metrics": metrics, "consent": {"research": consent_research, "commercial": consent_commercial, "derivative": consent_derivative, "attribution": consent_attribution} } export_display = f"""### Export Preview ```json {json.dumps(export_data, indent=2)} ```""" return attribution_display, layers_display, essence_display, metrics_display, consent_display, export_display example_stories = [ ["My grandmother taught me to make dumplings when I was seven. Her hands, weathered from decades of work, moved with a grace I couldn't understand then. She never measured anything - a pinch of this, a handful of that. Years later, standing in my own kitchen, I finally understood: she wasn't teaching me to cook. She was passing down a language of love that words could never capture.", "Anonymous"], ["The day I failed my first exam, my father didn't say a word. He just took me fishing. We sat by the lake for hours in silence. When the sun set, he finally spoke: 'The fish don't care about your grades. Neither do I. I care about who you become.' That silence taught me more than any lecture ever could.", "Anonymous"] ] with gr.Blocks(title="YSenseAI Wisdom Canvas") as demo: gr.HTML("""
v4.5-Beta | Share your stories. Preserve your wisdom. Shape ethical AI.