Spaces:
Running
Running
update request fetch
Browse files
sketch.js
CHANGED
@@ -9,7 +9,6 @@ env.allowLocalModels = false;
|
|
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
|
@@ -29,6 +28,17 @@ var blanksArray = [] // an empty list to store all the variables we enter to mod
|
|
29 |
// out = JSON.stringify(out, null, 2)
|
30 |
// }
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
async function textImgTask(prompt){
|
33 |
console.log('text-to-image task initiated')
|
34 |
|
@@ -39,23 +49,19 @@ async function textImgTask(prompt){
|
|
39 |
const height = 1024
|
40 |
const guidaneceScale = 3.5
|
41 |
const inferenceSteps = 8
|
42 |
-
const options = [ prompt[0], seed, randomizeSeed, width, height, guidaneceScale, inferenceSteps ]
|
43 |
|
44 |
-
const
|
45 |
-
method: "POST",
|
46 |
-
body: JSON.stringify({"data": options }),
|
47 |
-
headers: {
|
48 |
-
"Content-Type": "application/json"
|
49 |
-
}
|
50 |
-
})
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
|
56 |
-
|
57 |
|
58 |
-
|
|
|
59 |
|
60 |
return out
|
61 |
}
|
@@ -295,8 +301,8 @@ new p5(function (p5){
|
|
295 |
await outText.html(outs, false) // false valuereplaces text, true appends text
|
296 |
|
297 |
let outPic = await textImgTask(promptArray)
|
298 |
-
console.log(outPic)
|
299 |
-
p5.createImage(outPic.url)
|
300 |
}
|
301 |
|
302 |
p5.draw = function(){
|
|
|
9 |
|
10 |
var promptArray = []
|
11 |
var PREPROMPT = `Please continue each sentence, filling in [MASK] with your own words:`
|
|
|
12 |
|
13 |
var PROMPT_INPUT = `` // a field for writing or changing a text value
|
14 |
var promptField // an html element to hold the prompt
|
|
|
28 |
// out = JSON.stringify(out, null, 2)
|
29 |
// }
|
30 |
|
31 |
+
// GENERIC API CALL HANDLING
|
32 |
+
async function post(request) {
|
33 |
+
try {
|
34 |
+
const response = await fetch(request);
|
35 |
+
const result = await response.json();
|
36 |
+
console.log("Success:", result);
|
37 |
+
} catch (error) {
|
38 |
+
console.error("Error:", error);
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
async function textImgTask(prompt){
|
43 |
console.log('text-to-image task initiated')
|
44 |
|
|
|
49 |
const height = 1024
|
50 |
const guidaneceScale = 3.5
|
51 |
const inferenceSteps = 8
|
|
|
52 |
|
53 |
+
const options = [ prompt[0], seed, randomizeSeed, width, height, guidaneceScale, inferenceSteps ]
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
const request = new Request(URL,{
|
56 |
+
method: "POST",
|
57 |
+
body: JSON.stringify({"data": options }),
|
58 |
+
headers: { "Content-Type": "application/json" }
|
59 |
+
})
|
60 |
|
61 |
+
let out = post(request)
|
62 |
|
63 |
+
console.log(out)
|
64 |
+
console.log("text-to-image task completed")
|
65 |
|
66 |
return out
|
67 |
}
|
|
|
301 |
await outText.html(outs, false) // false valuereplaces text, true appends text
|
302 |
|
303 |
let outPic = await textImgTask(promptArray)
|
304 |
+
console.log(outPic[1])
|
305 |
+
p5.createImage(outPic[1].url)
|
306 |
}
|
307 |
|
308 |
p5.draw = function(){
|