Spaces:
Sleeping
Sleeping
milestone 4 completed: multi-level simplification UI, key term highlighting, admin dashboard, updated README
ced18a1 Download templates/view_document.html from fathima-ai01/contract-simplifier: direct link, hf CLI and curl.
- Browser
- Download file 38.5 kB
-
https://huggingface.co/spaces/fathima-ai01/contract-simplifier/resolve/main/templates/view_document.html
- Command line
-
hf download hf://spaces/fathima-ai01/contract-simplifier/templates/view_document.html
-
curl -L -o view_document.html https://huggingface.co/spaces/fathima-ai01/contract-simplifier/resolve/main/templates/view_document.html
38.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contract Language Simplifier - {{ doc.title }}</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
/* ── Design tokens ── */
:root {
--primary: #007bff;
--primary-dark: #0056b3;
--primary-light: #e6f2ff;
--primary-pale: #f0f7ff;
--text-dark: #1a1a2e;
--text-mid: #374151;
--text-gray: #6b7280;
--bg-body: #f5f7fb;
--bg-card: #ffffff;
--border: #e5e7eb;
--green: #10b981;
--amber: #f59e0b;
--red: #ef4444;
--radius-card: 16px;
--radius-pill: 50px;
--shadow-sm: 0 2px 8px rgba(0, 0, 0, .06);
--shadow-md: 0 4px 20px rgba(0, 0, 0, .10);
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background: var(--bg-body);
color: var(--text-dark);
min-height: 100vh;
}
/* ── App Shell ── */
.app-shell {
max-width: 1100px;
margin: 0 auto;
padding: 24px 20px 48px;
}
/* ── Top Header ── */
.app-header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
border-radius: var(--radius-card) var(--radius-card) 0 0;
padding: 18px 28px;
display: flex;
justify-content: space-between;
align-items: center;
color: #fff;
}
.app-header h1 {
font-size: 1.15rem;
font-weight: 700;
letter-spacing: .01em;
}
.header-dots {
display: flex;
gap: 7px;
}
.dot {
width: 11px;
height: 11px;
background: rgba(255, 255, 255, .55);
border-radius: 50%;
}
/* ── Navigation tabs (User View / Admin Dashboard) ── */
.nav-tabs {
background: var(--bg-card);
border-bottom: 2px solid var(--border);
display: flex;
gap: 0;
padding: 0 28px;
}
.nav-tab {
padding: 14px 24px;
font-size: 0.9rem;
font-weight: 600;
color: var(--text-gray);
cursor: pointer;
border-bottom: 3px solid transparent;
margin-bottom: -2px;
text-decoration: none;
transition: color .15s, border-color .15s;
user-select: none;
}
.nav-tab.active {
color: var(--primary);
border-bottom-color: var(--primary);
}
.nav-tab:hover {
color: var(--primary);
}
/* ── Main card body ── */
.main-card {
background: var(--bg-card);
border-radius: 0 0 var(--radius-card) var(--radius-card);
box-shadow: var(--shadow-md);
padding: 28px;
}
.back-link {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--text-gray);
text-decoration: none;
font-size: 0.85rem;
font-weight: 500;
margin-bottom: 20px;
}
.back-link:hover {
color: var(--primary);
}
/* ── Simplification Level Cards ── */
.mode-section-title {
font-size: 0.82rem;
font-weight: 700;
color: var(--text-gray);
text-transform: uppercase;
letter-spacing: .08em;
margin-bottom: 14px;
}
.mode-cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 14px;
margin-bottom: 28px;
}
.mode-card {
border: 2px solid var(--border);
border-radius: 14px;
padding: 20px 16px;
text-align: center;
cursor: pointer;
transition: all .2s ease;
background: #fff;
position: relative;
}
.mode-card:hover {
border-color: var(--primary);
box-shadow: 0 0 0 4px var(--primary-light);
transform: translateY(-2px);
}
.mode-card.selected {
border-color: var(--primary);
background: var(--primary-pale);
box-shadow: 0 0 0 4px var(--primary-light);
}
.mode-icon {
width: 48px;
height: 48px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 12px;
font-size: 1.4rem;
background: var(--primary-light);
color: var(--primary);
transition: background .2s;
}
.mode-card.selected .mode-icon {
background: var(--primary);
color: #fff;
}
.mode-name {
font-weight: 700;
font-size: 0.95rem;
color: var(--text-dark);
margin-bottom: 4px;
}
.mode-sub {
font-size: 0.76rem;
color: var(--text-gray);
}
/* ── Doc title area ── */
.doc-heading {
border-left: 4px solid var(--primary);
padding-left: 14px;
margin-bottom: 22px;
}
.doc-heading h2 {
font-size: 1.15rem;
font-weight: 700;
color: var(--primary);
margin-bottom: 2px;
}
.doc-heading span {
font-size: 0.78rem;
color: var(--text-gray);
}
/* ── Simplify button row ── */
.action-row {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 28px;
flex-wrap: wrap;
}
.slider-wrap {
display: flex;
align-items: center;
gap: 10px;
flex: 1;
min-width: 180px;
}
.slider-label {
font-size: 0.82rem;
font-weight: 600;
color: var(--text-mid);
white-space: nowrap;
}
input[type=range] {
-webkit-appearance: none;
appearance: none;
width: 100%;
background: transparent;
cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 18px;
width: 18px;
border-radius: 50%;
background: var(--primary);
cursor: pointer;
margin-top: -6px;
box-shadow: 0 0 0 4px var(--primary-light);
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 6px;
background: #e5e7eb;
border-radius: 3px;
}
.btn-simplify {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
color: #fff;
border: none;
border-radius: var(--radius-pill);
padding: 11px 28px;
font-weight: 700;
font-size: 0.9rem;
cursor: pointer;
display: flex;
align-items: center;
gap: 8px;
transition: opacity .2s, transform .1s;
white-space: nowrap;
box-shadow: 0 4px 12px rgba(0, 123, 255, .3);
}
.btn-simplify:hover {
opacity: .88;
transform: translateY(-1px);
}
.btn-simplify:active {
transform: translateY(0);
}
.btn-simplify:disabled {
background: #b0bec5;
box-shadow: none;
cursor: not-allowed;
transform: none;
}
/* ── Two column panes ── */
.panes {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 28px;
}
.pane {
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
}
.pane-header {
background: var(--primary-pale);
border-bottom: 1px solid var(--border);
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
}
.pane-title {
font-weight: 700;
font-size: 0.85rem;
color: var(--primary);
}
.grade-badge {
background: #fff;
border: 1px solid var(--border);
color: var(--text-gray);
font-size: 0.72rem;
font-weight: 700;
padding: 3px 10px;
border-radius: 20px;
}
.mode-badge {
background: var(--primary);
color: #fff;
font-size: 0.72rem;
font-weight: 700;
padding: 3px 10px;
border-radius: 20px;
display: none;
}
.pane-body {
padding: 16px;
min-height: 200px;
font-size: 0.88rem;
line-height: 1.7;
color: var(--text-mid);
max-height: 340px;
overflow-y: auto;
}
.pane-body.html-mode {
white-space: normal;
word-wrap: break-word;
}
.pane-body:not(.html-mode) {
white-space: pre-wrap;
}
/* ── Legal term highlight & tooltip ── */
.legal-term {
background: #fff8e1;
border-bottom: 2px solid var(--amber);
border-radius: 2px;
cursor: help;
padding: 0 2px;
position: relative;
}
.legal-term::after {
content: attr(data-definition);
position: absolute;
bottom: calc(100% + 8px);
left: 50%;
transform: translateX(-50%);
background: #1e293b;
color: #f8fafc;
font-size: 0.75rem;
font-weight: 400;
line-height: 1.5;
padding: 8px 12px;
border-radius: 8px;
white-space: normal;
width: 240px;
z-index: 1000;
box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
opacity: 0;
pointer-events: none;
transition: opacity .18s;
}
.legal-term::before {
content: '';
position: absolute;
bottom: calc(100% + 3px);
left: 50%;
transform: translateX(-50%);
border: 5px solid transparent;
border-top-color: #1e293b;
opacity: 0;
pointer-events: none;
transition: opacity .18s;
}
.legal-term:hover::after,
.legal-term:focus::after,
.legal-term:hover::before,
.legal-term:focus::before {
opacity: 1;
}
/* ── Summary pane ── */
.summary-card {
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
margin-bottom: 28px;
}
.summary-header {
background: var(--primary-pale);
border-bottom: 1px solid var(--border);
padding: 12px 16px;
display: flex;
align-items: center;
gap: 8px;
font-weight: 700;
font-size: 0.85rem;
color: var(--primary);
}
.summary-body {
padding: 16px;
font-size: 0.88rem;
line-height: 1.7;
color: var(--text-mid);
white-space: pre-wrap;
}
/* ── Metrics ── */
.metrics-row {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
margin-bottom: 28px;
}
.metric-box {
background: var(--primary-pale);
border: 1px solid var(--primary-light);
border-radius: 10px;
padding: 14px;
text-align: center;
}
.metric-box .m-label {
font-size: 0.72rem;
color: var(--text-gray);
margin-bottom: 6px;
font-weight: 500;
}
.metric-box .m-value {
font-size: 1.4rem;
font-weight: 800;
color: var(--primary);
}
/* ── Bar chart ── */
.chart-section {
border-top: 1px solid var(--border);
padding-top: 20px;
margin-bottom: 28px;
}
.chart-title {
font-size: 0.82rem;
font-weight: 700;
color: var(--text-gray);
text-transform: uppercase;
letter-spacing: .06em;
margin-bottom: 12px;
}
.chart-bars {
display: flex;
align-items: flex-end;
justify-content: space-around;
height: 110px;
border-bottom: 2px solid var(--border);
gap: 20px;
}
.chart-bar-group {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
height: 100%;
}
.chart-bar {
width: 70px;
border-radius: 6px 6px 0 0;
transition: height .5s ease;
}
.chart-bar.original {
background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.chart-bar.simplified {
background: linear-gradient(180deg, var(--green) 0%, #059669 100%);
}
.chart-bar-label {
font-size: 0.72rem;
color: var(--text-gray);
font-weight: 500;
margin-top: 8px;
}
/* ── Legal Glossary section ── */
.glossary-section {
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
}
.glossary-section-header {
background: var(--primary-pale);
border-bottom: 1px solid var(--border);
padding: 14px 18px;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
}
.glossary-section-header h3 {
font-size: 0.92rem;
font-weight: 700;
color: var(--primary);
display: flex;
align-items: center;
gap: 8px;
}
.glossary-section-body {
padding: 18px;
}
/* Search bar */
.glossary-search-wrap {
position: relative;
margin-bottom: 16px;
}
.glossary-search {
width: 100%;
padding: 10px 44px 10px 16px;
border: 1px solid var(--border);
border-radius: var(--radius-pill);
font-family: inherit;
font-size: 0.85rem;
background: #fff;
outline: none;
transition: border-color .15s;
}
.glossary-search:focus {
border-color: var(--primary);
box-shadow: 0 0 0 3px var(--primary-light);
}
.glossary-search-btn {
position: absolute;
right: 6px;
top: 50%;
transform: translateY(-50%);
background: var(--primary);
color: #fff;
border: none;
border-radius: 50%;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
font-size: 0.8rem;
}
/* Term list */
.glossary-term-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.glossary-term-item {
border: 1px solid var(--border);
border-radius: 10px;
padding: 12px 16px;
background: #fff;
display: flex;
align-items: flex-start;
gap: 10px;
}
.glossary-term-icon {
width: 28px;
height: 28px;
background: var(--primary-light);
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
font-size: 0.75rem;
color: var(--primary);
font-weight: 700;
}
.glossary-term-text .gt-name {
font-weight: 700;
font-size: 0.85rem;
color: var(--primary);
margin-bottom: 2px;
}
.glossary-term-text .gt-def {
font-size: 0.78rem;
color: var(--text-gray);
line-height: 1.5;
}
.glossary-empty {
text-align: center;
color: var(--text-gray);
font-size: 0.85rem;
padding: 14px 0;
}
/* ── Utility ── */
.loading-text {
color: var(--text-gray);
font-style: italic;
}
@media (max-width: 700px) {
.panes {
grid-template-columns: 1fr;
}
.mode-cards {
grid-template-columns: 1fr;
}
.metrics-row {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<div class="app-shell">
<a class="back-link" href="/dashboard">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
<polyline points="15 18 9 12 15 6" />
</svg>
Back to Dashboard
</a>
<!-- Header -->
<div class="app-header">
<h1>Contract Language Simplifier</h1>
<div class="header-dots">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>
<!-- Nav tabs -->
<div class="nav-tabs">
<span class="nav-tab active" id="nav-user">User View</span>
<a class="nav-tab" href="/admin">Admin Dashboard</a>
</div>
<!-- Main card -->
<div class="main-card">
<!-- Simplification Level Cards -->
<p class="mode-section-title">Choose Simplification Level</p>
<div class="mode-cards">
<div class="mode-card" id="card-basic" onclick="selectMode('basic')">
<div class="mode-icon">👤</div>
<div class="mode-name">Basic</div>
<div class="mode-sub">Simplest language</div>
</div>
<div class="mode-card selected" id="card-intermediate" onclick="selectMode('intermediate')">
<div class="mode-icon">👥</div>
<div class="mode-name">Intermediate</div>
<div class="mode-sub">Balanced clarity</div>
</div>
<div class="mode-card" id="card-advanced" onclick="selectMode('advanced')">
<div class="mode-icon">🎓</div>
<div class="mode-name">Advanced</div>
<div class="mode-sub">Professional terms</div>
</div>
</div>
<!-- Document heading -->
<div class="doc-heading">
<h2>{{ doc.title }}</h2>
<span>Uploaded {{ doc.created_at.strftime('%B %d, %Y') if doc.created_at else 'recently' }}</span>
</div>
<!-- Simplify action row -->
<div class="action-row">
<div class="slider-wrap">
<span class="slider-label">Level:</span>
<input type="range" min="1" max="100" value="70" id="simplify-level">
<span id="level-val"
style="font-size:.8rem;font-weight:700;color:var(--primary);width:32px;text-align:right;">70</span>
</div>
<button class="btn-simplify" id="btn-simplify" onclick="processDocument('{{ doc._id }}')">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.5">
<polyline points="23 4 23 10 17 10" />
<polyline points="1 20 1 14 7 14" />
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15" />
</svg>
<span id="btn-text">Simplify Document</span>
</button>
<button class="btn-simplify" id="btn-summarize" onclick="summarizeOnly('{{ doc._id }}')"
style="background:linear-gradient(135deg,#6366f1 0%,#4338ca 100%); box-shadow:0 4px 12px rgba(99,102,241,.3);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.5">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
<line x1="16" y1="13" x2="8" y2="13" />
<line x1="16" y1="17" x2="8" y2="17" />
</svg>
<span id="sum-text">Summarize</span>
</button>
</div>
<!-- Original / Simplified panes -->
<div class="panes">
<div class="pane">
<div class="pane-header">
<span class="pane-title">📄 Original Text</span>
<span class="grade-badge" id="grade-original">Grade --</span>
</div>
<div class="pane-body html-mode" id="original-content">{{ doc.content }}</div>
</div>
<div class="pane">
<div class="pane-header">
<span class="pane-title">✨ Simplified Text</span>
<div style="display:flex;gap:6px;align-items:center;">
<span class="mode-badge" id="mode-badge"></span>
<span class="grade-badge" id="grade-simplified">Grade --</span>
</div>
</div>
<div class="pane-body" id="simplified-content">{% if doc.simplified_content %}{{
doc.simplified_content }}{% else %}<span class="loading-text">Click "Simplify Document" to
generate.</span>{% endif %}</div>
</div>
</div>
<!-- Summary -->
<div class="summary-card">
<div class="summary-header">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
<line x1="16" y1="13" x2="8" y2="13" />
<line x1="16" y1="17" x2="8" y2="17" />
</svg>
Document Summary
</div>
<div class="summary-body" id="summary-content">{% if doc.summary %}{{ doc.summary }}{% else %}<span
class="loading-text">No summary yet.</span>{% endif %}</div>
</div>
<!-- Metrics (hidden until first simplify) -->
<div class="metrics-row" id="metrics-display" style="display:none;">
<div class="metric-box">
<div class="m-label">⏱ Processing Time</div>
<div class="m-value" id="metric-time">--</div>
</div>
<div class="metric-box">
<div class="m-label">📉 Grade Reduction</div>
<div class="m-value" id="metric-reduction" style="color:var(--green);">--</div>
</div>
<div class="metric-box">
<div class="m-label">📝 Original Words</div>
<div class="m-value" id="metric-orig-words">--</div>
</div>
<div class="metric-box">
<div class="m-label">📝 Simplified Words</div>
<div class="m-value" id="metric-simp-words">--</div>
</div>
</div>
<!-- Readability bar chart -->
<div class="chart-section">
<p class="chart-title">Readability Grade Comparison</p>
<div class="chart-bars">
<div class="chart-bar-group">
<div class="chart-bar original" id="bar-original-inner" style="height:0;"></div>
<span class="chart-bar-label">Original</span>
</div>
<div class="chart-bar-group">
<div class="chart-bar simplified" id="bar-simplified-inner" style="height:0;"></div>
<span class="chart-bar-label">Simplified</span>
</div>
</div>
</div>
<!-- Legal Terms Glossary -->
<div class="glossary-section" id="glossary-section">
<div class="glossary-section-header" onclick="toggleGlossary()">
<h3>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20" />
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z" />
</svg>
Legal Terms Glossary
<span id="terms-count-badge"
style="background:var(--primary);color:#fff;font-size:0.7rem;padding:2px 8px;border-radius:20px;font-weight:700;"></span>
</h3>
<svg id="glossary-chevron" width="16" height="16" viewBox="0 0 24 24" fill="none"
stroke="var(--primary)" stroke-width="2.5" style="transition:transform .2s;">
<polyline points="6 9 12 15 18 9" />
</svg>
</div>
<div class="glossary-section-body" id="glossary-body">
<div id="terms-loading-msg" style="color:var(--text-gray);font-style:italic;font-size:.85rem;">🔍
Detecting legal terms…</div>
<!-- Search -->
<div class="glossary-search-wrap" id="glossary-search-wrap" style="display:none;">
<input class="glossary-search" id="glossary-search" type="text" placeholder="Search terms…"
oninput="filterGlossary(this.value)">
<button class="glossary-search-btn">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.5">
<circle cx="11" cy="11" r="8" />
<line x1="21" y1="21" x2="16.65" y2="16.65" />
</svg>
</button>
</div>
<div class="glossary-term-list" id="glossary-list"></div>
</div>
</div>
</div><!-- /main-card -->
</div><!-- /app-shell -->
<script>
/* ── State ── */
let selectedMode = 'intermediate';
let allTerms = [];
let glossaryOpen = true;
/* ── Mode Cards ── */
const modeCards = { basic: 'card-basic', intermediate: 'card-intermediate', advanced: 'card-advanced' };
function selectMode(mode) {
selectedMode = mode;
Object.values(modeCards).forEach(id => document.getElementById(id).classList.remove('selected'));
document.getElementById(modeCards[mode]).classList.add('selected');
}
/* ── Slider live value ── */
document.getElementById('simplify-level').addEventListener('input', function () {
document.getElementById('level-val').textContent = this.value;
});
/* ── Page load ── */
document.addEventListener('DOMContentLoaded', () => {
fetchReadability();
highlightLegalTerms();
});
/* ── Legal Term Highlighting ── */
async function highlightLegalTerms() {
const originalBox = document.getElementById('original-content');
const loadingMsg = document.getElementById('terms-loading-msg');
const rawText = originalBox.innerText || originalBox.textContent;
try {
const res = await fetch('/api/highlight_terms', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: rawText })
});
const data = await res.json();
loadingMsg.style.display = 'none';
if (data.success) {
/* Replace original text with highlighted HTML */
originalBox.innerHTML = data.highlighted_html;
allTerms = data.terms || [];
if (allTerms.length > 0) {
document.getElementById('glossary-search-wrap').style.display = 'block';
document.getElementById('terms-count-badge').textContent = allTerms.length + ' found';
renderTermList(allTerms);
} else {
document.getElementById('glossary-list').innerHTML = '<div class="glossary-empty">No legal terms detected in this document.</div>';
}
}
} catch (err) {
loadingMsg.style.display = 'none';
console.warn('Highlight error:', err);
}
}
function renderTermList(terms) {
const list = document.getElementById('glossary-list');
if (!terms.length) {
list.innerHTML = '<div class="glossary-empty">No matches found.</div>';
return;
}
list.innerHTML = terms.map(t => `
<div class="glossary-term-item">
<div class="glossary-term-icon">${(t.display_term || t.term)[0].toUpperCase()}</div>
<div class="glossary-term-text">
<div class="gt-name">${escHtml(t.display_term || t.term)}</div>
<div class="gt-def">${escHtml(t.definition)}</div>
</div>
</div>
`).join('');
}
function filterGlossary(query) {
const q = query.toLowerCase().trim();
const filtered = q ? allTerms.filter(t =>
t.term.includes(q) || t.definition.toLowerCase().includes(q)
) : allTerms;
renderTermList(filtered);
}
function toggleGlossary() {
glossaryOpen = !glossaryOpen;
document.getElementById('glossary-body').style.display = glossaryOpen ? 'block' : 'none';
document.getElementById('glossary-chevron').style.transform = glossaryOpen ? '' : 'rotate(-90deg)';
}
function escHtml(s) {
return String(s || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
}
/* ── Readability Chart ── */
function fetchReadability() {
const origText = document.getElementById('original-content').innerText;
const simpText = document.getElementById('simplified-content').innerText;
analyzeAndUpdate(origText, 'grade-original', 'bar-original-inner');
if (!simpText.includes('Click "Simplify"') && simpText.trim().length > 10) {
analyzeAndUpdate(simpText, 'grade-simplified', 'bar-simplified-inner');
}
}
function analyzeAndUpdate(text, gradeId, barId) {
fetch('/api/analyze', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
})
.then(r => r.json())
.then(data => {
if (data.success) {
const grade = Math.max(0, Math.round(data.readability.flesch_kincaid_grade));
document.getElementById(gradeId).textContent = 'Grade ' + grade;
const pct = Math.min(100, (grade / 15) * 100);
document.getElementById(barId).style.height = pct + '%';
}
})
.catch(() => { });
}
/* ── Simplify + Summarize ── */
async function processDocument(docId) {
const btn = document.getElementById('btn-simplify');
const btnText = document.getElementById('btn-text');
const simplBox = document.getElementById('simplified-content');
const summBox = document.getElementById('summary-content');
const level = document.getElementById('simplify-level').value;
const modeBadge = document.getElementById('mode-badge');
const metricsDiv = document.getElementById('metrics-display');
btn.disabled = true;
btnText.textContent = 'Processing…';
simplBox.innerHTML = '<span class="loading-text">✨ Simplifying with FLAN-T5 (' + selectedMode + ')…</span>';
summBox.innerHTML = '<span class="loading-text">📝 Generating summary…</span>';
metricsDiv.style.display = 'none';
modeBadge.style.display = 'none';
try {
const [simpRes, sumRes] = await Promise.all([
fetch(`/simplify/${docId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ level, simplification_mode: selectedMode })
}),
fetch(`/summarize/${docId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
]);
const simpData = await simpRes.json();
const sumData = await sumRes.json();
if (simpData.success) {
simplBox.innerText = simpData.simplified_content;
const labels = { basic: '📘 Basic', intermediate: '📗 Intermediate', advanced: '📕 Advanced' };
modeBadge.textContent = labels[simpData.simplification_mode] || simpData.simplification_mode;
modeBadge.style.display = 'inline-block';
if (simpData.metrics) {
document.getElementById('metric-time').textContent = simpData.metrics.processing_time + 's';
document.getElementById('metric-reduction').textContent = (simpData.metrics.reduction > 0 ? '-' : '') + simpData.metrics.reduction + ' grades';
document.getElementById('metric-orig-words').textContent = simpData.metrics.original_words;
document.getElementById('metric-simp-words').textContent = simpData.metrics.simplified_words;
metricsDiv.style.display = 'grid';
}
} else {
simplBox.innerHTML = `<span style="color:var(--red);">Error: ${simpData.message}</span>`;
}
if (sumData.success) {
summBox.innerText = sumData.summary;
} else {
summBox.innerHTML = `<span style="color:var(--red);">Error: ${sumData.message}</span>`;
}
fetchReadability();
} catch (err) {
simplBox.innerHTML = `<span style="color:var(--red);">Network error — check console.</span>`;
summBox.innerHTML = `<span style="color:var(--red);">Network error.</span>`;
} finally {
btn.disabled = false;
btnText.textContent = 'Simplify Again';
}
}
/* ── Summarize only ── */
async function summarizeOnly(docId) {
const sumBtn = document.getElementById('btn-summarize');
const sumText = document.getElementById('sum-text');
const summBox = document.getElementById('summary-content');
sumBtn.disabled = true;
sumText.textContent = 'Summarizing…';
summBox.innerHTML = '<span class="loading-text">📝 Generating summary…</span>';
try {
const res = await fetch(`/summarize/${docId}`, { method: 'POST', headers: { 'Content-Type': 'application/json' } });
const data = await res.json();
summBox.innerText = data.success ? data.summary : 'Error: ' + data.message;
} catch (err) {
summBox.innerHTML = '<span style="color:var(--red);">Network error.</span>';
} finally {
sumBtn.disabled = false;
sumText.textContent = 'Summarize';
}
}
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contract Language Simplifier - {{ doc.title }}</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
/* ── Design tokens ── */
:root {
--primary: #007bff;
--primary-dark: #0056b3;
--primary-light: #e6f2ff;
--primary-pale: #f0f7ff;
--text-dark: #1a1a2e;
--text-mid: #374151;
--text-gray: #6b7280;
--bg-body: #f5f7fb;
--bg-card: #ffffff;
--border: #e5e7eb;
--green: #10b981;
--amber: #f59e0b;
--red: #ef4444;
--radius-card: 16px;
--radius-pill: 50px;
--shadow-sm: 0 2px 8px rgba(0, 0, 0, .06);
--shadow-md: 0 4px 20px rgba(0, 0, 0, .10);
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
background: var(--bg-body);
color: var(--text-dark);
min-height: 100vh;
}
/* ── App Shell ── */
.app-shell {
max-width: 1100px;
margin: 0 auto;
padding: 24px 20px 48px;
}
/* ── Top Header ── */
.app-header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
border-radius: var(--radius-card) var(--radius-card) 0 0;
padding: 18px 28px;
display: flex;
justify-content: space-between;
align-items: center;
color: #fff;
}
.app-header h1 {
font-size: 1.15rem;
font-weight: 700;
letter-spacing: .01em;
}
.header-dots {
display: flex;
gap: 7px;
}
.dot {
width: 11px;
height: 11px;
background: rgba(255, 255, 255, .55);
border-radius: 50%;
}
/* ── Navigation tabs (User View / Admin Dashboard) ── */
.nav-tabs {
background: var(--bg-card);
border-bottom: 2px solid var(--border);
display: flex;
gap: 0;
padding: 0 28px;
}
.nav-tab {
padding: 14px 24px;
font-size: 0.9rem;
font-weight: 600;
color: var(--text-gray);
cursor: pointer;
border-bottom: 3px solid transparent;
margin-bottom: -2px;
text-decoration: none;
transition: color .15s, border-color .15s;