Spaces:
Running
Running
simplify test, only console log
Browse files
index.js
CHANGED
|
@@ -7,6 +7,7 @@ env.allowLocalModels = false;
|
|
| 7 |
|
| 8 |
// GLOBAL VARIABLES
|
| 9 |
var PROMPT_INPUT = `The vice president [MASK] after returning from war.` // a field for writing or changing a text value
|
|
|
|
| 10 |
var OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 11 |
|
| 12 |
|
|
@@ -14,25 +15,27 @@ var OUTPUT_LIST = [] // a blank array to store the results from the model
|
|
| 14 |
async function fillInTask(){
|
| 15 |
console.log('fill-in task initiated')
|
| 16 |
|
|
|
|
|
|
|
| 17 |
const pipe = await pipeline('fill-mask', 'Xenova/bert-base-uncased');
|
| 18 |
|
| 19 |
var out = await pipe(PROMPT_INPUT);
|
| 20 |
|
| 21 |
console.log(await out) // yields { score, sequence, token, token_str } for each result
|
| 22 |
|
| 23 |
-
await out.forEach(o => {
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
})
|
| 27 |
|
| 28 |
-
console.log(OUTPUT_LIST)
|
| 29 |
|
| 30 |
-
displayResults(OUTPUT_LIST)
|
| 31 |
|
| 32 |
console.log('fill-in task completed')
|
| 33 |
|
| 34 |
-
|
| 35 |
-
return await OUTPUT_LIST
|
| 36 |
}
|
| 37 |
|
| 38 |
// PROCESS MODEL OUTPUT
|
|
@@ -51,7 +54,7 @@ async function fillInTask(){
|
|
| 51 |
|
| 52 |
// await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
//// p5.js Instance
|
| 57 |
|
|
@@ -74,12 +77,13 @@ new p5(function (p5){
|
|
| 74 |
}
|
| 75 |
|
| 76 |
function makeFields(){
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
p5.createP(
|
| 81 |
-
|
| 82 |
-
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
function makeButtons(){
|
|
@@ -89,11 +93,12 @@ new p5(function (p5){
|
|
| 89 |
submitButton.mousePressed(fillInTask)
|
| 90 |
}
|
| 91 |
|
| 92 |
-
function displayResults(
|
| 93 |
console.log('displayed or pressed')
|
|
|
|
| 94 |
let outHead = p5.createElement('h4',"Results:")
|
| 95 |
let outText = p5.createP('')
|
| 96 |
-
outText.html(
|
| 97 |
}
|
| 98 |
|
| 99 |
// async function makeOutputDisplay(){
|
|
|
|
| 7 |
|
| 8 |
// GLOBAL VARIABLES
|
| 9 |
var PROMPT_INPUT = `The vice president [MASK] after returning from war.` // a field for writing or changing a text value
|
| 10 |
+
var pField
|
| 11 |
var OUTPUT_LIST = [] // a blank array to store the results from the model
|
| 12 |
|
| 13 |
|
|
|
|
| 15 |
async function fillInTask(){
|
| 16 |
console.log('fill-in task initiated')
|
| 17 |
|
| 18 |
+
PROMPT_INPUT = pField.value()
|
| 19 |
+
|
| 20 |
const pipe = await pipeline('fill-mask', 'Xenova/bert-base-uncased');
|
| 21 |
|
| 22 |
var out = await pipe(PROMPT_INPUT);
|
| 23 |
|
| 24 |
console.log(await out) // yields { score, sequence, token, token_str } for each result
|
| 25 |
|
| 26 |
+
// await out.forEach(o => {
|
| 27 |
+
// console.log(o) // yields { score, sequence, token, token_str } for each result
|
| 28 |
+
// OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
|
| 29 |
+
// })
|
| 30 |
|
| 31 |
+
// console.log(await OUTPUT_LIST)
|
| 32 |
|
| 33 |
+
// displayResults(await OUTPUT_LIST)
|
| 34 |
|
| 35 |
console.log('fill-in task completed')
|
| 36 |
|
| 37 |
+
return await out
|
| 38 |
+
// return await OUTPUT_LIST
|
| 39 |
}
|
| 40 |
|
| 41 |
// PROCESS MODEL OUTPUT
|
|
|
|
| 54 |
|
| 55 |
// await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
|
| 56 |
|
| 57 |
+
await fillInTask()
|
| 58 |
|
| 59 |
//// p5.js Instance
|
| 60 |
|
|
|
|
| 77 |
}
|
| 78 |
|
| 79 |
function makeFields(){
|
| 80 |
+
pField = p5.createInput(PROMPT_INPUT) // turns the string into an input; now access the text via PROMPT_INPUT.value()
|
| 81 |
+
pField.size(700)
|
| 82 |
+
pField.attribute('label', `Write a text prompt with at least one [MASK] that the model will fill in.`)
|
| 83 |
+
p5.createP(pField.attribute('label'))
|
| 84 |
+
pField.addClass("prompt")
|
| 85 |
+
pField.value(PROMPT_INPUT)
|
| 86 |
+
console.log(pField.value())
|
| 87 |
}
|
| 88 |
|
| 89 |
function makeButtons(){
|
|
|
|
| 93 |
submitButton.mousePressed(fillInTask)
|
| 94 |
}
|
| 95 |
|
| 96 |
+
async function displayResults(text){
|
| 97 |
console.log('displayed or pressed')
|
| 98 |
+
text = str(text)
|
| 99 |
let outHead = p5.createElement('h4',"Results:")
|
| 100 |
let outText = p5.createP('')
|
| 101 |
+
await outText.html(text)
|
| 102 |
}
|
| 103 |
|
| 104 |
// async function makeOutputDisplay(){
|