-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindex.html
1916 lines (1549 loc) · 69 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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en" class="h-100" data-bs-theme="auto">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="application-name" content="AI Character Editor">
<meta name="description" content="Create, edit and convert AI character files for CharacterAI, Pygmalion, Text Generation and TavernAI">
<meta name="version" content="0.5.0">
<meta name="revision" content="2023-02-06">
<meta name="author" content="ZoltanAI">
<meta name="contact" content="Zoltan#8287 on Discord">
<meta name="license" content="GNU-GPLv3">
<meta name="color-scheme" content="light dark" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#F8F9FA" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#2B3035" />
<meta name="twitter:card" content="summary">
<meta property="og:title" content="AI Character Editor">
<meta property="og:description" content="Create, edit and convert AI character files for CharacterAI, Pygmalion, Text Generation and TavernAI">
<meta property="og:url" content="https://zoltanai.github.io/character-editor/">
<meta property="og:type" content="website">
<title>AI Character Editor</title>
<script>
(() => {
'use strict';
const getTheme = () => localStorage.getItem('theme') ?? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-bs-theme', getTheme());
window.addEventListener('DOMContentLoaded', () => {
document.getElementById('theme').addEventListener('click', () => {
const theme = getTheme() === 'dark' ? 'light' : 'dark';
localStorage.setItem('theme', theme);
document.documentElement.setAttribute('data-bs-theme', theme);
});
});
})();
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<style>
.accordion-button:disabled {
cursor: not-allowed;
}
.bg-drag {
background-color: var(--bs-accordion-active-bg);
}
.border-dotted {
--bs-border-style: dotted;
}
.tooltip {
--bs-tooltip-max-width: 500px;
}
.popover {
--bs-popover-max-width: 50vw;
--bs-popover-body-padding-x: 0;
--bs-popover-body-padding-y: 0.5rem;
--bs-popover-bg: var(--bs-tertiary-bg);
}
.list-group-item {
--bs-list-group-bg: var(--bs-tertiary-bg);
}
textarea {
resize: none;
}
figure div a:hover,
figure div a.hover {
background-color: rgba(var(--bs-secondary-color-rgb), 0.3);
}
figure div a:hover svg,
figure div a.hover svg {
display: block !important;
}
i[data-bs-toggle="tooltip"],
[data-bs-toggle="popover"] * {
cursor: help;
}
@media (min-width: 992px) {
.border-end-lg {
border-right: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color) !important;
}
.border-bottom-lg-0 {
border-bottom: 0 !important;
}
}
</style>
</head>
<body class="d-flex flex-column h-100 bg-body-tertiary">
<main class="flex-shrink-0">
<div class="container pt-4 pb-5">
<h1 class="display-1 text-center">AI Character Editor</h1>
<p class="my-0 lead text-center">Create, edit and convert to and from <a href="https://beta.character.ai/" target="_blank">CharacterAI</a> <a href="https://github.com/0x000011b/characterai-dumper" target="_blank">dumps</a>, <a href="https://github.com/PygmalionAI/gradio-ui" target="_blank">Pygmalion</a>, <a href="https://github.com/oobabooga/text-generation-webui" target="_blank">Text Generation</a> and <a href="https://github.com/TavernAI/TavernAI" target="_blank">TavernAI</a> formats easily</p>
<p class="lead text-center">Supports both JSON and Character Card image files</p>
<button id="theme" class="btn btn-outline-secondary position-absolute top-0 end-0 m-4">
<i class="bi bi-lightbulb"></i>
</button>
<div class="container my-5 text-center">
<div id="site-alert" class="alert alert-warning alert-dismissible show d-none" role="alert">
None of your data is uploaded or shared, this entire webpage runs locally in your browser!
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
<div class="container">
<div id="accordion" class="accordion border-0">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button shadow-none fs-5" type="button" data-bs-toggle="collapse" data-bs-target="#accordion-load">
<i class="bi bi-file-earmark-plus flex-shrink-0 me-2"></i> Load
</button>
</h2>
<div id="accordion-load" class="accordion-collapse collapse show" data-bs-parent="#accordion">
<div class="accordion-body text-center p-0">
<div class="container">
<div class="row">
<div class="col-6 py-5 position-relative">
<form id="load-form">
<i class="bi bi-cloud-upload display-2 text-primary"></i>
<p class="my-2">Drag & drop a JSON or image file here<br><i>or</i></p>
<label for="load" class="btn btn-primary stretched-link">Choose file...</label>
<input id="load" class="position-absolute invisible" type="file" accept="application/json, image/png">
</form>
</div>
<div class="col-6 py-5 position-relative border-start">
<i class="bi bi-file-earmark-plus display-2 text-primary"></i>
<p class="my-2">Start from scratch and create a new character<br><br></p>
<button id="create" type="button" class="btn btn-primary stretched-link">New character</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed shadow-none fs-5" type="button" data-bs-toggle="collapse" data-bs-target="#accordion-edit" disabled autocomplete="off">
<i class="bi bi-pencil flex-shrink-0 me-2"></i> Edit
</button>
</h2>
<div id="accordion-edit" class="accordion-collapse collapse" data-bs-parent="#accordion">
<div class="accordion-body">
<div class="container">
<div class="row">
<div id="edit-alert-characterai-history" class="my-2 alert alert-warning alert-dismissible show d-none" role="alert">
<p class="fw-semibold">You have loaded a CharacterAI chat history file</p>
<p class="mb-0">CharacterAI chat history files do not contain character Example Messages, so where possible use a CharacterAI character definition file!<br>If the character you want to use is your own or the character settings are public, then you will get better results <a id="edit-alert-characterai-history-link" class="alert-link" href="#" target="_blank">downloading a definition dump</a> instead.</p>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
<div class="row my-3">
<div id="edit-details" class="col-12 col-md-5 col-lg-4 col-xl-3">
<figure class="mb-4 figure w-100 text-center">
<div class="position-relative w-100 h-100">
<input id="image" class="position-absolute invisible" type="file" accept="image/*">
<a id="edit-image-add" href="" class="position-absolute top-0 start-0 w-100 h-100 d-inline-block rounded stretched-link z-3">
<svg class="position-absolute top-50 start-50 translate-middle w-25 h-25 d-none" xmlns="http://www.w3.org/2000/svg" fill="var(--bs-secondary-bg)" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z" />
</svg>
</a>
<svg id="edit-image-placeholder" class="img-thumbnail w-100 bg-body-tertiary" xmlns="http://www.w3.org/2000/svg" width="5" height="6" viewBox="0 0 16 16" fill="var(--bs-secondary-bg)">
<path d="M8.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z" />
<path d="M12 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2zM3 2a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1v8l-2.083-2.083a.5.5 0 0 0-.76.063L8 11 5.835 9.7a.5.5 0 0 0-.611.076L3 12V2z" />
</svg>
<img id="edit-image" class="img-thumbnail w-100 bg-body-tertiary d-none" src="#" alt="">
</div>
<figcaption id="edit-image-details" class="figure-caption d-inline-flex mt-1 d-none"></figcaption>
<i class="bi bi-info-circle fs-5 d-inline-block ms-1 align-top text-success d-none" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-help" data-bs-title="Character Card images should be 400 x 600px (2:3)"></i>
</figure>
<div id="edit-original" class="container p-3 border rounded d-none">
<div class="row text-center">
<h3 class="h5">Original File</h3>
</div>
<div class="row mt-3">
<div class="col-auto fst-italic">Name</div>
<div id="edit-original-name" class="col-auto ms-auto text-end text-break text-wrap"></div>
</div>
<div class="row mt-3">
<div class="col-auto fst-italic">Format</div>
<div id="edit-original-format" class="col-auto ms-auto text-end text-break text-wrap"></div>
</div>
<div class="row mt-3">
<div class="col-auto fst-italic">Tokens</div>
<div id="edit-original-tokens" class="col-auto ms-auto text-end"></div>
</div>
<div class="row mt-3">
<div class="col-auto fst-italic">Size</div>
<div id="edit-original-size" class="col-auto ms-auto text-end"></div>
</div>
<div class="row mt-3">
<div class="col-auto fst-italic">Last Modified</div>
<div class="col-auto ms-auto text-end">
<time id="edit-original-modified" class="border-bottom border-dotted border-primary" datetime="" data-bs-toggle="tooltip" data-bs-title=" "></time>
</div>
</div>
</div>
<div id="edit-metadata-cai" class="container mt-4 p-3 border rounded d-none">
<div class="row text-center">
<h3 class="h5">CharacterAI Metadata</h3>
</div>
<div class="row mt-3 d-none">
<div class="col-auto fst-italic">Character</div>
<div class="col-auto ms-auto text-end">
<a id="edit-metadata-cai-link" href="#" target="_blank"></a>
</div>
</div>
<div class="row mt-3 d-none">
<div class="col-auto fst-italic">Visibility</div>
<div id="edit-metadata-cai-visibility" class="col-auto ms-auto text-end"></div>
</div>
<div class="row mt-3 d-none">
<div class="col-auto fst-italic">Interactions</div>
<div id="edit-metadata-cai-interactions" class="col-auto ms-auto text-end"></div>
</div>
<div class="row mt-3 d-none">
<div class="col-auto fst-italic">Categories</div>
<div id="edit-metadata-cai-categories" class="col-auto ms-auto text-end"></div>
</div>
<div class="row mt-3 d-none">
<div class="col-auto fst-italic">Image Generation</div>
<div id="edit-metadata-cai-image-generation" class="col-auto ms-auto text-end"></div>
</div>
</div>
</div>
<div class="col-12 col-md-7 col-lg-8 col-xl-9">
<form class="needs-validation" autocomplete="off" novalidate>
<div class="mb-3">
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover">
<label for="edit-name" class="form-label fw-semibold">Name</label>
<i class="bi bi-info-circle fs-5 text-primary"></i>
<ul class="list-group list-group-flush d-none">
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Pygmalion</span> · Character Name
<p class="mb-0">The character's name</p>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Text Generation</span> · Bot's name
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> TavernAI</span> · <em>Used but uneditable</em>
</li>
<li class="list-group-item d-none">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> KoboldAI</span> · Name
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> CharacterAI</span> · Name
<p class="mb-0">This will be the name your Character uses in chat</p>
</li>
</ul>
</span>
<input type="text" class="form-control" id="edit-name" required>
<label for="edit-name" class="form-label float-end mt-1 small text-secondary"></label>
<div class="invalid-feedback">
Name is required by all formats
</div>
</div>
<div class="mb-3">
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover">
<label for="edit-summary" class="form-label fw-semibold">Summary</label>
<i class="bi bi-info-circle fs-5 text-primary"></i>
<ul class="list-group list-group-flush d-none">
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> Pygmalion</span> · <em>Not used</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> Text Generation</span> · <em>Not used</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> TavernAI</span> · Personality summary
<p class="mb-0">A brief description of the personality</p>
</li>
<li class="list-group-item d-none">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> KoboldAI</span> · <em>???</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> CharacterAI</span> · Short Description
<p class="mb-0">In just a few words, how would your Character describe themselves?</p>
</li>
</ul>
</span>
<textarea class="form-control auto-size" id="edit-summary" rows="1"></textarea>
<label for="edit-summary" class="form-label float-end mt-1 small text-secondary"></label>
</div>
<div class="mb-3">
<span class="d-inline-block " tabindex="0" data-bs-toggle="popover">
<label for="edit-personality" class="form-label fw-semibold">Personality</label>
<i class="bi bi-info-circle fs-5 text-primary"></i>
<ul class="list-group list-group-flush d-none">
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Pygmalion</span> · Character Persona
<p class="mb-0">Describe the character's persona here. Think of this as CharacterAI's description + definitions in one box.</p>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Text Generation</span> · Context (Persona)
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> TavernAI</span> · Description
<p class="mb-0">Description of personality and other characteristics</p>
</li>
<li class="list-group-item d-none">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> KoboldAI</span> · <em>???</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> CharacterAI</span> · Long Description
<p class="mb-0">In a few sentences, how would your Character describe themselves?</p>
</li>
</ul>
</span>
<textarea class="form-control auto-size" id="edit-personality" rows="1"></textarea>
<label for="edit-personality" class="form-label float-end mt-1 small text-secondary"></label>
</div>
<div class="mb-3">
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover">
<label for="edit-scenario" class="form-label fw-semibold">Scenario</label>
<i class="bi bi-info-circle fs-5 text-primary"></i>
<ul class="list-group list-group-flush d-none">
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Pygmalion</span> · Scenario
<p class="mb-0">Optionally, describe the starting scenario in a few short sentences.</p>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Text Generation</span> · Context (Scenario)
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> TavernAI</span> · Scenario
<p class="mb-0">Circumstances and context of the dialogue</p>
</li>
<li class="list-group-item d-none">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> KoboldAI</span> · <em>???</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> CharacterAI</span> · <em>Not used</em>
</li>
</ul>
</span>
<textarea class="form-control auto-size" id="edit-scenario" rows="1"></textarea>
<label for="edit-scenario" class="form-label float-end mt-1 small text-secondary"></label>
</div>
<div class="mb-3">
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover">
<label for="edit-greeting" class="form-label fw-semibold">Greeting Message</label>
<i class="bi bi-info-circle fs-5 text-primary"></i>
<ul class="list-group list-group-flush d-none">
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Pygmalion</span> · Character Greeting
<p class="mb-0">Write the character's greeting here. They will say this verbatim as their first response.</p>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Text Generation</span> · <em>Used but uneditable</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> TavernAI</span> · First message
<p class="mb-0">First message from the character</p>
</li>
<li class="list-group-item d-none">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> KoboldAI</span> · <em>???</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> CharacterAI</span> · Greeting
<p class="mb-0">What would your Character say to start a conversation?</p>
</li>
</ul>
</span>
<textarea class="form-control auto-size" id="edit-greeting" rows="1"></textarea>
<label for="edit-greeting" class="form-label float-end mt-1 small text-secondary"></label>
</div>
<div class="mb-3">
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover">
<label for="edit-examples" class="form-label fw-semibold">Example Messages</label>
<i class="bi bi-info-circle fs-5 text-primary"></i>
<ul class="list-group list-group-flush d-none">
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Pygmalion</span> · Example Chat
<p class="mb-0">Optionally, write in an example chat here. This is useful for showing how the character should behave, for example.</p>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> Text Generation</span> · <em>Used but uneditable</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> TavernAI</span> · Examples of dialogue
<p class="mb-0">Forms a personality more clearly</p>
</li>
<li class="list-group-item d-none">
<span class="fw-semibold"><i class="bi bi-x text-danger"></i> KoboldAI</span> · <em>???</em>
</li>
<li class="list-group-item">
<span class="fw-semibold"><i class="bi bi-check text-success"></i> CharacterAI</span> · Definition
<p class="mb-0">Example conversations and information to define your Character</p>
</li>
</ul>
</span>
<textarea class="form-control auto-size" id="edit-examples" rows="1"></textarea>
<label for="edit-examples" class="form-label float-end mt-1 small text-secondary"></label>
</div>
<div class="clearfix"></div>
<span id="edit-tokens" class="float-end small text-secondary"></span>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button collapsed shadow-none fs-5" type="button" data-bs-toggle="collapse" data-bs-target="#accordion-export" disabled autocomplete="off">
<i class="bi bi-box-arrow-down flex-shrink-0 me-2"></i> Export
</button>
</h2>
<div id="accordion-export" class="accordion-collapse collapse" data-bs-parent="#accordion">
<div class="accordion-body text-center">
<div class="container">
<div class="row py-3 px-5">
<div id="export-image" class="col-12 col-lg border-end-0 border-end-lg border-bottom border-bottom-lg-0 pb-4 pb-lg-0 mb-4 mb-lg-0 d-none">
<h4>Export as Image</h4>
<button id="export-png" type="button" class="btn btn-outline-primary my-3"><i class="bi bi-download flex-shrink-0 me-1"></i> Download as Character Card Image</button>
<p>Compatible with <a href="https://github.com/oobabooga/text-generation-webui" target="_blank">Text Generation</a> / <a href="https://github.com/TavernAI/TavernAI" target="_blank">TavernAI</a></p>
<div class="mt-4 small text-body-secondary">
Character Cards are PNG images with embedded JSON
</div>
</div>
<div class="col-12 col-lg">
<h4>Export as JSON</h4>
<button id="export-json" type="button" class="btn btn-outline-primary my-3"><i class="bi bi-download flex-shrink-0 me-1"></i> Download as Character JSON</button>
<p>Compatible with <a href="https://github.com/PygmalionAI/gradio-ui" target="_blank">Pygmalion</a> / <a href="https://github.com/oobabooga/text-generation-webui" target="_blank">Text Generation</a> / <a href="https://github.com/TavernAI/TavernAI" target="_blank">TavernAI</a></p>
<div class="mt-4 small text-body-secondary">
Having problems with the Hybrid JSON?<br>
<a href="" id="export-json-gradio" class="link-secondary">Download as Pygmalion / Text Generation JSON</a><br>
<a href="" id="export-json-tavern" class="link-secondary">Download as TavernAI JSON</a>
</div>
<div class="mt-4 small text-danger">
There is currently a bug in TavernAI which stops it from importing all data from JSON files! You are strongly encouraged to import your character as a Character Card image to avoid the issue
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<footer class="footer mt-auto p-3 bg-body">
<div class="container">
<div class="row text-body-secondary user-select-none">
<div class="col">
<span data-bs-toggle="tooltip" data-bs-title="Get in contact on Discord for any suggestions or help!">Made with 💦 by <code class="user-select-all">Zoltan#8287</code></span>
</div>
<div class="col text-end">
Version 0.5
</div>
</div>
</div>
</footer>
<div id="error-modal" class="modal fade" tabindex="-1" aria-labelledby="error-modal-heading" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content">
<div class="modal-header">
<h1 id="error-modal-heading" class="modal-title fs-5 text-danger"><i class="bi bi-exclamation-octagon"></i> An Error has Occurred</h1>
</div>
<div class="modal-body">
<p>An unexpected error has occurred, sorry!</p>
<p>This tool is still in development and you can help improve it by sending the error message below and your file (if applicable) to <code class="user-select-all">Zoltan#8287</code> on Discord or by reporting it on <a href="https://github.com/ZoltanAI/character-editor" target="_blank">GitHub</a>.</p>
<pre class="mb-0 p-3 border bg-body-secondary rounded"><code id="error-message" class="user-select-all"></code></pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="warning-modal" class="modal fade" tabindex="-1" aria-labelledby="warning-modal-heading" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 id="warning-modal-heading" class="modal-title fs-5 text-danger"><i class="bi bi-exclamation-octagon"></i> <span id="warning-modal-title"></span></h1>
</div>
<div class="modal-body">
<p id="warning-modal-body" class="m-0"></p>
<div id="warning-modal-collapse" class="collapse">
<hr>
<p>If you think you have mistakenly received this warning, please send the error message below and your file to <code class="user-select-all">Zoltan#8287</code> on Discord or report it on <a href="https://github.com/ZoltanAI/character-editor" target="_blank">GitHub</a>.</p>
<pre class="mb-0 p-3 border bg-body-secondary rounded"><code id="warning-modal-details" class="user-select-all"></code></pre>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary me-auto" data-bs-toggle="collapse" data-bs-target="#warning-modal-collapse" aria-expanded="false" aria-controls="warning-modal-collapse">
<i class="bi bi-chevron-expand"></i> Details
</button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected]/dist/js/bootstrap.bundle.min.js,npm/[email protected],gh/syonfox/GPT-3-Encoder@c3c2e2533a15645d812b5e6fcb00b75b74718161/browser.min.js"></script>
<script>
'use strict';
const APP = 'AI Character Editor';
const VER = '0.5.0';
Element.prototype.show = function () {
this.classList.remove('d-none');
};
Element.prototype.hide = function () {
this.classList.add('d-none');
};
const JsonFormats = {
TextGenerationCharacter: 'Text Generation Character',
TavernCharacter: 'TavernAI Character',
KoboldCharacter: 'KoboldAI Character',
CaiCharacter: 'CharacterAI Character',
CaiHistory: 'CharacterAI History'
};
class JsonParseError extends Error {
#json;
get json() {
return this.#json;
}
constructor(message, json, options) {
super(message, options);
this.name = 'JSON Parse Error';
this.#json = json;
}
}
class JsonUnknownFormatError extends Error {
#json;
get json() {
return this.#json;
}
constructor(message, json, options) {
super(message, options);
this.name = 'Unknown JSON Format Error';
this.#json = json;
}
}
class PngDecodeError extends Error {
constructor(message, options) {
super(message, options);
this.name = 'PNG Decode Error';
}
}
class PngFormatError extends Error {
constructor(message, options) {
super(message, options);
this.name = 'PNG Format Error';
}
}
class PngMissingCharacterError extends Error {
constructor(message, options) {
super(message, options);
this.name = 'PNG Missing Character Error';
}
}
class PngInvalidCharacterError extends Error {
constructor(message, options) {
super(message, options);
this.name = 'PNG Invalid Character Error';
}
}
class Exception {
static #modal = new bootstrap.Modal('#error-modal', {
backdrop: 'static'
});
static set #message(value) {
document.getElementById('error-message').innerText = value;
}
static format(ex, indent = 0) {
let message = `${' '.repeat(indent)}${ex.name ?? 'Error'}: ${ex.message}`;
if (ex.lineNumber) {
message += ` (${ex.lineNumber}`;
if (ex.columnNumber) message += `:${ex.columnNumber}`;
message += ')';
}
message += '\n';
if (ex.cause) message += this.format(ex.cause, indent + 2);
if (ex instanceof JsonParseError && ex.json) message += `Source: "${ex.json}"\n`;
if (ex instanceof JsonUnknownFormatError && ex.json) message += `Source: "${Format.stringify(ex.json)}"\n`;
if (ex instanceof TypeError && ex.stack && indent == 0) message += `\n${ex.stack}`;
return message;
}
static show(ex) {
console.error(ex);
this.#message = `${APP} v${VER}\n${this.format(ex)}`.trim();
this.#modal.show();
}
}
class Warning {
static #modal = new bootstrap.Modal('#warning-modal', {
backdrop: 'static'
});
static set #title(value) {
document.getElementById('warning-modal-title').innerText = value;
}
static set #message(value) {
document.getElementById('warning-modal-body').innerHTML = value;
}
static set #details(value) {
document.getElementById('warning-modal-details').innerText = value;
}
static show(title, message, ex) {
console.warn(ex);
document.getElementById('warning-modal-collapse').classList.remove('show');
this.#title = title;
this.#message = message;
this.#details = Exception.format(ex);
this.#modal.show();
}
}
class Format {
static bytes(bytes, decimals = 2) {
if (bytes == 1) return '0 bytes';
if (bytes == 1) return '1 byte';
const k = 1024;
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'][i];
}
static dateTime(date) {
return new Intl.DateTimeFormat(undefined, {
dateStyle: 'long',
timeStyle: 'medium',
hour12: true
}).format(date);
}
static ago(date) {
const DIVISIONS = [
{ amount: 60, name: 'seconds' },
{ amount: 60, name: 'minutes' },
{ amount: 24, name: 'hours' },
{ amount: 7, name: 'days' },
{ amount: 4.34524, name: 'weeks' },
{ amount: 12, name: 'months' },
{ amount: Number.POSITIVE_INFINITY, name: 'years' }
];
let duration = (date - new Date()) / 1000;
for (let i = 0; i <= DIVISIONS.length; i++) {
const division = DIVISIONS[i];
if (Math.abs(duration) < division.amount) {
return Format.capitalize(new Intl.RelativeTimeFormat(undefined, {
numeric: 'auto'
}).format(Math.round(duration), division.name));
}
duration /= division.amount;
}
}
static ratio(width, height) {
return height == 0 ? width : Format.ratio(height, width % height);
}
static capitalize(text) {
return text && text.charAt(0).toUpperCase() + text.slice(1);
}
static pluralize(count, singular, plural) {
switch (new Intl.PluralRules('en').select(count)) {
case 'one':
return singular;
default:
return plural;
}
}
static stringify(object) {
return JSON.stringify(object, null, '\t');
}
}
class Png {
static #uint8 = new Uint8Array(4);
static #int32 = new Int32Array(this.#uint8.buffer);
static #uint32 = new Uint32Array(this.#uint8.buffer);
// Parse and extract PNG tEXt chunk
static #decodeText(data) {
let naming = true;
let keyword = '';
let text = '';
for (let index = 0; index < data.length; index++) {
const code = data[index];
if (naming) {
if (code) {
keyword += String.fromCharCode(code);
} else {
naming = false;
}
} else {
if (code) {
text += String.fromCharCode(code);
} else {
throw new PngDecodeError('Invalid NULL character found in PNG tEXt chunk');
}
}
}
return {
keyword,
text
};
}
// Encode value to PNG tEXt chunk
static #encodeText(keyword, text) {
keyword = String(keyword);
text = String(text);
if (!/^[\x00-\xFF]+$/.test(keyword) || !/^[\x00-\xFF]+$/.test(text)) throw new PngDecodeError('Invalid character in PNG tEXt chunk');
if (keyword.length > 79) throw new PngDecodeError('Keyword "' + keyword + '" is longer than the 79 character limit');
const data = new Uint8Array(keyword.length + text.length + 1);
let idx = 0;
let code;
for (let i = 0; i < keyword.length; i++) {
if (!(code = keyword.charCodeAt(i))) throw new PngDecodeError('0x00 character is not permitted in tEXt keywords');
data[idx++] = code;
}
data[idx++] = 0;
for (let i = 0; i < text.length; i++) {
if (!(code = text.charCodeAt(i))) throw new PngDecodeError('0x00 character is not permitted in tEXt text');
data[idx++] = code;
}
return data;
}
// Read PNG format chunk
static #readChunk(data, idx) {
// Read length field
this.#uint8[3] = data[idx++];
this.#uint8[2] = data[idx++];
this.#uint8[1] = data[idx++];
this.#uint8[0] = data[idx++];
const length = this.#uint32[0];
// Read chunk type field
const chunkType = String.fromCharCode(data[idx++]) + String.fromCharCode(data[idx++]) + String.fromCharCode(data[idx++]) + String.fromCharCode(data[idx++]);
// Read chunk data field
const chunkData = data.slice(idx, idx + length);
idx += length;
// Read CRC field
this.#uint8[3] = data[idx++];
this.#uint8[2] = data[idx++];
this.#uint8[1] = data[idx++];
this.#uint8[0] = data[idx++];
const crc = this.#int32[0];
// Compare stored CRC to actual
if (crc !== CRC32.buf(chunkData, CRC32.str(chunkType))) throw new PngDecodeError('CRC for "' + chunkType + '" header is invalid, file is likely corrupted');
return {
type: chunkType,
data: chunkData,
crc
};
}
// Read PNG file and extract chunks
static #readChunks(data) {
if (data[0] !== 0x89 || data[1] !== 0x50 || data[2] !== 0x4E || data[3] !== 0x47 || data[4] !== 0x0D || data[5] !== 0x0A || data[6] !== 0x1A || data[7] !== 0x0A) throw new PngFormatError('Invalid PNG header');
const chunks = [];
let idx = 8; // Skip signature
while (idx < data.length) {
const chunk = Png.#readChunk(data, idx);
if (!chunks.length && chunk.type !== 'IHDR') throw new PngDecodeError('PNG missing IHDR header');
chunks.push(chunk);
idx += 4 + 4 + chunk.data.length + 4; // Skip length, chunk type, chunk data, CRC
}
if (chunks.length === 0) throw new PngDecodeError('PNG ended prematurely, no chunks');
if (chunks[chunks.length - 1].type !== 'IEND') throw new PngDecodeError('PNG ended prematurely, missing IEND header');
return chunks;
}
// Write PNG file from chunks
static #encodeChunks(chunks) {
const output = new Uint8Array(chunks.reduce((a, c) => a + 4 + 4 + c.data.length + 4, 8)); // Signature + chunks (length, chunk type, chunk data, CRC)
// Signature
output[0] = 0x89;
output[1] = 0x50;
output[2] = 0x4E;
output[3] = 0x47;
output[4] = 0x0D;
output[5] = 0x0A;
output[6] = 0x1A;
output[7] = 0x0A;
let idx = 8; // After signature
chunks.forEach(c => {
// Write length field
this.#uint32[0] = c.data.length;
output[idx++] = this.#uint8[3];
output[idx++] = this.#uint8[2];
output[idx++] = this.#uint8[1];
output[idx++] = this.#uint8[0];
// Write chunk type field
output[idx++] = c.type.charCodeAt(0);
output[idx++] = c.type.charCodeAt(1);
output[idx++] = c.type.charCodeAt(2);
output[idx++] = c.type.charCodeAt(3);
// Write chunk data field
for (let i = 0; i < c.data.length;) {
output[idx++] = c.data[i++];
}
// Write CRC field
this.#int32[0] = c.crc || CRC32.buf(c.data, CRC32.str(c.type));
output[idx++] = this.#uint8[3];
output[idx++] = this.#uint8[2];
output[idx++] = this.#uint8[1];
output[idx++] = this.#uint8[0];
});
return output;
}
// Parse PNG file and return decoded UTF8 "chara" base64 tEXt chunk value
static Parse(arrayBuffer) {
const chunks = Png.#readChunks(new Uint8Array(arrayBuffer));
const text = chunks.filter(c => c.type === 'tEXt').map(c => Png.#decodeText(c.data));
if (text.length < 1) throw new PngMissingCharacterError('No PNG text fields found in file');
const chara = text.find(t => t.keyword === 'chara');
if (chara === undefined) throw new PngMissingCharacterError('No PNG text field named "chara" found in file');
try {
return new TextDecoder().decode(Uint8Array.from(atob(chara.text), c => c.charCodeAt(0)));
} catch (e) {
throw new PngInvalidCharacterError('Unable to parse "chara" field as base64', {
cause: e
});
}
}
// Parse PNG file, strip all tEXt chunks, add encoded UTF8 "chara" base64 tEXt chunk and return PNG file
static Generate(arrayBuffer, text) {
// Read PNG and remove all tEXt chunks, as TavernAI does
// NOTE: TavernAI blindly reads first tEXt chunk, rather than searching for one named "chara"
const chunks = Png.#readChunks(new Uint8Array(arrayBuffer)).filter(c => c.type !== 'tEXt');
// Insert new "chara" tEXt chunk just before IEND chunk, as TavernAI does
// NOTE: Some programs won't see the tEXt chunk if its after any IDAT chunks
chunks.splice(-1, 0, {
type: 'tEXt',
data: Png.#encodeText('chara', btoa(new TextEncoder().encode(text).reduce((a, c) => a + String.fromCharCode(c), '')))
});
return Png.#encodeChunks(chunks);
}
}
class Loader {
// Create image element and wait for it to load
static image(src) {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.crossOrigin = 'anonymous';
image.src = src;
});
}
// Parse JSON and wrap any error
static #json(text) {
try {
return JSON.parse(text);