Skip to content

Commit 896650d

Browse files
eps1lonannxingyuan
andauthored
[toxicity] Improve demo accessibility (#510)
Co-authored-by: Ann Yuan <[email protected]>
1 parent 5a65fce commit 896650d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

toxicity/demo/index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#classify-new-text-input {
8484
border: none;
8585
border-bottom: solid 1px #ccc;
86+
cursor: pointer;
8687
font-size: 14px;
8788
line-height: 2;
8889
width: calc(100% - 127px);
@@ -98,7 +99,7 @@
9899
}
99100

100101
#classify-new-text {
101-
cursor: pointer;
102+
border: none;
102103
text-transform: uppercase;
103104
padding: 9px 14px 9px 14px;
104105
font-size: 13px;
@@ -126,10 +127,10 @@ <h1>TensorFlow.js toxicity classifier demo</h1>
126127
<div class="description">This is a demo of the TensorFlow.js toxicity model, which classifies text according to whether it exhibits offensive attributes (i.e. profanity, sexual explicitness). The samples in the table below were taken from this <a href="https://www.kaggle.com/c/jigsaw-toxic-comment-classification-challenge/data">Kaggle dataset</a>.</div>
127128
<div id="table-wrapper"></div>
128129
<p>Enter text below and click 'Classify' to add it to the table.</p>
129-
<div>
130-
<input id="classify-new-text-input" placeholder="i.e. 'you suck'">
131-
<div id="classify-new-text">Classify</div>
132-
</div>
130+
<form id="classify-new">
131+
<input id="classify-new-text-input" placeholder="i.e. 'you suck'" required="">
132+
<button id="classify-new-text" type="submit">Classify</div>
133+
</form>
133134
</div>
134135
<script src="index.js"></script>
135136
</body>

toxicity/demo/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ const predict = async () => {
8383
const predictions = await classify(samples.map(d => d.text));
8484
addPredictions(predictions);
8585

86-
document.querySelector('#classify-new-text')
87-
.addEventListener('click', (e) => {
86+
document.querySelector('#classify-new')
87+
.addEventListener('submit', (e) => {
8888
const text = document.querySelector('#classify-new-text-input').value;
8989
const predictions = classify([text]).then(d => {
9090
addPredictions(d);
9191
});
92+
93+
// Prevent submitting the form which would cause a page reload.
94+
e.preventDefault();
9295
});
9396
};
9497

95-
predict();
98+
predict();

0 commit comments

Comments
 (0)