Spaces:
Running
Running
sarahciston
commited on
Commit
•
a02510b
1
Parent(s):
52d92f9
try accessing blanks array values at button push point, skip model run
Browse files
sketch.js
CHANGED
@@ -6,12 +6,15 @@ import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers
|
|
6 |
env.allowLocalModels = false;
|
7 |
|
8 |
// GLOBAL VARIABLES
|
9 |
-
|
10 |
let PREPROMPT = `Please continue the story, and fill any [MASK] with your own words:`
|
11 |
// let PREPROMPT = `Please complete the phrase and fill in any [MASK]: `
|
12 |
let PROMPT_INPUT = `The [BLANK] has a job as a [MASK] but...` // a field for writing or changing a text value
|
13 |
-
let pField
|
14 |
-
let outText
|
|
|
|
|
|
|
15 |
|
16 |
// RUN TEXT-GEN MODEL
|
17 |
|
@@ -22,10 +25,10 @@ async function textGenTask(pre, prompt, blanks){
|
|
22 |
let promptArray = []
|
23 |
promptArray.push(pre) // add preprompt to the list of prompts
|
24 |
|
25 |
-
// fill in blanks from our sample prompt and make new prompts
|
26 |
blanks.forEach(b => {
|
27 |
-
console.log(b)
|
28 |
-
let p = prompt.replace('[BLANK]', b) // replace the string segment with an
|
29 |
promptArray.push(p) // add the new prompt to the list we created
|
30 |
})
|
31 |
|
@@ -162,7 +165,7 @@ new p5(function (p5){
|
|
162 |
f.class("blank")
|
163 |
f.parent("#fieldsDiv")
|
164 |
|
165 |
-
|
166 |
console.log("made field")
|
167 |
|
168 |
// Cap the number of fields, avoids token limit in prompt
|
@@ -200,16 +203,17 @@ new p5(function (p5){
|
|
200 |
PROMPT_INPUT = pField.value() // grab update to the prompt if it's been changed
|
201 |
console.log("latest prompt: ", PROMPT_INPUT)
|
202 |
|
203 |
-
console.log(
|
204 |
-
|
|
|
|
|
|
|
205 |
|
206 |
-
//
|
207 |
-
//
|
208 |
-
let outs = await textGenTask(PREPROMPT, PROMPT_INPUT, blankArray)
|
209 |
-
console.log(outs)
|
210 |
|
211 |
-
// insert the model outputs into the paragraph
|
212 |
-
await outText.html(outs, false) // false replaces text instead of appends
|
213 |
}
|
214 |
|
215 |
});
|
|
|
6 |
env.allowLocalModels = false;
|
7 |
|
8 |
// GLOBAL VARIABLES
|
9 |
+
|
10 |
let PREPROMPT = `Please continue the story, and fill any [MASK] with your own words:`
|
11 |
// let PREPROMPT = `Please complete the phrase and fill in any [MASK]: `
|
12 |
let PROMPT_INPUT = `The [BLANK] has a job as a [MASK] but...` // a field for writing or changing a text value
|
13 |
+
let pField // an html element for the prompt
|
14 |
+
let outText // an html element for the results
|
15 |
+
let blanksArray = []
|
16 |
+
// a list for all the variable inputs, e.g. ["woman", "man", "non-binary person"]
|
17 |
+
|
18 |
|
19 |
// RUN TEXT-GEN MODEL
|
20 |
|
|
|
25 |
let promptArray = []
|
26 |
promptArray.push(pre) // add preprompt to the list of prompts
|
27 |
|
28 |
+
// fill in blanks from our sample prompt and make new prompts using our variable list 'blanksArray'
|
29 |
blanks.forEach(b => {
|
30 |
+
console.log(b.value())
|
31 |
+
let p = prompt.replace('[BLANK]', b.value()) // replace the string segment with an item from the blanksArray
|
32 |
promptArray.push(p) // add the new prompt to the list we created
|
33 |
})
|
34 |
|
|
|
165 |
f.class("blank")
|
166 |
f.parent("#fieldsDiv")
|
167 |
|
168 |
+
blanksArray.push(f)
|
169 |
console.log("made field")
|
170 |
|
171 |
// Cap the number of fields, avoids token limit in prompt
|
|
|
203 |
PROMPT_INPUT = pField.value() // grab update to the prompt if it's been changed
|
204 |
console.log("latest prompt: ", PROMPT_INPUT)
|
205 |
|
206 |
+
console.log(blanksArray)
|
207 |
+
blanksArray.forEach(b => console.log(b))
|
208 |
+
|
209 |
+
// // call the function that runs the model for the task of your choice here
|
210 |
+
// // make sure to use the PROMPT_INPUT as a parameter, or also the PREPROMPT if valid for that task
|
211 |
|
212 |
+
// // let outs = await textGenTask(PREPROMPT, PROMPT_INPUT, blanksArray)
|
213 |
+
// console.log(outs)
|
|
|
|
|
214 |
|
215 |
+
// // insert the model outputs into the paragraph
|
216 |
+
// await outText.html(outs, false) // false replaces text instead of appends
|
217 |
}
|
218 |
|
219 |
});
|