-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathasticaDesign_sample.js
More file actions
71 lines (60 loc) · 2.59 KB
/
Copy pathasticaDesign_sample.js
File metadata and controls
71 lines (60 loc) · 2.59 KB
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
61
62
63
64
65
66
67
68
69
70
71
const axios = require('axios');
var asticaAPI_timeout = 60;
var asticaAPI_key = 'YOUR API KEY'; // Put your API key here
// See Input Documentation: https://astica.ai/design/documentation/#inputs
var asticaAPI_endpoint = 'https://design.astica.ai/generate_image';
var asticaAPI_modelVersion = '2.0_full';
var asticaAPI_prompt = 'close-up photography of older gentleman standing in the rain at night, in a street lit by lamps';
var asticaAPI_prompt_negative = '';
var asticaAPI_generate_quality = 'faster'; //high, standard, fast, faster
var asticaAPI_generate_lossless = 0; //0 = Default JPG, 1 = lossless uncompressed PNG
var asticaAPI_seed = 0; //0 will randomize the seed for every generation
var asticaAPI_moderate = 1;
var asticaAPI_low_priority = 0; //0 = realtime, 1 = low_priority (lower cost)
//Prepare payload
var asticaAPI_payload = {
tkn: asticaAPI_key,
modelVersion: asticaAPI_modelVersion,
prompt: asticaAPI_prompt,
prompt_negative: asticaAPI_prompt_negative,
generate_quality: asticaAPI_generate_quality,
generate_lossless: asticaAPI_generate_lossless,
seed: asticaAPI_seed,
moderate: asticaAPI_moderate,
low_priority: asticaAPI_low_priority,
};
//Demo function
(async () => {
// Submit request
console.log("Generating Image..")
const result = await asticaAPI(asticaAPI_endpoint, asticaAPI_payload, asticaAPI_timeout);
console.log('astica API Output:\n', JSON.stringify(result, null, 4));
// Handle response
if (result.status === 'error') {
console.log('Error:', result.error);
} else if (result.status === 'success') {
if (result.resultURI) {
console.log('===============');
console.log('Low Priority URI: ', result.resultURI, '\nQuery this URL to obtain the output of your results');
console.log('===============');
} else {
console.log('===============');
console.log('Generated Image:', result.output);
console.log('===============');
}
} else { console.log('Invalid response'); }
})();
// Required astica api function
async function asticaAPI(endpoint, payload, timeout) {
try {
const response = await axios.post(endpoint, payload, {
headers: { 'Content-Type': 'application/json' },
timeout: timeout * 1000, // timeout in ms
});
if (response.status === 200) {
return response.data;
}
} catch (error) {
return { status: 'error', error: 'Failed to connect to the API.' };
}
}