This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
425 lines (382 loc) · 13 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Auto MindMap</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"/>
<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
</head>
<style>
.prompt,
.mer_container,
.floating-input {
display: flex;
justify-content: center;
}
.floating-input {
position: fixed;
width: 80%;
bottom: 50px;
box-shadow: 8px 8px 20px rgba(0, 0, 0, 0.1);
border-radius: 15px;
}
.floating-input.anim::before, .floating-input.anim::after {
content: '';
position: absolute;
left: -2px;
top: -2px;
background: linear-gradient(45deg, #fb0094, #0000ff, #00ff00, #ffff00, #ff0000, #fb0094,
#0000ff, #00ff00, #ffff00, #ff0000);
background-size: 400%;
width: calc(100% + 4px);
height: calc(100% + 4px);
z-index: -1;
animation: steam 20s linear infinite;
}
@keyframes steam {
0% {
background-position: 0 0;
opacity: 0.15;
}
8% {
opacity: 0.4;
}
14% {
opacity: 1;
}
50% {
background-position: 400% 0;
}
100% {
background-position: 0 0;
}
}
.floating-input:after {
filter: blur(100px);
}
.floating-input input {
font-size: 18px;
width: 100%;
padding: 10px;
border: none;
}
form input:focus,
textarea:focus {
outline: none;
}
form input {
display: block;
width: 100%;
height: 100%;
border: none;
font-size: 18px;
border-bottom: 2px solid rgba(0, 0, 0, 0.12);
margin-top: 10px;
margin-bottom: 18px;
padding: 4px;
}
form textarea {
width: 100%;
box-sizing: border-box;
border-radius: 10px;
padding: 5px;
}
.settings {
margin-top: 25px;
display: flex;
justify-content: center;
cursor: pointer;
}
.settings details {
padding: 25px;
background-color: #fff;
position: absolute;
display: block;
width: 60%;
box-shadow: 8px 8px 20px rgba(0, 0, 0, 0.1);
border-radius: 15px;
}
.settings details summary {
text-align: center;
}
details {
transition: height ease-in 1s;
}
details[itemscope] {
height: inherit;
}
details form,
details textarea,
details select {
cursor: default;
margin-top: 10px;
}
.mer_container {
margin-top: 20vh;
}
#render {
width: 95%;
}
.mermaid svg {
max-width: 100% !important;
max-height: 85%;
}
</style>
<script>
mermaid.initialize({startOnLoad: false, theme: "dark"});
function checkAndReplaceLastLine(text) {
// Split the text into an array of lines
const lines = text.split('\n');
// Get the last line
const lastLine = lines[lines.length - 1];
// Check if the last line is "```"
if (lastLine === "```") {
// Replace the last line with an empty string
lines[lines.length - 1] = "";
}
// Join the lines back into a single text
return lines.join('\n');
}
document.addEventListener('DOMContentLoaded', function () {
const details = document.querySelector("#details");
details.addEventListener(
"click",
(event) => {
event.target.hasAttribute("open") ?
event.target.removeAttribute("open")
: event.target.setAttribute("open", "");
}
);
const endpoint = document.querySelector('#BaseURL');
const endpoint_val = localStorage.getItem("endpoint");
if (endpoint_val !== null) {
endpoint.value = endpoint_val;
}
endpoint.addEventListener(
"change",
(e) => {
localStorage.setItem("endpoint", e.target.value);
}
)
const template = document.querySelector('#template');
const template_val = localStorage.getItem("template");
if (template_val !== null) {
template.value = template_val;
}
template.addEventListener(
"change",
(e) => {
localStorage.setItem("template", e.target.value);
}
)
const model = document.querySelector('#model');
const model_val = localStorage.getItem("model");
if (model_val !== null) {
model.value = model_val;
}
model.addEventListener(
"change",
(e) => {
localStorage.setItem("model", e.target.value);
}
)
const custom_model = document.querySelector('#custom_model');
const custom_model_val = localStorage.getItem("custom_model");
if (custom_model_val !== null) {
custom_model.value = custom_model_val;
}
custom_model.addEventListener(
"change",
(e) => {
localStorage.setItem("custom_model", e.target.value);
}
)
const max_tokens = document.querySelector('#max_tokens');
const max_tokens_val = localStorage.getItem("max_tokens");
if (max_tokens_val !== null) {
max_tokens.value = max_tokens_val;
}
max_tokens.addEventListener(
"change",
(e) => {
localStorage.setItem("max_tokens", e.target.value);
}
)
const temperature = document.querySelector('#temp');
const temperature_val = localStorage.getItem("temperature");
if (temperature_val !== null) {
temperature.value = temperature_val;
}
temperature.addEventListener(
"change",
(e) => {
localStorage.setItem("temperature", e.target.value);
}
)
// Select the input field
const prompt = document.querySelector('#prompt');
const mermaid_text = document.querySelector('#text');
const mermaid_render = document.querySelector('#render');
// Add event listener for the keydown event
prompt.addEventListener('keydown', function (event) {
// Check if the Enter key was pressed
if (event.keyCode === 13) {
// Prevent the form from being submitted (which would cause the page to reload)
event.preventDefault();
let model_val = model.value;
// Define the data to send
let data = {
model: model_val === "custom" ? custom_model.value : model_val,
messages: [
{
role: "system",
content: template.value
},
{
role: "user",
content: prompt.value
}
],
stream: false,
max_tokens: Number(max_tokens.value),
temperature: Number(temperature.value)
};
let token = document.querySelector('#token').value;
prompt.parentElement.classList.add("anim")
// Make the POST request
fetch(endpoint.value, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
let resp = data.choices[0].message.content;
let new_text = `mindmap\n${resp.substring(resp.indexOf("root("))}`
const text = checkAndReplaceLastLine(new_text);
mermaid_text.innerHTML = text;
mermaid_render.innerHTML = text;
mermaid.run();
prompt.parentElement.classList.remove("anim");
mermaid_render.removeAttribute("data-processed");
})
.catch((error) => {
prompt.parentElement.classList.remove("anim");
console.error('Error:', error);
});
}
});
});
</script>
<body>
<div class="settings">
<details id="details">
<summary>settings</summary>
<form>
<label for="BaseURL">Base URL:</label>
<br>
<input type="text" id="BaseURL" name="BaseURL"
value="https://api.openai.com/v1/chat/completions">
<br>
<label for="token">Token:</label>
<br>
<input type="text" id="token" name="token">
<br>
<label for="model">Model:</label>
<br>
<select id="model" name="model">
<option>gpt-3.5-turbo</option>
<option>gpt-3.5-turbo-16k</option>
<option>gpt-4</option>
<option>custom</option>
</select>
<br>
<input type="text" id="custom_model" name="custom"
placeholder="Custom model" style="display: none">
<br>
<label for="max_tokens">max_tokens:</label>
<br>
<input id="max_tokens" name="max_tokens" value="2000">
<br>
<label for="temp">temperature:</label>
<br>
<input id="temp" name="temperature" value="0.7">
<br>
<label for="template">Prompt template:</label>
<br>
<textarea id="template" name="template" rows="5">Create a mermaid mindmap based on user input like these examples:
brainstorming mindmap
mindmap
root(("leisure activities weekend"))
["spend time with friends"]
::icon(fafa fa-users)
("action activities")
::icon(fafa fa-play)
("dancing at night club")
("going to a restaurant")
("go to the theater")
["spend time your self"]
::icon(fa fa-fa-user)
("meditation")
::icon(fa fa-om)
("\`take a sunbath ☀️\`")
("reading a book")
::icon(fa fa-book)
text summary mindmap:
Barack Obama (born August 4, 1961) is an American politician who served as the 44th president of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African-American president of the United States.
mindmap
root("Barack Obama")
("Born August 4, 1961")
::icon(fa fa-baby-carriage)
("American Politician")
::icon(fa fa-flag)
("44th President of the United States")
("2009 - 2017")
("Democratic Party")
::icon(fa fa-democrat)
("First African-American President")
cause and effects mindmap:
mindmap
root("Landlord sells apartment")
::icon(fa fa-sell)
("Renter must be notified of sale")
::icon(fa fa-envelope)
("Tenants may feel some uncertainty")
::icon(fa fa-question-circle)
("Notice periods must be observed")
::icon(fa fa-calendar)
("Landlord can submit notice of termination for personal use")
::icon(fa fa-home)
("Tenant has to look for a new apartment")
::icon(fa fa-search)
("New owner")
::icon(fa fa-user)
("New owner takes over existing rental agreement")
::icon(fa fa-file-contract)
("Tenant keeps previous apartment")
::icon(fa fa-handshake)
("New owner terminates newly concluded lease")
::icon(fa fa-ban)
("Tenant has to look for a new apartment")
::icon(fa fa-search)
Only one root, use free FontAwesome icons, and follow node types "[", "(". No need to use "mermaid", "\`\`\`", or "graph TD". Respond only with code and syntax.</textarea>
<br>
</form>
</details>
</div>
<div class="mer_container">
<pre id="text" style="display: none"></pre>
<pre class="mermaid" id="render"></pre>
</div>
<div class="prompt">
<div class="floating-input">
<input id="prompt" type="text" placeholder="Prompt">
</div>
</div>
</body>
</html>