-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
31 lines (26 loc) · 985 Bytes
/
index.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
const axios = require('axios');
const API_URL = 'https://stablediffusion-two.vercel.app/generate-image';
function generate(prompta) {
let prompt = prompta
if (prompt.endsWith('{enhanced}')) {
prompt = prompt.replace('{enhanced}', "realistic, smoothening, epic cinematic lighting, dark villanous looking background.")
}
const generateImage = async () => {
try {
const response = await axios.post(API_URL, { prompt }, { responseType: 'arraybuffer' });
if (response.status === 200) {
return response.data;
} else {
console.log(`Error: ${response.status} - ${response.statusText}`);
throw new Error('Image generation failed');
}
} catch (error) {
console.error('Error generating image:', error);
throw error;
}
};
return generateImage();
}
module.exports = {
generate
};