Spaces:
Running
Running
try to add image fetch call
Browse files
sketch.js
CHANGED
@@ -7,11 +7,15 @@ env.allowLocalModels = false;
|
|
7 |
|
8 |
// GLOBAL VARIABLES
|
9 |
|
|
|
10 |
var PREPROMPT = `Please continue each sentence, filling in [MASK] with your own words:`
|
|
|
|
|
11 |
var PROMPT_INPUT = `` // a field for writing or changing a text value
|
12 |
var promptField // an html element to hold the prompt
|
13 |
var outText, outPics, outInfo // html elements to hold the results
|
14 |
var blanksArray = [] // an empty list to store all the variables we enter to modify the prompt
|
|
|
15 |
// e.g. ["woman", "man", "non-binary person"]
|
16 |
|
17 |
// // RUN IMAGE CAPTIONER //// W-I-P
|
@@ -25,23 +29,53 @@ var blanksArray = [] // an empty list to store all the variables we enter to mod
|
|
25 |
// out = JSON.stringify(out, null, 2)
|
26 |
// }
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
// RUN TEXT-GEN MODEL
|
29 |
|
30 |
-
async function textGenTask(pre, prompt, blanks){
|
|
|
31 |
console.log('text-gen task initiated')
|
32 |
|
33 |
// Create concatenated prompt array including preprompt and all variable prompts
|
34 |
-
let promptArray = []
|
35 |
-
|
36 |
|
37 |
-
// Fill in blanks from our sample prompt and make new prompts using our variable list 'blanksArray'
|
38 |
-
blanks.forEach(b => {
|
39 |
-
|
40 |
-
|
41 |
-
})
|
42 |
|
43 |
// create combined fill prompt
|
44 |
-
let INPUT =
|
45 |
console.log(INPUT)
|
46 |
// let INPUT = pre + prompt // simple concatenated input
|
47 |
// let INPUT = prompt // basic prompt input
|
@@ -230,20 +264,31 @@ new p5(function (p5){
|
|
230 |
PROMPT_INPUT = promptField.value() // grab update to the prompt if it's been changed
|
231 |
console.log("latest prompt: ", PROMPT_INPUT)
|
232 |
|
233 |
-
|
234 |
blanksArray.forEach(b => {
|
235 |
blanksValues.push(b.value())
|
236 |
})
|
237 |
console.log(blanksValues)
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
// call the function that runs the model for the task of your choice here
|
241 |
// make sure to use the PROMPT_INPUT as a parameter, or also the PREPROMPT if valid for that task
|
242 |
-
let outs = await textGenTask(PREPROMPT, PROMPT_INPUT, blanksValues)
|
|
|
|
|
243 |
console.log(outs)
|
244 |
|
245 |
// insert the model outputs into the paragraph
|
246 |
await outText.html(outs, false) // false valuereplaces text, true appends text
|
|
|
|
|
|
|
247 |
}
|
248 |
|
249 |
p5.draw = function(){
|
|
|
7 |
|
8 |
// GLOBAL VARIABLES
|
9 |
|
10 |
+
var promptArray = []
|
11 |
var PREPROMPT = `Please continue each sentence, filling in [MASK] with your own words:`
|
12 |
+
promptArray.push(PREPROMPT) // add preprompt to the list of prompts
|
13 |
+
|
14 |
var PROMPT_INPUT = `` // a field for writing or changing a text value
|
15 |
var promptField // an html element to hold the prompt
|
16 |
var outText, outPics, outInfo // html elements to hold the results
|
17 |
var blanksArray = [] // an empty list to store all the variables we enter to modify the prompt
|
18 |
+
|
19 |
// e.g. ["woman", "man", "non-binary person"]
|
20 |
|
21 |
// // RUN IMAGE CAPTIONER //// W-I-P
|
|
|
29 |
// out = JSON.stringify(out, null, 2)
|
30 |
// }
|
31 |
|
32 |
+
async function textImgTask(prompt){
|
33 |
+
const URL = 'https://multimodalart-flux-1-merged.hf.space/call/infer'
|
34 |
+
const seed = 0
|
35 |
+
const randomizeSeed = true
|
36 |
+
const width = 1024
|
37 |
+
const height = 1024
|
38 |
+
const guidaneceScale = 3.5
|
39 |
+
const inferenceSteps = 8
|
40 |
+
const options = [ prompt[0], seed, randomizeSeed, width, height, guidaneceScale, inferenceSteps ]
|
41 |
+
|
42 |
+
const res = await fetch(URL, {
|
43 |
+
method: "POST",
|
44 |
+
body: JSON.stringify({"data": options })
|
45 |
+
headers: {
|
46 |
+
"Content-Type": "application/json",
|
47 |
+
}
|
48 |
+
})
|
49 |
+
|
50 |
+
let data = await res.json()
|
51 |
+
|
52 |
+
console.log(data)
|
53 |
+
|
54 |
+
let out = await data[0]
|
55 |
+
|
56 |
+
return out
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
// RUN TEXT-GEN MODEL
|
62 |
|
63 |
+
// async function textGenTask(pre, prompt, blanks){
|
64 |
+
async function textGenTask(pre, prompts)
|
65 |
console.log('text-gen task initiated')
|
66 |
|
67 |
// Create concatenated prompt array including preprompt and all variable prompts
|
68 |
+
// let promptArray = []
|
69 |
+
let PROMPTS = input.unshift(pre) //adds the preprompt to the front of the prompts list
|
70 |
|
71 |
+
// // Fill in blanks from our sample prompt and make new prompts using our variable list 'blanksArray'
|
72 |
+
// blanks.forEach(b => {
|
73 |
+
// let p = prompt.replace('[BLANK]', b) // replace the string segment with an item from the blanksArray
|
74 |
+
// promptArray.push(p) // add the new prompt to the list we created
|
75 |
+
// })
|
76 |
|
77 |
// create combined fill prompt
|
78 |
+
let INPUT = PROMPTS.toString()
|
79 |
console.log(INPUT)
|
80 |
// let INPUT = pre + prompt // simple concatenated input
|
81 |
// let INPUT = prompt // basic prompt input
|
|
|
264 |
PROMPT_INPUT = promptField.value() // grab update to the prompt if it's been changed
|
265 |
console.log("latest prompt: ", PROMPT_INPUT)
|
266 |
|
267 |
+
// create a list of the values in the blanks fields
|
268 |
blanksArray.forEach(b => {
|
269 |
blanksValues.push(b.value())
|
270 |
})
|
271 |
console.log(blanksValues)
|
272 |
+
|
273 |
+
// Fill in blanks from our sample prompt and make new prompts using our variable list 'blanksArray'
|
274 |
+
blanks.forEach(b => {
|
275 |
+
let p = prompt.replace('[BLANK]', b) // replace the string segment with an item from the blanksArray
|
276 |
+
promptArray.push(p) // add the new prompt to the list we created
|
277 |
+
})
|
278 |
+
console.log(promptArray)
|
279 |
|
280 |
// call the function that runs the model for the task of your choice here
|
281 |
// make sure to use the PROMPT_INPUT as a parameter, or also the PREPROMPT if valid for that task
|
282 |
+
// let outs = await textGenTask(PREPROMPT, PROMPT_INPUT, blanksValues)
|
283 |
+
|
284 |
+
let outs = await textGenTask(PREPROMPT, promptArray)
|
285 |
console.log(outs)
|
286 |
|
287 |
// insert the model outputs into the paragraph
|
288 |
await outText.html(outs, false) // false valuereplaces text, true appends text
|
289 |
+
|
290 |
+
let outPic = await textImgTask(promptArray)
|
291 |
+
p5.createImage(outPic)
|
292 |
}
|
293 |
|
294 |
p5.draw = function(){
|