-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
138 lines (115 loc) · 3.53 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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet">
<style>
body {
font-family: sans-serif;
background-color: white;
max-width: 30em;
}
select,
button {
font-size: 100%;
max-width: 15em;
}
#title {
font-size: 100%;
font-weight: bold;
}
#about>p {
margin: 0.5em 0;
}
.section {
border: 1px solid #ccc;
margin: 0.5em 0;
padding: 0.5em;
border-radius: 0.5em;
font-family: 'Work Sans Light', sans-serif;
background-color: rgb(245, 245, 245);
}
#lyric {
max-height: 7em;
overflow: scroll;
}
</style>
</head>
<body>
<p>
Neural lyrics given a <b>style</b> and <b>subject</b>.
</p>
<select id="lyrics"></select> <button onclick="randomSelect(selectLyrics); update();">random</button>
<div id="lyric" class="section">Loading...</div>
<select id="seeds"></select> <button onclick="randomSelect(selectSeeds); update();">random</button> <button
onclick="regenerate()">regenerate</button>
<p id="generated" class="section">Loading...</p>
<p>
<a href="https://github.com/openai/gpt-2">GPT-2</a> with <a href="https://genius.com/">Genius</a>.
Code by <a href="https://twitter.com/ewen_/">@ewen_</a>, based on <a href="https://kylemcdonald.github.io/gpt-2-poetry/">gpt-2-poetry</a> by <a href="https://twitter.com/kcimc/">@kcimc</a>.
</p>
<script>
let index = 0;
let selectLyrics = document.querySelector('#lyrics');
let selectSeeds = document.querySelector('#seeds');
let lyricElt = document.querySelector("#lyric");
let generatedElt = document.querySelector("#generated");
function convertNewlines(text) {
return text.split('\n').join('<br/>').split('<|endoftext|>')[0];
}
function update() {
let key = selectLyrics.value;
let lyric = lyrics[key];
// console.log(lyrics.url);
lyricElt.innerHTML = lyric.lyrics.join('<br/>');
let seed = selectSeeds.value;
generatedElt.innerHTML = convertNewlines(generated[seed][key][index]) + '...';
}
function randomSelect(elt) {
let n = elt.options.length;
let i = Math.floor(Math.random() * n);
elt.value = elt.options[i].value;
regenerate();
}
function regenerate() {
index = (index + 1) % 10;
update();
}
Promise.all([
fetch('output/lyrics.json').then(e => e.json()),
fetch('output/generated.json').then(e => e.json())
])
.then(files => {
lyrics = files[0];
generated = files[1];
let sortable = [];
for (key in lyrics) {
let lyric = lyrics[key];
sortable.push([
lyric['artist'] + ' > ' + lyric['title'],
key
])
}
sortable.sort(function (a, b) {
return a[0].toLowerCase().localeCompare(b[0].toLowerCase());
});
sortable.forEach(item => {
let opt = document.createElement("option");
opt.text = item[0];
opt.value = item[1];
selectLyrics.add(opt);
})
for (key in generated) {
let opt = document.createElement("option");
opt.text = key;
opt.value = key;
selectSeeds.add(opt);
}
randomSelect(selectLyrics);
randomSelect(selectSeeds);
selectSeeds.onchange = update;
selectLyrics.onchange = update;
update();
})
</script>
</body>
</html>