File size: 19,337 Bytes
deff797 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
<!DOCTYPE html>
<html>
<head>
<title>Context-Aware Profanity Handler - Interactive Demo</title>
<style>
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 20px;
background: #f5f5f7;
}
.header {
max-width: 1400px;
margin: 0 auto 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40px;
border-radius: 12px;
color: white;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.header h1 { margin: 0 0 10px; font-size: 36px; }
.header p { margin: 0; opacity: 0.95; font-size: 18px; }
.container {
max-width: 1400px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.panel {
background: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.panel.full { grid-column: 1 / -1; }
h2 {
margin-top: 0;
color: #1d1d1f;
font-size: 24px;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.input-group {
margin: 20px 0;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #1d1d1f;
}
textarea, select {
width: 100%;
padding: 12px;
border: 2px solid #d2d2d7;
border-radius: 8px;
font-size: 15px;
font-family: inherit;
transition: border-color 0.2s;
}
textarea:focus, select:focus {
outline: none;
border-color: #667eea;
}
textarea { min-height: 120px; resize: vertical; }
.checkbox-group {
display: flex;
gap: 20px;
margin: 20px 0;
}
.checkbox-group label {
display: flex;
align-items: center;
gap: 8px;
font-weight: 500;
}
input[type="checkbox"] {
width: 18px;
height: 18px;
cursor: pointer;
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 14px 32px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
transition: transform 0.2s, box-shadow 0.2s;
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
}
button:active {
transform: translateY(0);
}
.badge {
display: inline-block;
padding: 6px 12px;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
margin: 4px;
}
.badge.safe { background: #d1f4e0; color: #0f5132; }
.badge.mild { background: #fff3cd; color: #997404; }
.badge.explicit { background: #f8d7da; color: #842029; }
.badge.slur { background: #f5c2c7; color: #58151c; }
.badge.threat { background: #ea868f; color: #58151c; }
.comparison {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-top: 20px;
}
.comparison-item {
padding: 15px;
background: #f5f5f7;
border-radius: 8px;
border-left: 4px solid #667eea;
}
.comparison-item h4 {
margin-top: 0;
color: #667eea;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.comparison-item pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
font-size: 14px;
line-height: 1.6;
}
.metrics {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin: 20px 0;
}
.metric {
background: #f5f5f7;
padding: 20px;
border-radius: 8px;
text-align: center;
}
.metric-value {
font-size: 32px;
font-weight: 700;
color: #667eea;
margin: 10px 0;
}
.metric-label {
font-size: 13px;
color: #86868b;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.log-viewer {
background: #1d1d1f;
color: #f5f5f7;
padding: 20px;
border-radius: 8px;
font-family: 'Courier New', monospace;
font-size: 13px;
max-height: 400px;
overflow-y: auto;
}
.log-entry {
margin: 10px 0;
padding: 10px;
background: rgba(255,255,255,0.05);
border-radius: 4px;
}
.log-redacted {
color: #ff9f0a;
}
.log-verbatim {
color: #30d158;
}
.example-box {
background: linear-gradient(135deg, #e0e7ff 0%, #f0e7ff 100%);
padding: 20px;
border-radius: 8px;
margin: 20px 0;
border-left: 4px solid #667eea;
}
.example-box h3 {
margin-top: 0;
color: #1d1d1f;
}
.tab-container {
margin-top: 20px;
}
.tabs {
display: flex;
gap: 10px;
border-bottom: 2px solid #d2d2d7;
margin-bottom: 20px;
}
.tab {
padding: 10px 20px;
cursor: pointer;
border: none;
background: none;
font-size: 15px;
font-weight: 600;
color: #86868b;
border-bottom: 3px solid transparent;
transition: all 0.2s;
}
.tab.active {
color: #667eea;
border-bottom-color: #667eea;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.hidden { display: none !important; }
.ai-scores {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 10px;
margin: 15px 0;
}
.ai-score {
background: #f5f5f7;
padding: 12px;
border-radius: 6px;
text-align: center;
}
.ai-score-label {
font-size: 11px;
color: #86868b;
text-transform: uppercase;
}
.ai-score-value {
font-size: 20px;
font-weight: 700;
color: #1d1d1f;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="header">
<h1>π§© Context-Aware Profanity Handler</h1>
<p>Interactive demonstration of context-aware profanity detection, delexicalization, and audit logging</p>
</div>
<div class="container">
<!-- Input Panel -->
<div class="panel">
<h2>π Input</h2>
<div class="example-box">
<h3>π‘ Example Use Case</h3>
<p><strong>Scenario:</strong> A user wants to generate a report about an asset with an explicit song title.</p>
<p><strong>Input:</strong> "Report on asset: <em>Do You Want to Fuck Me Tonight</em>"</p>
<p><strong>Context:</strong> Song Title (Entity Name)</p>
</div>
<div class="input-group">
<label for="text">Text to Analyze:</label>
<textarea id="text" placeholder="Enter text here...">Report on asset: Do You Want to Fuck Me Tonight</textarea>
</div>
<div class="input-group">
<label for="context">Content Category:</label>
<select id="context">
<option value="song_title">Song Title</option>
<option value="entity_name">Entity Name</option>
<option value="brand_name">Brand Name</option>
<option value="user_input">User Input</option>
</select>
</div>
<div class="checkbox-group">
<label>
<input type="checkbox" id="strict_mode"> Strict Mode
</label>
<label>
<input type="checkbox" id="use_ai" checked> Use AI Classifier
</label>
<label>
<input type="checkbox" id="include_explicit"> Include in Export
</label>
</div>
<button onclick="analyzeText()">π Analyze Text</button>
</div>
<!-- Results Panel -->
<div class="panel">
<h2>π Analysis Results</h2>
<div id="results" style="color: #86868b; text-align: center; padding: 40px;">
Run an analysis to see results here
</div>
</div>
<!-- Comparison Panel -->
<div class="panel full hidden" id="comparisonPanel">
<h2>π Text Comparison</h2>
<div class="comparison">
<div class="comparison-item">
<h4>π Original Text (Verbatim)</h4>
<pre id="originalText"></pre>
</div>
<div class="comparison-item">
<h4>β¨ Delexicalized Text (Safe for AI)</h4>
<pre id="safeText"></pre>
</div>
<div class="comparison-item">
<h4>π€ Export Text (Based on Preference)</h4>
<pre id="exportText"></pre>
</div>
<div class="comparison-item">
<h4>π Detected Words</h4>
<pre id="detectedWords"></pre>
</div>
</div>
</div>
<!-- Logs Panel -->
<div class="panel full hidden" id="logsPanel">
<h2>π Audit Logs Visualization</h2>
<div class="tab-container">
<div class="tabs">
<button class="tab active" onclick="switchTab('redacted')">π Redacted Logs (Analytics)</button>
<button class="tab" onclick="switchTab('verbatim')">π Verbatim Logs (Compliance)</button>
</div>
<div class="tab-content active" id="redacted-tab">
<p style="color: #86868b; margin-bottom: 15px;">
<strong>Purpose:</strong> Safe for analytics and monitoring. Contains metadata without sensitive content.
</p>
<div class="log-viewer" id="redactedLogs">
<div class="log-redacted">Waiting for analysis...</div>
</div>
</div>
<div class="tab-content" id="verbatim-tab">
<p style="color: #86868b; margin-bottom: 15px;">
<strong>Purpose:</strong> Full audit trail for compliance. Access should be restricted (RBAC).
</p>
<div class="log-viewer" id="verbatimLogs">
<div class="log-verbatim">Waiting for analysis...</div>
</div>
</div>
</div>
</div>
</div>
<script>
let currentRequestId = null;
function switchTab(tabName) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
event.target.classList.add('active');
document.getElementById(tabName + '-tab').classList.add('active');
}
async function analyzeText() {
const text = document.getElementById('text').value;
const context = document.getElementById('context').value;
const strict_mode = document.getElementById('strict_mode').checked;
const use_ai = document.getElementById('use_ai').checked;
const include_explicit_in_export = document.getElementById('include_explicit').checked;
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = '<div style="text-align: center; padding: 20px;">β³ Analyzing...</div>';
try {
const response = await fetch('/analyze', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, context, strict_mode, use_ai, include_explicit_in_export })
});
const data = await response.json();
currentRequestId = data.request_id;
// Display results
displayResults(data, text);
// Show comparison panel
displayComparison(text, data);
// Load and display logs
await displayLogs(data.request_id);
} catch (error) {
resultsDiv.innerHTML = `<div style="color: #d1180b;">Error: ${error.message}</div>`;
}
}
function displayResults(data, originalText) {
const resultsDiv = document.getElementById('results');
let html = '<div class="metrics">';
html += `<div class="metric">
<div class="metric-label">Profanity</div>
<div class="metric-value">${data.contains_profanity ? 'β οΈ' : 'β
'}</div>
</div>`;
html += `<div class="metric">
<div class="metric-label">Toxicity</div>
<div class="metric-value"><span class="badge ${data.toxicity_level}">${data.toxicity_level.toUpperCase()}</span></div>
</div>`;
html += '</div>';
html += `<div style="margin: 20px 0;">
<strong>Message:</strong>
<div style="padding: 15px; background: #f5f5f7; border-radius: 8px; margin-top: 10px;">
${data.message}
</div>
</div>`;
if (data.ai_confidence) {
html += '<div style="margin: 20px 0;"><strong>AI Confidence Scores:</strong><div class="ai-scores">';
for (const [label, score] of Object.entries(data.ai_confidence)) {
html += `<div class="ai-score">
<div class="ai-score-label">${label}</div>
<div class="ai-score-value">${(score * 100).toFixed(1)}%</div>
</div>`;
}
html += '</div></div>';
}
html += `<div style="margin-top: 20px; font-size: 13px; color: #86868b;">
Request ID: <code>${data.request_id}</code>
</div>`;
resultsDiv.innerHTML = html;
}
function displayComparison(originalText, data) {
document.getElementById('comparisonPanel').classList.remove('hidden');
document.getElementById('originalText').textContent = originalText;
document.getElementById('safeText').textContent = data.safe_text;
document.getElementById('exportText').textContent = data.export_text;
document.getElementById('detectedWords').textContent =
data.detected_words && data.detected_words.length > 0
? data.detected_words.join(', ')
: 'None detected';
}
async function displayLogs(requestId) {
document.getElementById('logsPanel').classList.remove('hidden');
try {
// Load redacted logs
const redactedResponse = await fetch('/logs/redacted');
const redactedData = await redactedResponse.json();
const redactedLogs = document.getElementById('redactedLogs');
if (redactedData.logs && redactedData.logs.length > 0) {
redactedLogs.innerHTML = redactedData.logs.slice(-5).reverse().map(log => `
<div class="log-entry log-redacted">
<strong>Request ID:</strong> ${log.request_id}<br>
<strong>Timestamp:</strong> ${new Date(log.timestamp).toLocaleString()}<br>
<strong>Context:</strong> ${log.context}<br>
<strong>Profanity:</strong> ${log.contains_profanity ? 'Yes' : 'No'}<br>
<strong>Toxicity:</strong> ${log.toxicity_level}<br>
<strong>Text Hash:</strong> ${log.text_hash}<br>
<strong>Text Length:</strong> ${log.text_length} chars
</div>
`).join('');
}
// Load verbatim log for current request
const verbatimResponse = await fetch(`/logs/verbatim/${requestId}`);
const verbatimData = await verbatimResponse.json();
const verbatimLogs = document.getElementById('verbatimLogs');
if (verbatimData.request_id) {
verbatimLogs.innerHTML = `
<div class="log-entry log-verbatim">
<strong>β οΈ COMPLIANCE ACCESS ONLY β οΈ</strong><br><br>
<strong>Request ID:</strong> ${verbatimData.request_id}<br>
<strong>Timestamp:</strong> ${new Date(verbatimData.timestamp).toLocaleString()}<br>
<strong>Context:</strong> ${verbatimData.context}<br>
<strong>Original Text:</strong> ${verbatimData.original_text}<br>
<strong>Safe Text:</strong> ${verbatimData.safe_text}<br>
<strong>Profanity:</strong> ${verbatimData.contains_profanity ? 'Yes' : 'No'}<br>
<strong>Toxicity:</strong> ${verbatimData.toxicity_level}
</div>
`;
} else {
verbatimLogs.innerHTML = '<div class="log-verbatim">Verbatim logs not available or disabled</div>';
}
} catch (error) {
console.error('Error loading logs:', error);
}
}
</script>
</body>
</html>
|