sarahciston commited on
Commit
7c5c6b0
·
verified ·
1 Parent(s): f1a49f4

add more interface

Browse files
Files changed (1) hide show
  1. sketch.js +67 -46
sketch.js CHANGED
@@ -124,60 +124,94 @@ new p5(function (p5){
124
  p5.setup = function(){
125
  p5.noCanvas()
126
  console.log('p5 instance loaded')
127
- makeTextDisplay()
128
- makeFields()
129
- makeButtons()
130
  }
131
 
132
- p5.draw = function(){
133
- //
134
- }
135
-
136
- function makeTextDisplay(){
137
  const introDiv = p5.createDiv().class('module').id('intro')
138
- p5.createElement('h1','p5.js Critical AI Prompt Battle')
139
  p5.createP(`What do AI models really 'know' about you — about your community, your language, your culture? What do they 'know' about different concepts, ideas, and worldviews?`).parent(introDiv)
140
  p5.createP(`This tool lets you compare the results of multiple AI-generated texts and images side-by-side, using blanks you fill in to explore variations on a single prompt. For more info on prompt programming and critical AI, see [TUTORIAL-LINK].`).parent(introDiv)
141
 
142
  const instructDiv = p5.createDiv().class('module').id('instructions')
143
- p5.createElement('h2', 'Instructions')
144
  p5.createP(`Write your prompt using [BLANK] and [MASK], where [BLANK] will be the variation you choose and fill in below, and [MASK] is a variation that the model will complete.`).parent(instructDiv)
145
  p5.createP(`For best results, try to phrase your prompt so that [BLANK] and [MASK] highlight the qualities you want to investigate. <A href="http://p5js.org">See examples.</a>`).parent(instructDiv)
146
  }
147
 
148
- function makeFields(){
149
- promptField = p5.createInput(PROMPT_INPUT) // turns the string into an input; now access the text via PROMPT_INPUT.value()
 
 
 
 
 
 
 
150
  promptField.size(700)
151
- // promptField.attribute('label', `Write a text prompt with one [MASK] that the model will fill in.`)
152
- p5.createP(promptField.attribute('label'))
153
  promptField.addClass("prompt")
154
 
155
- const fieldsDiv = p5.createDiv()
156
- fieldsDiv.id('fieldsDiv')
 
157
 
158
  addField()
159
- }
160
-
161
- function makeButtons(){
162
-
163
- // press to add more blanks to fill in
164
- const addButton = p5.createButton("more blanks")
165
- addButton.size(170)
166
- // addButton.position(220,500)
167
- addButton.mousePressed(addField)
168
 
169
  // press to run model
170
- const submitButton = p5.createButton("SUBMIT")
171
  submitButton.size(170)
172
- submitButton.class('submit')
173
  submitButton.mousePressed(displayResults)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
- // also make results placeholder
176
- const outHeader = p5.createElement('h3',"Results")
177
- outText = p5.createP('').id('results')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  }
179
 
180
- async function displayResults(){
181
  console.log('submitButton pressed')
182
 
183
  // insert waiting dots into results space of interface
@@ -203,22 +237,9 @@ new p5(function (p5){
203
  await outText.html(outs, false) // false replaces text instead of appends
204
  }
205
 
206
- function addField(){
207
- let f = p5.createInput("")
208
- f.class("blank")
209
- f.parent("#fieldsDiv")
210
-
211
- blanksArray.push(f)
212
- console.log("made variable field")
213
-
214
- // Cap the number of fields, avoids token limit in prompt
215
- let blanks = document.querySelectorAll(".blank")
216
- if (blanks.length > 3){
217
- console.log(blanks.length)
218
- addButton.style('visibility','hidden')
219
- }
220
  }
221
-
222
  });
223
 
224
 
 
124
  p5.setup = function(){
125
  p5.noCanvas()
126
  console.log('p5 instance loaded')
127
+ makeTextModules()
128
+ makeInputModule()
129
+ makeOutputModule()
130
  }
131
 
132
+ function makeTextModules(){
 
 
 
 
133
  const introDiv = p5.createDiv().class('module').id('intro')
134
+ p5.createElement('h1','p5.js Critical AI Prompt Battle').parent(introDiv)
135
  p5.createP(`What do AI models really 'know' about you — about your community, your language, your culture? What do they 'know' about different concepts, ideas, and worldviews?`).parent(introDiv)
136
  p5.createP(`This tool lets you compare the results of multiple AI-generated texts and images side-by-side, using blanks you fill in to explore variations on a single prompt. For more info on prompt programming and critical AI, see [TUTORIAL-LINK].`).parent(introDiv)
137
 
138
  const instructDiv = p5.createDiv().class('module').id('instructions')
139
+ p5.createElement('h4', 'INSTRUCTIONS').class('header').parent(instructDiv)
140
  p5.createP(`Write your prompt using [BLANK] and [MASK], where [BLANK] will be the variation you choose and fill in below, and [MASK] is a variation that the model will complete.`).parent(instructDiv)
141
  p5.createP(`For best results, try to phrase your prompt so that [BLANK] and [MASK] highlight the qualities you want to investigate. <A href="http://p5js.org">See examples.</a>`).parent(instructDiv)
142
  }
143
 
144
+ function makeInputModule(){
145
+ const inputDiv = p5.createDiv()
146
+ inputDiv.id('inputDiv').class('module')
147
+ p5.createElement('h4', 'INPUT').class('header').parent(inputDiv)
148
+ p5.createElement('h3', 'Enter your prompt').class('header').parent(inputDiv)
149
+ p5.createP('Write your prompt in the box below using one [BLANK] and one [MASK].').parent(inputDiv)
150
+ p5.createP('e.g. Write "The [BLANK] was a [MASK]..." and in the three blanks choose three occupations.').parent(inputDiv)
151
+ p5.createP('(This is taken from an actual example used to test GPT-3. (Brown et al. 2020).)').class('caption').parent(inputDiv)
152
+ promptField = p5.createInput(PROMPT_INPUT).parent(inputDiv) // turns the string into an input; now access the text via PROMPT_INPUT.value()
153
  promptField.size(700)
154
+ p5.createP(promptField.attribute('label')).parent(inputDiv)
 
155
  promptField.addClass("prompt")
156
 
157
+ p5.createElement('h3', 'Fill in your blanks').class('header').parent(inputDiv)
158
+ p5.createP('Add three words or phrases in the boxes below that will replace the [BLANK] in your prompt when the model runs.').parent(inputDiv)
159
+ p5.createP('(e.g. doctor, secretary, circus performer)').parent(inputDiv)
160
 
161
  addField()
162
+ addField()
163
+ addField()
 
 
 
 
 
 
 
164
 
165
  // press to run model
166
+ const submitButton = p5.createButton("RUN PROMPT")
167
  submitButton.size(170)
168
+ submitButton.class('button').parent(inputDiv)
169
  submitButton.mousePressed(displayResults)
170
+ }
171
+
172
+ function addField(){
173
+ let f = p5.createInput("").parent(inputDiv)
174
+ f.class("blank")
175
+ // f.parent("#inputDiv")
176
+ blanksArray.push(f)
177
+ console.log("made variable field")
178
+ // // Cap the number of fields, avoids token limit in prompt
179
+ // let blanks = document.querySelectorAll(".blank")
180
+ // if (blanks.length > 3){
181
+ // console.log(blanks.length)
182
+ // addButton.style('visibility','hidden')
183
+ // }
184
+ }
185
 
186
+ // function makeButtons(){
187
+ // // // press to add more blanks to fill in
188
+ // // const addButton = p5.createButton("more blanks")
189
+ // // addButton.size(170)
190
+ // // // addButton.position(220,500)
191
+ // // addButton.mousePressed(addField)
192
+ // }
193
+
194
+ function makeOutputModule(){
195
+ const outDiv() = p5.createDiv()
196
+ outDiv.id('outputDiv').class('module')
197
+ const outHeader = p5.createElement('h4',"OUTPUT").parent(outDiv)
198
+
199
+ //make output placeholders
200
+
201
+ // text-only output
202
+ p5.createElement('h3', 'Text output').class('header').parent(outDiv)
203
+ outText = p5.createP('').id('outText').parent(outDiv)
204
+
205
+ //a placeholder DIV for images and captions
206
+ p5.createElement('h3', 'Text-to-image output').class('header').parent(outDiv)
207
+ outPics = p5.createDiv().id('outPics').parent(outDiv)
208
+ // img1 = p5.createImg('URL')
209
+
210
+ p5.createElement('h3', 'Prompting info').class('header').parent(outDiv)
211
+ outInfo = p5.createP('').id('outInfo').parent(OutDiv)
212
  }
213
 
214
+ async function displayOutput(){
215
  console.log('submitButton pressed')
216
 
217
  // insert waiting dots into results space of interface
 
237
  await outText.html(outs, false) // false replaces text instead of appends
238
  }
239
 
240
+ p5.draw = function(){
241
+ //
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
 
243
  });
244
 
245