-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
328 lines (295 loc) · 17.6 KB
/
index.html
File metadata and controls
328 lines (295 loc) · 17.6 KB
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
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LexiFi - Visual Document Story</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #0f172a; /* slate-900 */
}
.flowchart-node {
transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}
.flowchart-node:hover {
transform: translateY(-4px) scale(1.02);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}
.flowchart-connector {
height: 40px;
width: 3px;
background-color: #334155; /* slate-700 */
margin: 0 auto;
}
.modal-content {
animation: slide-up 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slide-up {
from {
transform: translateY(30px) scale(0.98);
opacity: 0;
}
to {
transform: translateY(0) scale(1);
opacity: 1;
}
}
.loader {
width: 50px;
height: 50px;
border-radius: 50%;
border: 5px solid rgba(255, 255, 255, 0.2);
border-top-color: #3b82f6;
animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
</style>
</head>
<body class="text-gray-200">
<div id="app" class="min-h-screen p-4 md:p-8">
<!-- Header -->
<header class="text-center mb-8 md:mb-12">
<h1 class="text-4xl md:text-5xl font-bold text-white tracking-tight">
<i class="fas fa-gavel text-blue-400"></i> Lexi<span class="text-blue-400">Fi</span>
</h1>
<p class="text-slate-400 mt-2 text-lg">Your AI-powered visual guide to legal documents.</p>
</header>
<!-- Input Section -->
<div id="input-section" class="max-w-3xl mx-auto bg-slate-800/50 border border-slate-700 rounded-2xl p-6 shadow-2xl">
<h2 class="text-2xl font-bold text-white mb-4">Analyze Your Document</h2>
<textarea id="legal-text" class="w-full h-48 bg-slate-900 border border-slate-600 rounded-lg p-3 text-slate-300 text-sm focus:ring-2 focus:ring-blue-500 transition-colors" placeholder="Paste your legal document here..."></textarea>
<button id="generate-btn" class="mt-4 w-full bg-blue-600 text-white font-bold py-3 px-6 rounded-lg hover:bg-blue-500 transition-all duration-300 shadow-lg flex items-center justify-center text-lg disabled:bg-slate-500 disabled:cursor-not-allowed">
<span id="btn-text"><i class="fas fa-rocket mr-2"></i>Generate Visual Story</span>
<div id="btn-loader" class="hidden w-6 h-6 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
</button>
</div>
<!-- Result Section -->
<div id="result-section" class="hidden mt-12 max-w-2xl mx-auto">
<h2 class="text-3xl font-bold text-center mb-8">Document Story</h2>
<div id="flowchart-container"></div>
</div>
<!-- Modal -->
<div id="clause-modal" class="hidden fixed inset-0 bg-black bg-opacity-70 z-50 flex items-center justify-center p-4">
<div class="modal-content bg-slate-800 border border-slate-700 rounded-2xl shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col">
<div id="modal-header" class="p-5 border-b border-slate-700 flex justify-between items-center">
<!-- Header content will be injected here -->
</div>
<div id="modal-body" class="p-6 space-y-5 overflow-y-auto">
<!-- Body content will be injected here -->
</div>
<div class="p-4 bg-slate-900/50 border-t border-slate-700">
<button id="close-modal-btn" class="w-full bg-slate-600 text-white font-bold py-2 px-4 rounded-lg hover:bg-slate-500 transition-colors">Close</button>
</div>
</div>
</div>
</div>
<script>
// --- DOM Elements ---
const ui = {
legalTextInput: document.getElementById('legal-text'),
generateBtn: document.getElementById('generate-btn'),
btnText: document.getElementById('btn-text'),
btnLoader: document.getElementById('btn-loader'),
inputSection: document.getElementById('input-section'),
resultSection: document.getElementById('result-section'),
flowchartContainer: document.getElementById('flowchart-container'),
clauseModal: document.getElementById('clause-modal'),
modalHeader: document.getElementById('modal-header'),
modalBody: document.getElementById('modal-body'),
closeModalBtn: document.getElementById('close-modal-btn'),
};
// --- State ---
let fullDocumentText = '';
let currentClauses = [];
// --- Event Listeners ---
ui.generateBtn.addEventListener('click', handleGenerateClick);
ui.closeModalBtn.addEventListener('click', hideClauseModal);
ui.clauseModal.addEventListener('click', (e) => {
if (e.target === ui.clauseModal) {
hideClauseModal();
}
});
// --- Sample Text ---
ui.legalTextInput.value = `This End-User License Agreement ("EULA") is a legal agreement between you and Example Corp.
1. GRANT OF LICENSE. Example Corp grants you a revocable, non-exclusive, non-transferable, limited license to download, install and use the Software solely for your personal, non-commercial purposes.
2. RESTRICTIONS. You agree not to license, sell, rent, lease, or commercially exploit the Software. You may not reverse engineer the software.
3. TERMINATION. Example Corp may, in its sole discretion, at any time and for any or no reason, terminate this Agreement with or without prior notice.
4. OBLIGATION TO PAY. You are obligated to pay all fees associated with the premium version of the software within 30 days of purchase.
5. LIMITATION OF LIABILITY. In no event shall Example Corp be liable for any special, incidental, indirect, or consequential damages whatsoever. Your sole remedy is to stop using the software.`;
// --- Core Logic ---
async function handleGenerateClick() {
fullDocumentText = ui.legalTextInput.value.trim();
if (!fullDocumentText) return;
setLoading(true);
const systemPrompt = `You are a legal document analyst. Your job is to deconstruct a legal document into its primary clauses. For each clause, provide a title, its category, a simple summary, and an "Explain Like I'm 5" (ELI5) analogy. Strictly follow the requested JSON schema.`;
const schema = {
type: "OBJECT", properties: { clauses: { type: "ARRAY", items: {
type: "OBJECT", properties: {
"title": { type: "STRING" },
"originalText": { type: "STRING" },
"category": { type: "STRING", enum: ["Grant of Rights", "Restriction", "Obligation", "Liability Waiver", "Termination", "General"] },
"summary": { type: "STRING" },
"eli5": { type: "STRING" }
}, required: ["title", "originalText", "category", "summary", "eli5"]
}}}, required: ["clauses"]
};
const payload = {
contents: [{ parts: [{ text: `Analyze this document:\n\n${fullDocumentText}` }] }],
systemInstruction: { parts: [{ text: systemPrompt }] },
generationConfig: { responseMimeType: "application/json", responseSchema: schema, temperature: 0.2 }
};
try {
const data = await callGeminiAPI(payload);
currentClauses = data.clauses;
renderFlowchart(currentClauses);
ui.resultSection.classList.remove('hidden');
} catch (error) {
console.error("Error:", error);
alert("Failed to analyze the document. The AI may be busy or the content could not be processed. Please try again.");
} finally {
setLoading(false);
}
}
// --- Rendering ---
const categoryConfig = {
"Grant of Rights": { color: 'green', icon: 'fa-check-circle' },
"Restriction": { color: 'red', icon: 'fa-ban' },
"Obligation": { color: 'blue', icon: 'fa-tasks' },
"Liability Waiver": { color: 'red', icon: 'fa-shield-alt' },
"Termination": { color: 'yellow', icon: 'fa-times-circle' },
"General": { color: 'slate', icon: 'fa-file-alt' }
};
const colorClasses = {
red: { bg: 'bg-red-900/50', border: 'border-red-500', text: 'text-red-300' },
green: { bg: 'bg-green-900/50', border: 'border-green-500', text: 'text-green-300' },
blue: { bg: 'bg-blue-900/50', border: 'border-blue-500', text: 'text-blue-300' },
yellow: { bg: 'bg-yellow-900/50', border: 'border-yellow-500', text: 'text-yellow-300' },
slate: { bg: 'bg-slate-700', border: 'border-slate-500', text: 'text-slate-300' },
};
function renderFlowchart(clauses) {
ui.flowchartContainer.innerHTML = '';
clauses.forEach((clause, index) => {
const config = categoryConfig[clause.category] || categoryConfig["General"];
const colors = colorClasses[config.color] || colorClasses['slate'];
// Create Node
const node = document.createElement('div');
node.className = `flowchart-node cursor-pointer p-5 rounded-xl border-2 ${colors.bg} ${colors.border} shadow-lg`;
node.innerHTML = `
<div class="flex items-center">
<i class="fas ${config.icon} ${colors.text} text-2xl mr-4"></i>
<div>
<h3 class="text-lg font-bold text-white">${clause.title}</h3>
<p class="text-sm font-semibold ${colors.text}">${clause.category}</p>
</div>
</div>
`;
node.addEventListener('click', () => showClauseModal(clause));
ui.flowchartContainer.appendChild(node);
// Create Connector (if not the last node)
if (index < clauses.length - 1) {
const connector = document.createElement('div');
connector.className = 'flowchart-connector';
ui.flowchartContainer.appendChild(connector);
}
});
}
function showClauseModal(clause) {
const config = categoryConfig[clause.category] || categoryConfig["General"];
const colors = colorClasses[config.color] || colorClasses['slate'];
// Header
ui.modalHeader.innerHTML = `
<div class="flex items-center">
<i class="fas ${config.icon} ${colors.text} text-2xl mr-4"></i>
<div>
<h2 class="text-xl font-bold text-white">${clause.title}</h2>
<p class="text-sm font-semibold ${colors.text}">${clause.category}</p>
</div>
</div>
<button id="modal-close-icon" class="text-slate-400 hover:text-white text-2xl">×</button>
`;
document.getElementById('modal-close-icon').addEventListener('click', hideClauseModal);
// Body
const contentId = `feature-content-${Math.random().toString(36).substr(2, 9)}`;
ui.modalBody.innerHTML = `
<div>
<h4 class="font-semibold text-slate-400 text-sm mb-1 uppercase tracking-wider">Summary</h4>
<p class="text-slate-300">${clause.summary}</p>
</div>
<div class="bg-slate-900/50 p-4 rounded-lg border border-slate-700">
<h4 class="font-semibold text-blue-300 text-sm mb-1">Explain Like I'm 5</h4>
<p class="text-slate-300">${clause.eli5}</p>
</div>
<div class="pt-4 space-y-4">
<button id="suggest-btn" class="w-full text-sm font-semibold bg-slate-700/80 text-blue-300 py-2 px-3 rounded-md hover:bg-slate-700 transition-colors flex items-center justify-center">✨ Suggest a Fairer Version</button>
<div class="flex gap-2">
<input type="text" id="question-input" class="flex-grow bg-slate-900 text-sm border border-slate-600 rounded-lg p-2 text-slate-300 focus:ring-2 focus:ring-blue-500" placeholder="Ask a follow-up question...">
<button id="ask-btn" class="bg-blue-600 text-white font-bold py-2 px-4 rounded-lg text-sm">Ask</button>
</div>
<div id="${contentId}" class="mt-2 text-sm text-slate-300"></div>
</div>
`;
document.getElementById('suggest-btn').addEventListener('click', (e) => handleSuggestEdit(clause.originalText, e.currentTarget, contentId));
document.getElementById('ask-btn').addEventListener('click', () => handleAskQuestion(document.getElementById('question-input').value, contentId));
ui.clauseModal.classList.remove('hidden');
}
function hideClauseModal() {
ui.clauseModal.classList.add('hidden');
}
// --- API & Helper Functions ---
function setLoading(isLoading) {
ui.generateBtn.disabled = isLoading;
if (isLoading) {
ui.btnText.classList.add('hidden');
ui.btnLoader.classList.remove('hidden');
} else {
ui.btnText.classList.remove('hidden');
ui.btnLoader.classList.add('hidden');
}
}
async function callGeminiAPI(payload) {
const apiKey = "AIzaSyCtM5-dGBjF-wizeepnoTkstNpWGaia1N4";
const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`;
const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
if (!response.ok) throw new Error(`API Error: ${response.status}`);
const result = await response.json();
if (payload.generationConfig.responseMimeType === "application/json") {
return JSON.parse(result.candidates[0].content.parts[0].text);
}
return result.candidates[0].content.parts[0].text;
}
async function handleSuggestEdit(originalClauseText, button, contentId) {
const contentEl = document.getElementById(contentId);
button.disabled = true;
contentEl.innerHTML = `<div class="flex justify-center p-4"><div class="w-5 h-5 border-2 border-slate-400 border-t-transparent rounded-full animate-spin"></div></div>`;
const prompt = `Here is a clause from a legal document:\n---\n${originalClauseText}\n---\nPlease rewrite this clause to be more balanced and fair for the party who is agreeing to the terms. Then, provide a brief, bulleted list explaining the key changes you made. Format the output cleanly with Markdown.`;
const payload = { contents: [{ parts: [{ text: prompt }] }], generationConfig: { temperature: 0.5 } };
try {
let newText = await callGeminiAPI(payload);
newText = newText.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>').replace(/\n/g, '<br>').replace(/•/g, '<br>•');
contentEl.innerHTML = `<div class="bg-slate-900/50 p-3 rounded-lg">${newText}</div>`;
} catch(error) {
contentEl.innerHTML = `<p class="text-red-400 text-center">Could not generate a suggestion.</p>`;
} finally {
button.disabled = false;
}
}
async function handleAskQuestion(question, contentId) {
if (!question) return;
const contentEl = document.getElementById(contentId);
contentEl.innerHTML = `<div class="flex justify-center p-4"><div class="w-5 h-5 border-2 border-slate-400 border-t-transparent rounded-full animate-spin"></div></div>`;
const prompt = `Based on the following legal document, provide a clear, concise answer to the user's question. Use only the information within the document.\n\nDOCUMENT:\n---\n${fullDocumentText}\n---\n\nQUESTION: "${question}"`;
const payload = { contents: [{ parts: [{ text: prompt }] }], generationConfig: { temperature: 0.1 } };
try {
const answer = await callGeminiAPI(payload);
contentEl.innerHTML = `<div class="bg-slate-900/50 p-3 rounded-lg">${answer.replace(/\n/g, '<br>')}</div>`;
} catch (error) {
contentEl.innerHTML = `<p class="text-red-400 text-center">Could not get an answer.</p>`;
}
}
</script>
</body>
</html>