sd.js 1.2 KB
Newer Older
1 2
import axios from "axios";

3
export default {
4
    draw (config, prompt, negative_prompt) {
5
        return new Promise(function(resolve,rejcet){
6
            
7 8 9
            const data = {
                prompt: prompt,
                steps: config?.steps??20,
10
                negative_prompt: negative_prompt??'nsfw',
11 12 13 14 15 16 17 18 19 20
                width: config?.width??512,
                height: config?.height??512,
                cfg_scale: config?.cfg_scale??6,
                seed : config?.seed??-1,
                sampler_name: config?.sampler_name??"DPM++ SDE Karras"
            }
            const headers = { 
                'content-type': 'application/json'
            };
    
21 22 23 24 25
            let api = config?.sd_api
            if (api.indexOf('/sd') === -1) {
                api += '/sdapi/v1/txt2img'
            }
            axios.post(api, data, { headers }).then(response => {
26
    
27 28
                if (response.status === 200 && response?.data?.images){
                    const image = response?.data?.images[0]                    
29 30 31 32 33 34
                    resolve('data:image/png;base64,' + image)
                }
                
            }).catch(err => {
                rejcet(err)
            });
35

36
        })
37

38
        
39 40 41 42
        
    }

}