-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.js
60 lines (52 loc) · 1.67 KB
/
image.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require('dotenv').config();
const { v4: uuidv4 } = require('uuid');
function generateJobId() {
return "sdk_image_" + uuidv4();
}
async function main() {
console.log('Starting image generation job...');
const url = "http://sequencer.heurist.xyz/submit_job";
const apiKey = process.env.HEURIST_API_KEY;
const payload = {
"job_id": generateJobId(),
"model_input": {
"SD": {
"prompt": "A beautiful landscape with mountains and a river",
"neg_prompt": "Avoid any signs of human presence",
"num_iterations": 20,
"width": 1024,
"height": 512,
"guidance_scale": 7.5,
"seed": -1
}
},
"model_id": "HeuristLogo",
"deadline": 60,
"priority": 1
};
console.log('Job ID:', payload.job_id);
console.log('Submitting request to:', url);
try {
const response = await fetch(url, {
method: 'POST',
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) {
console.error('Request failed with status:', response.status);
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('Request successful. Response:', data);
return data;
} catch (error) {
console.error('Failed to generate image:', error.message);
throw error;
}
}
if (require.main === module) {
main().catch(console.error);
}