djuna commited on
Commit
2bae4ee
·
verified ·
1 Parent(s): 9d4f479

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +413 -19
index.html CHANGED
@@ -1,19 +1,413 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Chat Template Tester</title>
7
+ <script src="https://mozilla.github.io/nunjucks/files/nunjucks.min.js"></script>
8
+ <style>
9
+ /* CSS Reset and Base styles */
10
+ * {
11
+ margin: 0;
12
+ padding: 0;
13
+ box-sizing: border-box;
14
+ }
15
+
16
+ body {
17
+ font-family: system-ui, -apple-system, sans-serif;
18
+ background-color: #f5f5f5;
19
+ line-height: 1.6;
20
+ color: #333;
21
+ }
22
+
23
+ /* Container */
24
+ .container {
25
+ max-width: 1200px;
26
+ margin: 0 auto;
27
+ padding: 20px;
28
+ }
29
+
30
+ @media (max-width: 768px) {
31
+ .container {
32
+ padding: 12px;
33
+ }
34
+ }
35
+
36
+ /* Typography */
37
+ h1 {
38
+ font-size: clamp(1.5rem, 4vw, 2rem);
39
+ margin-bottom: 1.5rem;
40
+ color: #333;
41
+ }
42
+
43
+ h2 {
44
+ font-size: clamp(1.2rem, 3vw, 1.5rem);
45
+ margin-bottom: 1rem;
46
+ color: #444;
47
+ }
48
+
49
+ /* Card Layout */
50
+ .card {
51
+ background: white;
52
+ padding: clamp(16px, 3vw, 24px);
53
+ border-radius: 12px;
54
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
55
+ margin-bottom: 20px;
56
+ }
57
+
58
+ /* Form Elements */
59
+ .input-group {
60
+ display: flex;
61
+ gap: 8px;
62
+ margin-bottom: 12px;
63
+ }
64
+
65
+ @media (max-width: 600px) {
66
+ .input-group {
67
+ flex-direction: column;
68
+ }
69
+
70
+ .input-group select,
71
+ .input-group input,
72
+ .input-group button {
73
+ width: 100%;
74
+ }
75
+ }
76
+
77
+ textarea,
78
+ input[type="text"],
79
+ select {
80
+ padding: 12px;
81
+ border: 1.5px solid #ddd;
82
+ border-radius: 8px;
83
+ font-size: 14px;
84
+ background: #fff;
85
+ transition: border-color 0.2s;
86
+ }
87
+
88
+ textarea:focus,
89
+ input[type="text"]:focus,
90
+ select:focus {
91
+ outline: none;
92
+ border-color: #4CAF50;
93
+ }
94
+
95
+ select {
96
+ min-width: 120px;
97
+ }
98
+
99
+ @media (max-width: 600px) {
100
+ select {
101
+ min-width: 100%;
102
+ }
103
+ }
104
+
105
+ textarea {
106
+ width: 100%;
107
+ min-height: 120px;
108
+ resize: vertical;
109
+ font-family: inherit;
110
+ }
111
+
112
+ /* Buttons */
113
+ button {
114
+ background-color: #4CAF50;
115
+ color: white;
116
+ padding: 12px 20px;
117
+ border: none;
118
+ border-radius: 8px;
119
+ cursor: pointer;
120
+ font-size: 14px;
121
+ font-weight: 500;
122
+ transition: all 0.2s;
123
+ white-space: nowrap;
124
+ }
125
+
126
+ button:hover {
127
+ background-color: #45a049;
128
+ transform: translateY(-1px);
129
+ }
130
+
131
+ button:active {
132
+ transform: translateY(0);
133
+ }
134
+
135
+ button.secondary {
136
+ background-color: #6c757d;
137
+ }
138
+
139
+ button.danger {
140
+ background-color: #dc3545;
141
+ }
142
+
143
+ button.small {
144
+ padding: 6px 12px;
145
+ font-size: 13px;
146
+ }
147
+
148
+ /* Messages Section */
149
+ .message {
150
+ background-color: #f8f9fa;
151
+ padding: 16px;
152
+ border-radius: 8px;
153
+ margin-bottom: 12px;
154
+ display: flex;
155
+ align-items: center;
156
+ gap: 12px;
157
+ flex-wrap: wrap;
158
+ }
159
+
160
+ @media (max-width: 600px) {
161
+ .message {
162
+ flex-direction: column;
163
+ align-items: stretch;
164
+ }
165
+ }
166
+
167
+ .message-content {
168
+ flex-grow: 1;
169
+ min-width: 200px;
170
+ word-break: break-word;
171
+ }
172
+
173
+ .message strong {
174
+ color: #495057;
175
+ margin-right: 8px;
176
+ display: inline-block;
177
+ }
178
+
179
+ .message-actions {
180
+ display: flex;
181
+ gap: 6px;
182
+ flex-wrap: wrap;
183
+ }
184
+
185
+ @media (max-width: 600px) {
186
+ .message-actions {
187
+ justify-content: flex-end;
188
+ margin-top: 8px;
189
+ }
190
+ }
191
+
192
+ /* Configuration section */
193
+ .config-group {
194
+ display: flex;
195
+ align-items: center;
196
+ gap: 16px;
197
+ margin-bottom: 16px;
198
+ flex-wrap: wrap;
199
+ }
200
+
201
+ @media (max-width: 600px) {
202
+ .config-group {
203
+ flex-direction: column;
204
+ align-items: stretch;
205
+ }
206
+ }
207
+
208
+ /* Output section */
209
+ #output {
210
+ white-space: pre-wrap;
211
+ background-color: #f8f9fa;
212
+ padding: 16px;
213
+ border-radius: 8px;
214
+ font-family: monospace;
215
+ border: 1.5px solid #ddd;
216
+ overflow-x: auto;
217
+ font-size: 14px;
218
+ line-height: 1.5;
219
+ }
220
+
221
+ /* Checkbox styling */
222
+ .checkbox-wrapper {
223
+ display: flex;
224
+ align-items: center;
225
+ gap: 8px;
226
+ }
227
+
228
+ input[type="checkbox"] {
229
+ width: 16px;
230
+ height: 16px;
231
+ }
232
+
233
+ /* Loading state */
234
+ .loading {
235
+ opacity: 0.7;
236
+ pointer-events: none;
237
+ }
238
+
239
+ /* Focus styles for accessibility */
240
+ :focus-visible {
241
+ outline: 2px solid #4CAF50;
242
+ outline-offset: 2px;
243
+ }
244
+ </style>
245
+ </head>
246
+ <body>
247
+ <div class="container">
248
+ <h1>Chat Template Tester</h1>
249
+
250
+ <div class="card">
251
+ <h2>Messages</h2>
252
+ <div class="input-group">
253
+ <select id="role">
254
+ <option value="user">User</option>
255
+ <option value="assistant">Assistant</option>
256
+ <option value="system">System</option>
257
+ </select>
258
+ <input type="text" id="content" placeholder="Type your message here..." style="flex-grow: 1">
259
+ <button onclick="addMessage()">Add Message</button>
260
+ </div>
261
+ <div id="messages"></div>
262
+ </div>
263
+
264
+ <div class="card">
265
+ <h2>Configuration</h2>
266
+ <div class="config-group">
267
+ <div class="checkbox-wrapper">
268
+ <input type="checkbox" id="addGenerationPrompt">
269
+ <label for="addGenerationPrompt">Add Generation Prompt</label>
270
+ </div>
271
+ <div class="input-group" style="margin-bottom: 0; flex-grow: 1;">
272
+ <input type="text" id="bosToken" placeholder="BOS Token (e.g., <s>)" style="flex-grow: 1;">
273
+ </div>
274
+ </div>
275
+
276
+ <h2>Template</h2>
277
+ <textarea id="template" placeholder="Enter your template here..."></textarea>
278
+
279
+ <button onclick="applyTemplate()" style="margin-top: 16px">Apply Template</button>
280
+ </div>
281
+
282
+ <div class="card">
283
+ <h2>Output</h2>
284
+ <pre id="output"></pre>
285
+ </div>
286
+ </div>
287
+
288
+ <script>
289
+ let messages = [];
290
+ let editingIndex = null;
291
+
292
+ function addMessage() {
293
+ const role = document.getElementById('role').value;
294
+ const content = document.getElementById('content').value;
295
+ if (content.trim()) {
296
+ messages.push({ role, content });
297
+ updateMessageDisplay();
298
+ document.getElementById('content').value = '';
299
+ document.getElementById('content').focus();
300
+ }
301
+ }
302
+
303
+ function updateMessageDisplay() {
304
+ const messagesDiv = document.getElementById('messages');
305
+ messagesDiv.innerHTML = messages.map((msg, index) => `
306
+ <div class="message">
307
+ <div class="message-content">
308
+ <strong>${msg.role}:</strong>
309
+ ${editingIndex === index
310
+ ? `<input type="text" id="editContent" value="${msg.content}" style="width: 100%;">`
311
+ : msg.content}
312
+ </div>
313
+ <div class="message-actions">
314
+ ${editingIndex === index
315
+ ? `<button class="small" onclick="saveEdit(${index})">Save</button>`
316
+ : `<button class="small secondary" onclick="editMessage(${index})">Edit</button>`}
317
+ <button class="small danger" onclick="removeMessage(${index})">Remove</button>
318
+ <button class="small" onclick="moveMessageUp(${index})" ${index === 0 ? 'disabled' : ''}>↑</button>
319
+ <button class="small" onclick="moveMessageDown(${index})" ${index === messages.length - 1 ? 'disabled' : ''}>↓</button>
320
+ </div>
321
+ </div>
322
+ `).join('');
323
+ }
324
+
325
+ function removeMessage(index) {
326
+ messages.splice(index, 1);
327
+ updateMessageDisplay();
328
+ }
329
+
330
+ function editMessage(index) {
331
+ editingIndex = index;
332
+ updateMessageDisplay();
333
+ setTimeout(() => {
334
+ const editInput = document.getElementById('editContent');
335
+ if (editInput) {
336
+ editInput.focus();
337
+ editInput.select();
338
+ }
339
+ }, 0);
340
+ }
341
+
342
+ function saveEdit(index) {
343
+ const newContent = document.getElementById('editContent').value;
344
+ if (newContent.trim()) {
345
+ messages[index].content = newContent;
346
+ editingIndex = null;
347
+ updateMessageDisplay();
348
+ }
349
+ }
350
+
351
+ function moveMessageUp(index) {
352
+ if (index > 0) {
353
+ [messages[index - 1], messages[index]] = [messages[index], messages[index - 1]];
354
+ updateMessageDisplay();
355
+ }
356
+ }
357
+
358
+ function moveMessageDown(index) {
359
+ if (index < messages.length - 1) {
360
+ [messages[index], messages[index + 1]] = [messages[index + 1], messages[index]];
361
+ updateMessageDisplay();
362
+ }
363
+ }
364
+
365
+ function applyTemplate() {
366
+ const template = document.getElementById('template').value;
367
+ const addGenerationPrompt = document.getElementById('addGenerationPrompt').checked;
368
+ const bosToken = document.getElementById('bosToken').value;
369
+
370
+ const context = {
371
+ messages: messages,
372
+ add_generation_prompt: addGenerationPrompt,
373
+ bos_token: bosToken,
374
+ };
375
+
376
+ try {
377
+ document.getElementById('output').parentElement.classList.add('loading');
378
+ const result = nunjucks.renderString(template, context);
379
+ const decodedResult = result.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
380
+ document.getElementById('output').textContent = decodedResult;
381
+ } catch (error) {
382
+ document.getElementById('output').textContent = `Error: ${error.message}`;
383
+ } finally {
384
+ document.getElementById('output').parentElement.classList.remove('loading');
385
+ }
386
+ }
387
+
388
+ // Keyboard shortcuts and accessibility
389
+ document.addEventListener('keydown', function(e) {
390
+ // Add message on Enter in the content input
391
+ if (e.target.id === 'content' && e.key === 'Enter' && !e.shiftKey) {
392
+ e.preventDefault();
393
+ addMessage();
394
+ }
395
+
396
+ // Save edit on Enter in the edit input
397
+ if (e.target.id === 'editContent' && e.key === 'Enter' && !e.shiftKey) {
398
+ e.preventDefault();
399
+ saveEdit(editingIndex);
400
+ }
401
+
402
+ // Cancel edit on Escape
403
+ if (e.key === 'Escape' && editingIndex !== null) {
404
+ editingIndex = null;
405
+ updateMessageDisplay();
406
+ }
407
+ });
408
+
409
+ // Initialize
410
+ updateMessageDisplay();
411
+ </script>
412
+ </body>
413
+ </html>