-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
280 lines (231 loc) · 9.24 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
<!DOCTYPE html>
<style>
html,
body {
height: 95% !important;
margin: 0 !important;
}
footer {
/*max-height: 5% !important;*/
padding: 1em !important
}
section {
min-height: 95% !important
}
.gen-box {
background-color: #fff;
display: block;
padding: 1.25rem;
color: #4a4a4a;
font-size: 1rem;
font-weight: 400;
line-height: 1.25;
}
.gen-border {
height: 0.25em;
background-color: #d5d5d5;
}
.gen-box.warning {
color: red;
font-weight: 700;
}
.brand-text {
display: flex;
align-items: center;
font-size: 1.5em
}
#extra-buttons {
padding-top: 1em;
margin-top: 1em;
border-top: 0.5px solid #d5d5d5;
}
</style>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AI-Generated Text with GPT-2 using Google Cloud Run</title>
<meta name="title" content="AI-Generated Text with GPT-2 using Google Cloud Run" />
<meta name="description" content="Generate text from OpenAI's GPT-2 model!" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
</head>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<span class="icon is-large">
<img src='https://upload.wikimedia.org/wikipedia/en/thumb/3/3b/SpongeBob_SquarePants_character.svg/220px-SpongeBob_SquarePants_character.svg.png'>
</span>
</span>
<div class="brand-text is-family-code is-uppercase has-text-weight-bold">GPT-2</div>
</div>
<div id="navbarBasicExample" class="navbar-menu is-active">
<div class="navbar-start">
<div class="navbar-item">
Generate pseudo-scripts from Spongebob from an AI model using GPT-2 (using the 117M default model)
</div>
</div>
<div class="navbar-end">
<div class="navbar-item is-hidden-touch">
<div class="buttons">
<a class="button is-light" href="https://github.com/ajsanjoaquin/spongebobNLP" target="_blank">
<span class="icon">
<i class="fab fa-lg fa-github"></i>
</span><span>GitHub</span>
</a>
</div>
</div>
</div>
</div>
</nav>
<body>
<section id="main" class="section">
<div class="container">
<div class="columns is-variable is-5">
<div class="column is-narrow" style="width: 250px;">
<form id="gen-form">
<div class="field">
<label class="label">Text Prompt</label>
<div class="control">
<textarea id="prefix" class="textarea" type="text" placeholder="Mr. Krabs:" rows="2"></textarea>
</div>
<p class="help">Starts the generated text with the specified text. <em>Must end with a colon (:)</em></p>
</div>
<div class="field">
<label class="label">Generated Text Length</label>
<div class="control">
<input id="length" class="input" type="text" placeholder="Text input" value="100">
</div>
<p class="help">Length of the text in tokens to generate. <em>(max: 1023)</em></p>
</div>
<div class="field">
<label class="label">Temperature</label>
<div class="control">
<input id="temperature" class="input" type="text" placeholder="0.7" value="0.7">
</div>
<p class="help">Controls the generated text "creativity." <em>(the higher the temperature, the more
creative)</em></p>
</div>
<div class="field">
<label class="label">Top <em>k</em></label>
<div class="control">
<input id="top_k" class="input" type="text" placeholder="40" value="40">
</div>
<p class="help">Constrains the generated text tokens to the top <em>k</em> possibilities. <em>(set to 0 to
disable)</em></p>
</div>
<div class="buttons">
<span class="control">
<button type="submit" name="submit" id="generate-text" class="button is-link">
<span class="icon">
<i class="fas fa-md fa-pen"></i>
</span><span>Generate Text!</span></button>
</span>
</div>
</form>
<div id="extra-buttons" class="buttons">
<span class="control">
<button id="save-image" class="button is-success">
<span class="icon">
<i class="fas fa-md fa-save"></i>
</span><span>Save Image</span></button>
</span>
<span class="control">
<button id="clear-text" class="button is-danger">
<span class="icon">
<i class="fas fa-md fa-trash-alt"></i>
</span><span>Clear Texts</span</button> </span> </div> </div> <div id="model-output" class="column">
<p id="tutorial" class="subtitle"><em>Generated text will appear here!
Use the form to configure GPT-2 and press <strong>Generate Text</strong>
to get your own text!
</em></p>
</div>
</div>
</div>
</section>
<footer class="footer">
<div class="content has-text-centered">
<p>
Made using <a href="https://github.com/minimaxir/gpt-2-simple" target="_blank"><strong>gpt-2-simple</strong></a>
and <a href="https://github.com/minimaxir/gpt-2-cloud-run" target="_blank"><strong>gpt-2-cloud-run</strong></a>
by <a href="https://minimaxir.com" target="_blank">Max Woolf</a>. Fine-tuned with <a href="https://github.com/SuminHan/NLP-SpongeBob">Spongebob episode transcripts </a> by Ayrton San Joaquin. Original GPT-2 model provided by <a
href="https://openai.com" target="_blank">OpenAI</a>. This webpage content
is licensed <a href="http://opensource.org/licenses/mit-license.php" target="_blank">MIT</a>.
</p>
</div>
</footer>
</body>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous">
</script>
<script src="http://html2canvas.hertzen.com/dist/html2canvas.min.js">
</script>
<script type="text/javascript">
$(function () {
$('#gen-form').submit(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "https://spongebob-7txc5qzmja-an.a.run.app", //modified to spongebob
dataType: "json",
data: JSON.stringify(getInputValues()),
beforeSend: function (data) {
$('#generate-text').addClass("is-loading");
$('#generate-text').prop("disabled", true);
},
success: function (data) {
$('#generate-text').removeClass("is-loading");
$('#generate-text').prop("disabled", false);
$('#tutorial').remove();
var gentext = data.text;
if ($("#prefix").length & $("#prefix").val() != '') {
var pattern = new RegExp('^' + $("#prefix").val(), 'g');
var gentext = gentext.replace(pattern, '<strong>' + $("#prefix").val() + '</strong>');
}
var gentext = gentext.replace(/\n\n/g, "<div><br></div>").replace(/\n/g, "<div></div>");
var html = '<div class=\"gen-box\">' + gentext + '</div><div class="gen-border"></div>';
$(html).appendTo('#model-output').hide().fadeIn("slow");
},
error: function (jqXHR, textStatus, errorThrown) {
$('#generate-text').removeClass("is-loading");
$('#generate-text').prop("disabled", false);
$('#tutorial').remove();
var html = '<div class="gen-box warning">There was an error generating the text! Please try again!</div><div class="gen-border"></div>';
$(html).appendTo('#model-output').hide().fadeIn("slow");
}
});
});
$('#clear-text').click(function (e) {
$('#model-output').text('')
});
// https://stackoverflow.com/a/51478809
$("#save-image").click(function () {
html2canvas(document.querySelector('#model-output')).then(function (canvas) {
saveAs(canvas.toDataURL(), 'gen_texts.png');
});
});
});
function getInputValues() {
var inputs = {};
$("textarea, input").each(function () {
inputs[$(this).attr('id')] = $(this).val();
});
return inputs;
}
// https://stackoverflow.com/a/51478809
function saveAs(uri, filename) {
var link = document.createElement('a');
if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;
//Firefox requires the link to be in the body
document.body.appendChild(link);
//simulate click
link.click();
//remove the link when done
document.body.removeChild(link);
} else {
window.open(uri);
}
}
</script>
</html>