sarahciston commited on
Commit
2988cff
1 Parent(s): 227827f

reverse the function flow

Browse files
Files changed (1) hide show
  1. index.js +39 -25
index.js CHANGED
@@ -12,35 +12,42 @@ var OUTPUT_LIST = [] // a blank array to store the results from the model
12
 
13
  // RUN MODEL
14
  async function fillInTask(){
 
 
15
  const pipe = await pipeline('fill-mask', 'Xenova/bert-base-uncased');
16
 
17
  var out = await pipe(PROMPT_INPUT);
18
 
19
  console.log(await out) // yields { score, sequence, token, token_str } for each result
20
 
21
- // await out.forEach(o => {
22
- // console.log(o) // yields { score, sequence, token, token_str } for each result
23
- // OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
24
- // })
25
 
26
- // console.log(OUTPUT_LIST)
 
 
27
 
28
- return await out
 
 
 
29
  }
30
 
31
  // PROCESS MODEL OUTPUT
32
  // a generic function to pass in different model task functions
33
- async function getOutputs(task){
34
- let output = await task
35
 
36
- await output.forEach(o => {
37
- OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
38
- })
39
 
40
- console.log(OUTPUT_LIST)
41
 
42
- return await OUTPUT_LIST
43
- }
44
 
45
  // await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
46
 
@@ -78,22 +85,29 @@ new p5(function (p5){
78
  let submitButton = p5.createButton("SUBMIT")
79
  submitButton.size(170)
80
  submitButton.class('submit')
81
- submitButton.mousePressed(makeOutputDisplay)
 
 
 
 
 
 
 
82
  }
83
 
84
- async function makeOutputDisplay(){
85
- console.log('button pressed')
86
- let outHead = p5.createElement('h4',"Results:")
87
 
88
- let out = await fillInTask() //just model no parsing
89
- // let out = await getOutputs(fillInTask()) // model and parsing
90
 
91
- out = str(await out)
92
- console.log(out)
93
 
94
- let outText = p5.createP('')
95
- await outText.html(out)
96
- }
97
 
98
  });
99
 
 
12
 
13
  // RUN 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
+ console.log(o) // yields { score, sequence, token, token_str } for each result
25
+ OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
26
+ })
27
 
28
+ console.log(OUTPUT_LIST)
29
+
30
+ displayResults(OUTPUT_LIST)
31
 
32
+ console.log('fill-in task completed')
33
+
34
+ // return await out
35
+ return await OUTPUT_LIST
36
  }
37
 
38
  // PROCESS MODEL OUTPUT
39
  // a generic function to pass in different model task functions
40
+ // async function getOutputs(task){
41
+ // let output = await task
42
 
43
+ // await output.forEach(o => {
44
+ // OUTPUT_LIST.push(o.sequence) // put only the full sequence in a list
45
+ // })
46
 
47
+ // console.log(OUTPUT_LIST)
48
 
49
+ // return await OUTPUT_LIST
50
+ // }
51
 
52
  // await getOutputs(fillInTask()) // getOutputs will later connect to the interface to display results
53
 
 
85
  let submitButton = p5.createButton("SUBMIT")
86
  submitButton.size(170)
87
  submitButton.class('submit')
88
+ submitButton.mousePressed(fillInTask)
89
+ }
90
+
91
+ function displayResults(list){
92
+ console.log('displayed or pressed')
93
+ let outHead = p5.createElement('h4',"Results:")
94
+ let outText = p5.createP('')
95
+ outText.html(list)
96
  }
97
 
98
+ // async function makeOutputDisplay(){
99
+ // console.log('button pressed')
100
+ // let outHead = p5.createElement('h4',"Results:")
101
 
102
+ // let out = await fillInTask() //just model no parsing
103
+ // // let out = await getOutputs(fillInTask()) // model and parsing
104
 
105
+ // out = str(await out)
106
+ // console.log(out)
107
 
108
+ // let outText = p5.createP('')
109
+ // await outText.html(out)
110
+ // }
111
 
112
  });
113