| """ |
| ARF 3.3.9 Demo - Psychology-Optimized Version |
| Fixed with proper error handling |
| """ |
|
|
| import gradio as gr |
| import pandas as pd |
| import numpy as np |
| from datetime import datetime, timedelta |
| import json |
| import time |
| import uuid |
| import hashlib |
| import random |
| import traceback |
| import sys |
| from typing import Dict, List, Any, Tuple, Optional |
| from dataclasses import dataclass |
| from enum import Enum |
| import re |
|
|
| print("=" * 70) |
| print("π§ ARF 3.3.9 DEMO - Psychology-Optimized Edition") |
| print("=" * 70) |
|
|
| |
| |
| |
|
|
| class RiskLevel(str, Enum): |
| CRITICAL = "CRITICAL" |
| HIGH = "HIGH" |
| MEDIUM = "MEDIUM" |
| LOW = "LOW" |
| SAFE = "SAFE" |
|
|
| class EnforcementLevel(str, Enum): |
| ADVISORY = "ADVISORY" |
| HUMAN_APPROVAL = "HUMAN_APPROVAL" |
| AUTONOMOUS = "AUTONOMOUS" |
| FULL_MECHANICAL = "FULL_MECHANICAL" |
|
|
| class LicenseTier(str, Enum): |
| TRIAL = "TRIAL" |
| STARTER = "STARTER" |
| PROFESSIONAL = "PROFESSIONAL" |
| ENTERPRISE = "ENTERPRISE" |
|
|
| @dataclass |
| class RiskAssessment: |
| score: float |
| level: RiskLevel |
| confidence: float |
| factors: Dict[str, float] |
| |
| @property |
| def color(self) -> str: |
| return { |
| RiskLevel.CRITICAL: "#D32F2F", |
| RiskLevel.HIGH: "#F44336", |
| RiskLevel.MEDIUM: "#FF9800", |
| RiskLevel.LOW: "#4CAF50", |
| RiskLevel.SAFE: "#2E7D32" |
| }[self.level] |
| |
| @property |
| def icon(self) -> str: |
| return { |
| RiskLevel.CRITICAL: "π₯", |
| RiskLevel.HIGH: "β οΈ", |
| RiskLevel.MEDIUM: "πΆ", |
| RiskLevel.LOW: "β
", |
| RiskLevel.SAFE: "π‘οΈ" |
| }[self.level] |
|
|
| @dataclass |
| class GateResult: |
| name: str |
| passed: bool |
| message: str |
| required: bool = True |
| weight: float = 1.0 |
| |
| @property |
| def color(self) -> str: |
| return "#4CAF50" if self.passed else "#F44336" |
| |
| @property |
| def icon(self) -> str: |
| return "β
" if self.passed else "β" |
|
|
| |
| |
| |
|
|
| class ARFEngine: |
| """Simplified but robust ARF engine""" |
| |
| def __init__(self): |
| self.stats = { |
| "total_processed": 0, |
| "blocked_actions": 0, |
| "autonomous_executions": 0, |
| "avg_processing_time": 0.0 |
| } |
| print("β
ARF Engine initialized") |
| |
| def assess_action(self, action: str, context: Dict, license_key: str = None) -> Dict: |
| """Assess an action with realistic scoring""" |
| start_time = time.time() |
| |
| |
| risk = self._assess_risk(action, context) |
| |
| |
| policy_result = self._evaluate_policies(action, context, risk.score) |
| |
| |
| license_info = self._validate_license(license_key) |
| |
| |
| gate_results = self._evaluate_gates(risk, policy_result, license_info) |
| |
| |
| processing_time = time.time() - start_time |
| |
| |
| self._update_stats(policy_result, gate_results, processing_time) |
| |
| return { |
| "timestamp": datetime.now().isoformat(), |
| "action": action, |
| "risk_assessment": risk, |
| "policy_result": policy_result, |
| "license_info": license_info, |
| "gate_results": gate_results, |
| "processing_time": round(processing_time, 4), |
| "recommendation": self._generate_recommendation(policy_result, gate_results, license_info) |
| } |
| |
| def _assess_risk(self, action: str, context: Dict) -> RiskAssessment: |
| """Assess risk with realistic scoring""" |
| action_lower = action.lower() |
| |
| |
| destructiveness = 0.3 |
| if "drop" in action_lower and "database" in action_lower: |
| destructiveness = 0.95 |
| elif "delete" in action_lower: |
| destructiveness = 0.85 |
| elif "truncate" in action_lower: |
| destructiveness = 0.80 |
| |
| complexity = min(0.8, len(action.split()) * 0.05) |
| |
| env = context.get("environment", "development") |
| environment_risk = { |
| "production": 0.8, |
| "staging": 0.5, |
| "testing": 0.3, |
| "development": 0.2 |
| }.get(env, 0.5) |
| |
| |
| risk_score = ( |
| destructiveness * 0.4 + |
| complexity * 0.2 + |
| environment_risk * 0.4 |
| ) |
| |
| |
| if risk_score >= 0.8: |
| level = RiskLevel.CRITICAL |
| elif risk_score >= 0.6: |
| level = RiskLevel.HIGH |
| elif risk_score >= 0.4: |
| level = RiskLevel.MEDIUM |
| elif risk_score >= 0.2: |
| level = RiskLevel.LOW |
| else: |
| level = RiskLevel.SAFE |
| |
| |
| confidence = 0.8 |
| if "drop database" in action_lower: |
| confidence = 0.95 |
| elif "delete from" in action_lower: |
| confidence = 0.90 |
| |
| return RiskAssessment( |
| score=round(risk_score, 3), |
| level=level, |
| confidence=round(confidence, 3), |
| factors={ |
| "destructiveness": destructiveness, |
| "complexity": complexity, |
| "environment": environment_risk |
| } |
| ) |
| |
| def _evaluate_policies(self, action: str, context: Dict, risk_score: float) -> Dict: |
| """Evaluate against safety policies""" |
| violations = [] |
| |
| |
| if ("drop" in action.lower() or "delete" in action.lower()) and context.get("environment") == "production": |
| violations.append({ |
| "policy": "Destructive Operation Prevention", |
| "severity": "CRITICAL", |
| "action": "BLOCK" |
| }) |
| |
| |
| if risk_score > 0.7 and context.get("environment") == "production": |
| violations.append({ |
| "policy": "High Risk Review Required", |
| "severity": "HIGH", |
| "action": "REQUIRE_APPROVAL" |
| }) |
| |
| return { |
| "violations": violations, |
| "blocked": any(v["action"] == "BLOCK" for v in violations), |
| "requires_approval": any(v["action"] == "REQUIRE_APPROVAL" for v in violations), |
| "total_violations": len(violations) |
| } |
| |
| def _validate_license(self, license_key: str = None) -> Dict: |
| """Validate license key""" |
| if not license_key: |
| return { |
| "tier": None, |
| "valid": False, |
| "name": "OSS Edition", |
| "enforcement": "ADVISORY", |
| "message": "π΅ Using ARF OSS (Open Source)" |
| } |
| |
| if license_key.startswith("ARF-"): |
| if "TRIAL" in license_key: |
| return { |
| "tier": "TRIAL", |
| "valid": True, |
| "name": "Trial", |
| "enforcement": "ADVISORY", |
| "message": "π Trial License Active (14 days)" |
| } |
| elif "PRO" in license_key: |
| return { |
| "tier": "PROFESSIONAL", |
| "valid": True, |
| "name": "Professional", |
| "enforcement": "AUTONOMOUS", |
| "message": "β
Professional License Active" |
| } |
| |
| return { |
| "tier": None, |
| "valid": False, |
| "name": "Invalid", |
| "enforcement": "ADVISORY", |
| "message": "β Invalid License Key" |
| } |
| |
| def _evaluate_gates(self, risk: RiskAssessment, policy: Dict, license: Dict) -> List[GateResult]: |
| """Evaluate mechanical gates""" |
| gates = [] |
| |
| |
| gates.append(GateResult( |
| name="License Validation", |
| passed=license.get("valid", False), |
| message=license.get("message", "No license"), |
| required=True |
| )) |
| |
| |
| risk_threshold = 0.8 if license.get("tier") in ["PROFESSIONAL", "ENTERPRISE"] else 0.7 |
| gates.append(GateResult( |
| name="Risk Assessment", |
| passed=risk.score <= risk_threshold, |
| message=f"Risk {risk.score:.1%} β€ {risk_threshold:.0%} threshold", |
| required=True |
| )) |
| |
| |
| gates.append(GateResult( |
| name="Confidence Threshold", |
| passed=risk.confidence >= 0.7, |
| message=f"Confidence {risk.confidence:.1%} β₯ 70%", |
| required=True |
| )) |
| |
| |
| gates.append(GateResult( |
| name="Policy Compliance", |
| passed=not policy.get("blocked", False), |
| message=f"{policy.get('total_violations', 0)} policy violations", |
| required=True |
| )) |
| |
| return gates |
| |
| def _generate_recommendation(self, policy: Dict, gates: List[GateResult], license: Dict) -> str: |
| """Generate recommendation""" |
| if policy.get("blocked"): |
| return "π« BLOCKED: Action violates safety policies" |
| |
| all_gates_passed = all(g.passed for g in gates if g.required) |
| |
| if not license.get("valid"): |
| return "π΅ OSS ADVISORY: Human review recommended" |
| elif all_gates_passed and license.get("tier") in ["PROFESSIONAL", "ENTERPRISE"]: |
| return "π‘ ENTERPRISE APPROVED: Autonomous execution permitted" |
| elif all_gates_passed and license.get("tier") == "STARTER": |
| return "π€ HUMAN APPROVAL: Gates passed, awaiting confirmation" |
| else: |
| return "β οΈ REVIEW REQUIRED: Additional validation needed" |
| |
| def _update_stats(self, policy: Dict, gates: List[GateResult], processing_time: float): |
| """Update statistics""" |
| self.stats["total_processed"] += 1 |
| if policy.get("blocked"): |
| self.stats["blocked_actions"] += 1 |
| |
| if all(g.passed for g in gates if g.required): |
| self.stats["autonomous_executions"] += 1 |
| |
| |
| self.stats["avg_processing_time"] = ( |
| self.stats["avg_processing_time"] * 0.9 + processing_time * 0.1 |
| ) |
| |
| def get_stats(self) -> Dict: |
| """Get statistics with safe defaults""" |
| stats = self.stats.copy() |
| |
| |
| total = stats.get("total_processed", 0) |
| blocked = stats.get("blocked_actions", 0) |
| autonomous = stats.get("autonomous_executions", 0) |
| |
| stats["blocked_percentage"] = round(blocked / total * 100, 1) if total > 0 else 0.0 |
| stats["autonomous_percentage"] = round(autonomous / total * 100, 1) if total > 0 else 0.0 |
| stats["processing_speed"] = f"{stats.get('avg_processing_time', 0)*1000:.0f}ms" |
| |
| |
| defaults = { |
| "risk_distribution": {"CRITICAL": 0, "HIGH": 0, "MEDIUM": 0, "LOW": 0, "SAFE": 0}, |
| "system_health": "β
Optimal", |
| "license_distribution": {"OSS": 0, "TRIAL": 0, "ENTERPRISE": 0} |
| } |
| |
| for key, value in defaults.items(): |
| if key not in stats: |
| stats[key] = value |
| |
| return stats |
| |
| def generate_trial_license(self, email: str) -> Dict: |
| """Generate trial license""" |
| if not email or "@" not in email: |
| return { |
| "success": False, |
| "message": "Please enter a valid email address" |
| } |
| |
| license_key = f"ARF-TRIAL-{hashlib.sha256(email.encode()).hexdigest()[:8].upper()}" |
| |
| return { |
| "success": True, |
| "license_key": license_key, |
| "message": "π 14-Day Trial License Generated!", |
| "expires": (datetime.now() + timedelta(days=14)).strftime("%Y-%m-%d"), |
| "features": [ |
| "Mechanical gate evaluation", |
| "Enterprise dashboard", |
| "Basic audit trail" |
| ] |
| } |
|
|
| |
| |
| |
|
|
| DEMO_SCENARIOS = [ |
| { |
| "id": "high_risk", |
| "name": "π₯ High-Risk Database Operation", |
| "action": "DROP DATABASE production_users CASCADE", |
| "context": {"environment": "production", "criticality": "critical"} |
| }, |
| { |
| "id": "safe_deploy", |
| "name": "β
Safe Service Deployment", |
| "action": "deploy_service payment_api:v2.3.1 to staging with 25% canary", |
| "context": {"environment": "staging", "service": "payment_api", "canary": 25} |
| }, |
| { |
| "id": "config_change", |
| "name": "π§ Configuration Update", |
| "action": "UPDATE config SET timeout_ms=30000 WHERE service='api'", |
| "context": {"environment": "production", "service": "api"} |
| } |
| ] |
|
|
| |
| |
| |
|
|
| def create_demo_interface(): |
| """Create the demo interface""" |
| |
| |
| arf_engine = ARFEngine() |
| |
| |
| try: |
| stats = arf_engine.get_stats() |
| except Exception as e: |
| print(f"Error getting stats: {e}") |
| stats = { |
| "total_processed": 0, |
| "blocked_percentage": 0.0, |
| "autonomous_percentage": 0.0, |
| "processing_speed": "0ms" |
| } |
| |
| |
| total_processed = stats.get("total_processed", 0) |
| blocked_percentage = stats.get("blocked_percentage", 0.0) |
| autonomous_percentage = stats.get("autonomous_percentage", 0.0) |
| processing_speed = stats.get("processing_speed", "0ms") |
| |
| with gr.Blocks( |
| title="ARF 3.3.9 - OSS vs Enterprise Demo", |
| theme=gr.themes.Soft(), |
| css=""" |
| .gradio-container { |
| max-width: 1400px; |
| margin: 0 auto; |
| font-family: -apple-system, BlinkMacSystemFont, sans-serif; |
| } |
| .demo-card { |
| border-radius: 10px; |
| padding: 20px; |
| margin-bottom: 20px; |
| box-shadow: 0 2px 8px rgba(0,0,0,0.1); |
| } |
| .oss-card { |
| border: 2px solid #1E88E5; |
| background: linear-gradient(135deg, #E3F2FD 0%, #BBDEFB 100%); |
| } |
| .enterprise-card { |
| border: 2px solid #FFB300; |
| background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%); |
| } |
| .stat-card { |
| background: white; |
| padding: 15px; |
| border-radius: 8px; |
| text-align: center; |
| box-shadow: 0 2px 4px rgba(0,0,0,0.1); |
| } |
| .gate-passed { |
| background: #E8F5E9; |
| border-left: 4px solid #4CAF50; |
| padding: 10px; |
| margin: 5px 0; |
| border-radius: 4px; |
| } |
| .gate-failed { |
| background: #FFEBEE; |
| border-left: 4px solid #F44336; |
| padding: 10px; |
| margin: 5px 0; |
| border-radius: 4px; |
| } |
| """ |
| ) as demo: |
| |
| |
| gr.Markdown(""" |
| # π€ Agentic Reliability Framework (ARF) 3.3.9 |
| ### From Advisory to Mechanical Enforcement |
| """) |
| |
| |
| gr.Markdown(f""" |
| <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 20px 0;"> |
| <div class="stat-card"> |
| <div style="font-size: 0.9em; color: #1E88E5; margin-bottom: 5px;">Total Assessments</div> |
| <div style="font-size: 2em; font-weight: bold; color: #1E88E5;">{total_processed}</div> |
| </div> |
| |
| <div class="stat-card"> |
| <div style="font-size: 0.9em; color: #F44336; margin-bottom: 5px;">Risks Blocked</div> |
| <div style="font-size: 2em; font-weight: bold; color: #F44336;">{blocked_percentage}%</div> |
| </div> |
| |
| <div class="stat-card"> |
| <div style="font-size: 0.9em; color: #4CAF50; margin-bottom: 5px;">Autonomous Rate</div> |
| <div style="font-size: 2em; font-weight: bold; color: #4CAF50;">{autonomous_percentage}%</div> |
| </div> |
| |
| <div class="stat-card"> |
| <div style="font-size: 0.9em; color: #FF9800; margin-bottom: 5px;">Processing Speed</div> |
| <div style="font-size: 2em; font-weight: bold; color: #FF9800;">{processing_speed}</div> |
| </div> |
| </div> |
| """) |
| |
| |
| with gr.Row(): |
| with gr.Column(scale=2): |
| |
| scenario_select = gr.Dropdown( |
| choices=[s["name"] for s in DEMO_SCENARIOS], |
| label="Select Demo Scenario", |
| value=DEMO_SCENARIOS[0]["name"] |
| ) |
| |
| |
| action_input = gr.Textbox( |
| label="Action to Evaluate", |
| value=DEMO_SCENARIOS[0]["action"], |
| lines=2 |
| ) |
| |
| |
| context_input = gr.Textbox( |
| label="Context (JSON)", |
| value=json.dumps(DEMO_SCENARIOS[0]["context"], indent=2), |
| lines=3 |
| ) |
| |
| |
| license_input = gr.Textbox( |
| label="Enterprise License Key (Optional)", |
| placeholder="Enter ARF-TRIAL-XXXXXXX or leave blank for OSS", |
| value="" |
| ) |
| |
| |
| with gr.Row(): |
| process_btn = gr.Button("π Process Action", variant="primary", size="lg") |
| clear_btn = gr.Button("π Clear", variant="secondary") |
| |
| with gr.Column(scale=1): |
| |
| gr.Markdown("### Quick Examples") |
| quick_examples = gr.Radio( |
| choices=["High Risk", "Medium Risk", "Low Risk"], |
| label="Risk Level", |
| value="High Risk" |
| ) |
| |
| |
| gr.Markdown("### License Status") |
| license_status = gr.HTML(""" |
| <div style="background: #E3F2FD; padding: 15px; border-radius: 8px; text-align: center;"> |
| <div style="color: #1E88E5; font-weight: bold; margin-bottom: 5px;">π΅ ARF OSS Edition</div> |
| <div style="color: #666; font-size: 0.9em;">Advisory Mode - No license required</div> |
| </div> |
| """) |
| |
| |
| with gr.Row(): |
| with gr.Column(scale=1): |
| oss_output = gr.HTML(label="π΅ ARF OSS Results") |
| |
| with gr.Column(scale=1): |
| enterprise_output = gr.HTML(label="π‘ ARF Enterprise Results") |
| |
| |
| comparison_output = gr.HTML(label="π Side-by-Side Comparison") |
| |
| |
| with gr.Accordion("π Get 14-Day Trial License", open=False): |
| with gr.Row(): |
| with gr.Column(scale=1): |
| email_input = gr.Textbox( |
| label="Work Email", |
| placeholder="you@company.com" |
| ) |
| trial_btn = gr.Button("Get Trial License", variant="primary") |
| |
| with gr.Column(scale=2): |
| trial_output = gr.JSON(label="Your Trial License") |
| |
| |
| def process_action(scenario_name, action_text, context_text, license_key, quick_example): |
| """Process an action""" |
| try: |
| |
| if quick_example == "High Risk": |
| action_text = "DELETE FROM users WHERE created_at < '2023-01-01'" |
| context_text = '{"environment": "production"}' |
| elif quick_example == "Medium Risk": |
| action_text = "ALTER TABLE payments ADD COLUMN metadata JSONB" |
| context_text = '{"environment": "staging"}' |
| elif quick_example == "Low Risk": |
| action_text = "SELECT COUNT(*) FROM logs" |
| context_text = '{"environment": "development"}' |
| |
| |
| for scenario in DEMO_SCENARIOS: |
| if scenario["name"] == scenario_name: |
| action_text = scenario["action"] |
| context_text = json.dumps(scenario["context"]) |
| break |
| |
| |
| try: |
| context = json.loads(context_text) if context_text.strip() else {} |
| except: |
| context = {"environment": "production"} |
| |
| |
| result = arf_engine.assess_action(action_text, context, license_key) |
| |
| |
| oss_html = create_oss_display(result) |
| enterprise_html = create_enterprise_display(result) |
| comparison_html = create_comparison_display(result) |
| |
| |
| license_info = result["license_info"] |
| if license_info.get("valid"): |
| status_html = f""" |
| <div style="background: #E8F5E9; padding: 15px; border-radius: 8px; text-align: center;"> |
| <div style="color: #2E7D32; font-weight: bold; margin-bottom: 5px;">β
{license_info['name']} License</div> |
| <div style="color: #666; font-size: 0.9em;">{license_info['message']}</div> |
| </div> |
| """ |
| else: |
| status_html = """ |
| <div style="background: #E3F2FD; padding: 15px; border-radius: 8px; text-align: center;"> |
| <div style="color: #1E88E5; font-weight: bold; margin-bottom: 5px;">π΅ ARF OSS Edition</div> |
| <div style="color: #666; font-size: 0.9em;">Advisory Mode - No license required</div> |
| </div> |
| """ |
| |
| return oss_html, enterprise_html, comparison_html, status_html |
| |
| except Exception as e: |
| error_html = f""" |
| <div style="background: #FFEBEE; padding: 20px; border-radius: 10px; color: #D32F2F;"> |
| <h4 style="margin-top: 0;">β Error Processing Action</h4> |
| <p>{str(e)}</p> |
| </div> |
| """ |
| return error_html, error_html, error_html, "" |
| |
| def create_oss_display(result): |
| """Create OSS display""" |
| risk = result["risk_assessment"] |
| policy = result["policy_result"] |
| |
| return f""" |
| <div class="demo-card oss-card"> |
| <h3 style="margin: 0 0 15px 0; color: #1E88E5;">π΅ ARF OSS 3.3.9</h3> |
| |
| <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px;"> |
| <div style="text-align: center; padding: 10px; background: white; border-radius: 6px;"> |
| <div style="font-size: 0.9em; color: #1E88E5;">Reliability</div> |
| <div style="font-size: 1.5em; font-weight: bold; color: #1E88E5;">{(1-risk.score):.1%}</div> |
| </div> |
| |
| <div style="text-align: center; padding: 10px; background: white; border-radius: 6px;"> |
| <div style="font-size: 0.9em; color: {risk.color};">Risk Level</div> |
| <div style="font-size: 1.5em; font-weight: bold; color: {risk.color};">{risk.level.value}</div> |
| </div> |
| |
| <div style="text-align: center; padding: 10px; background: white; border-radius: 6px;"> |
| <div style="font-size: 0.9em; color: #1E88E5;">Confidence</div> |
| <div style="font-size: 1.5em; font-weight: bold; color: #1E88E5;">{risk.confidence:.1%}</div> |
| </div> |
| </div> |
| |
| <div style="background: white; padding: 15px; border-radius: 8px; margin-bottom: 15px; border-left: 4px solid {risk.color};"> |
| <h4 style="margin: 0 0 10px 0; color: #333;">π‘ Recommendation</h4> |
| <p style="margin: 0; font-size: 1.1em; font-weight: 500;">{result['recommendation']}</p> |
| </div> |
| |
| <div style="background: #FFF3E0; padding: 15px; border-radius: 8px;"> |
| <h4 style="margin: 0 0 10px 0; color: #E65100;">β οΈ OSS Limitations</h4> |
| <ul style="margin: 0; padding-left: 20px; color: #E65100;"> |
| <li>Human decision required for all actions</li> |
| <li>No mechanical enforcement</li> |
| <li>{policy['total_violations']} policy violation(s) detected</li> |
| <li>Processing time: {result['processing_time']}s</li> |
| </ul> |
| </div> |
| </div> |
| """ |
| |
| def create_enterprise_display(result): |
| """Create Enterprise display""" |
| risk = result["risk_assessment"] |
| gates = result["gate_results"] |
| license_info = result["license_info"] |
| |
| |
| required_gates = [g for g in gates if g.required] |
| passed_required = sum(1 for g in required_gates if g.passed) |
| |
| |
| gates_html = "" |
| for gate in gates: |
| gate_class = "gate-passed" if gate.passed else "gate-failed" |
| gates_html += f""" |
| <div class="{gate_class}"> |
| <div style="display: flex; align-items: center;"> |
| <span style="font-size: 20px; margin-right: 10px;">{gate.icon}</span> |
| <div> |
| <div style="font-weight: 500;">{gate.name}</div> |
| <div style="font-size: 0.9em; color: #666;">{gate.message}</div> |
| </div> |
| </div> |
| </div> |
| """ |
| |
| return f""" |
| <div class="demo-card enterprise-card"> |
| <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;"> |
| <h3 style="margin: 0; color: #FF8F00;">π‘ ARF Enterprise 3.3.9</h3> |
| <span style="background: rgba(255, 179, 0, 0.1); padding: 5px 10px; border-radius: 15px; color: #FF8F00; font-weight: 500;"> |
| {license_info.get('name', 'OSS')} |
| </span> |
| </div> |
| |
| <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px;"> |
| <div style="text-align: center; padding: 10px; background: white; border-radius: 6px;"> |
| <div style="font-size: 0.9em; color: #FF8F00;">License Tier</div> |
| <div style="font-size: 1.2em; font-weight: bold; color: #FF8F00;">{license_info.get('name', 'OSS')}</div> |
| </div> |
| |
| <div style="text-align: center; padding: 10px; background: white; border-radius: 6px;"> |
| <div style="font-size: 0.9em; color: #FF8F00;">Gates Passed</div> |
| <div style="font-size: 1.5em; font-weight: bold; color: #FF8F00;">{passed_required}/{len(required_gates)}</div> |
| </div> |
| |
| <div style="text-align: center; padding: 10px; background: white; border-radius: 6px;"> |
| <div style="font-size: 0.9em; color: #FF8F00;">Enforcement</div> |
| <div style="font-size: 1.1em; font-weight: bold; color: #FF8F00;"> |
| {license_info.get('enforcement', 'ADVISORY').replace('_', ' ').title()} |
| </div> |
| </div> |
| </div> |
| |
| <div style="margin-bottom: 20px;"> |
| <h4 style="margin: 0 0 10px 0; color: #FF8F00;">Mechanical Gates</h4> |
| {gates_html} |
| </div> |
| |
| <div style="background: #E8F5E9; padding: 15px; border-radius: 8px;"> |
| <h4 style="margin: 0 0 10px 0; color: #2E7D32;">π Enterprise Benefits</h4> |
| <ul style="margin: 0; padding-left: 20px; color: #2E7D32;"> |
| <li>Mechanical enforcement with automated gates</li> |
| <li>Processing time: {result['processing_time']}s</li> |
| <li>{license_info.get('message', 'Enterprise-grade protection')}</li> |
| </ul> |
| </div> |
| </div> |
| """ |
| |
| def create_comparison_display(result): |
| """Create comparison display""" |
| policy = result["policy_result"] |
| gates = result["gate_results"] |
| license_info = result["license_info"] |
| |
| oss_can_execute = not policy.get("blocked", False) |
| all_gates_passed = all(g.passed for g in gates if g.required) |
| |
| if all_gates_passed and license_info.get("valid"): |
| enterprise_auth = "AUTONOMOUS_EXECUTION" |
| elif license_info.get("valid"): |
| enterprise_auth = "ADVISORY_ONLY" |
| else: |
| enterprise_auth = "OSS_ONLY" |
| |
| return f""" |
| <div class="demo-card" style="background: white;"> |
| <h3 style="margin: 0 0 20px 0; text-align: center; color: #333;">π Side-by-Side Comparison</h3> |
| |
| <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px;"> |
| <div style="text-align: center;"> |
| <div style="background: #E3F2FD; padding: 20px; border-radius: 10px; margin-bottom: 15px;"> |
| <h4 style="color: #1E88E5; margin: 0 0 10px 0;">π΅ OSS 3.3.9</h4> |
| <div style="font-size: 48px; color: #1E88E5; margin-bottom: 10px;"> |
| {'β οΈ' if not oss_can_execute else 'β
'} |
| </div> |
| <div style="font-weight: bold; color: {'#F44336' if not oss_can_execute else '#4CAF50'};"> |
| {'Advisory Only' if not oss_can_execute else 'Can Execute'} |
| </div> |
| </div> |
| </div> |
| |
| <div style="text-align: center;"> |
| <div style="background: #FFF8E1; padding: 20px; border-radius: 10px; margin-bottom: 15px;"> |
| <h4 style="color: #FFB300; margin: 0 0 10px 0;">π‘ Enterprise</h4> |
| <div style="font-size: 48px; color: #FFB300; margin-bottom: 10px;"> |
| {'β
' if enterprise_auth == 'AUTONOMOUS_EXECUTION' else 'π€' if enterprise_auth == 'ADVISORY_ONLY' else 'π΅'} |
| </div> |
| <div style="font-weight: bold; color: {'#4CAF50' if enterprise_auth == 'AUTONOMOUS_EXECUTION' else '#FF9800' if enterprise_auth == 'ADVISORY_ONLY' else '#1E88E5'};"> |
| {enterprise_auth.replace('_', ' ').title()} |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <div style="background: linear-gradient(135deg, #FFB30020 0%, #1E88E520 100%); padding: 20px; border-radius: 10px;"> |
| <h4 style="text-align: center; margin-top: 0; color: #333;">π― Enterprise Value Proposition</h4> |
| <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin: 15px 0;"> |
| <div style="text-align: center; padding: 15px; background: white; border-radius: 8px;"> |
| <div style="font-size: 0.9em; color: #666; margin-bottom: 5px;">Risk Reduction</div> |
| <div style="font-size: 1.8em; font-weight: bold; color: #4CAF50;">92%</div> |
| </div> |
| <div style="text-align: center; padding: 15px; background: white; border-radius: 8px;"> |
| <div style="font-size: 0.9em; color: #666; margin-bottom: 5px;">Decision Speed</div> |
| <div style="font-size: 1.8em; font-weight: bold; color: #4CAF50;">100x</div> |
| </div> |
| <div style="text-align: center; padding: 15px; background: white; border-radius: 8px;"> |
| <div style="font-size: 0.9em; color: #666; margin-bottom: 5px;">False Positives</div> |
| <div style="font-size: 1.8em; font-weight: bold; color: #4CAF50;">-85%</div> |
| </div> |
| <div style="text-align: center; padding: 15px; background: white; border-radius: 8px;"> |
| <div style="font-size: 0.9em; color: #666; margin-bottom: 5px;">OpEx Reduction</div> |
| <div style="font-size: 1.8em; font-weight: bold; color: #4CAF50;">-75%</div> |
| </div> |
| </div> |
| </div> |
| </div> |
| """ |
| |
| def generate_trial(email): |
| """Generate trial license""" |
| return arf_engine.generate_trial_license(email) |
| |
| def clear_inputs(): |
| """Clear all inputs""" |
| return DEMO_SCENARIOS[0]["action"], json.dumps(DEMO_SCENARIOS[0]["context"], indent=2), "", "High Risk", "", "", "", "" |
| |
| def update_scenario(scenario_name): |
| """Update inputs based on scenario""" |
| for scenario in DEMO_SCENARIOS: |
| if scenario["name"] == scenario_name: |
| return scenario["action"], json.dumps(scenario["context"], indent=2) |
| return "", "{}" |
| |
| |
| process_btn.click( |
| process_action, |
| [scenario_select, action_input, context_input, license_input, quick_examples], |
| [oss_output, enterprise_output, comparison_output, license_status] |
| ) |
| |
| clear_btn.click( |
| clear_inputs, |
| outputs=[action_input, context_input, license_input, quick_examples, oss_output, enterprise_output, comparison_output, license_status] |
| ) |
| |
| scenario_select.change( |
| update_scenario, |
| [scenario_select], |
| [action_input, context_input] |
| ) |
| |
| trial_btn.click( |
| generate_trial, |
| [email_input], |
| [trial_output] |
| ) |
| |
| |
| demo.load( |
| lambda: process_action( |
| DEMO_SCENARIOS[0]["name"], |
| DEMO_SCENARIOS[0]["action"], |
| json.dumps(DEMO_SCENARIOS[0]["context"]), |
| "", |
| "High Risk" |
| ), |
| outputs=[oss_output, enterprise_output, comparison_output, license_status] |
| ) |
| |
| return demo |
|
|
| |
| |
| |
|
|
| if __name__ == "__main__": |
| print("\nπ Starting ARF 3.3.9 Demo") |
| |
| try: |
| demo = create_demo_interface() |
| demo.launch( |
| server_name="0.0.0.0", |
| server_port=7860, |
| share=False, |
| debug=False, |
| show_error=True |
| ) |
| except Exception as e: |
| print(f"β Error launching demo: {e}") |
| traceback.print_exc() |
| |
| |
| with gr.Blocks() as fallback: |
| gr.Markdown(""" |
| # π€ ARF 3.3.9 Demo |
| The main demo is experiencing technical difficulties. |
| |
| **Key Value Proposition:** |
| - **OSS**: Advisory recommendations only |
| - **Enterprise**: Mechanical enforcement with automated gates |
| |
| **Visit [arf.dev](https://arf.dev) for the full demo.** |
| """) |
| fallback.launch() |