s0md3v / sd-webui-roop

roop extension for StableDiffusion web-ui
GNU Affero General Public License v3.0
3.3k stars 834 forks source link

Problems using PNG with the API #282

Open im-kent opened 7 months ago

im-kent commented 7 months ago

Hello,

I am having some issues using the Roop API with Automatic1111. I suspect I am reading in and/or sending the base64 image to the API incorrectly. When using the Roop API using my code, I seem to get results that are faces with black discoloring on them when a PNG file is used. When a JPG file is used, the images generated look good. When using the WebUI Gradio user interface, PNG and JPGs both work well. This leads me to believe I have poorly implemented the reading in of image files to send as base64 to the API. Any help would be appreciated!

With JPGs fed into API: image

With PNGs fed into API: image

The area of my code I suspect most is imageToBase64. I suspect that this is working fine for JPGs, but perhaps I am not handling it correctly for PNGs:

function imageToBase64(path) {
    // read binary data
    const bitmap = fs.readFileSync(path);
    // convert binary data to base64 encoded string
    return Buffer.from(bitmap).toString('base64');
}
roop = async function(locationOfSourceImage, prompt, neg){
    var modelLocation = '/home/ubuntu/SD/stable-diffusion-webui/models/roop/inswapper_128.onnx'

    var img_base64 = imageToBase64(locationOfSourceImage)
    var args=[img_base64,true,'0',modelLocation,'CodeFormer',1,null,1,'None',false,true]
    var payload = {
        "prompt": prompt,
        "negative_prompt": neg,
        "seed": -1,
        "sampler_name": "DPM++ 2M Karras",
        "steps": 20,
        "cfg_scale": 4.5,
        "width": 512,
        "height": 768,
        "restore_faces": true,
        //Begin HighResFix
        "enable_hr": true,
        "denoising_strength": 0.2,
        "hr_upscaler": "ESRGAN_4x",
        "hr_scale": 1.5,
        //End HighResFix
        "alwayson_scripts": {"roop":{"args":args}},
        "override_settings": {"CLIP_stop_at_last_layers": 2 }
    }
    //some other code not included here
}
xxyyboy commented 3 months ago

same problem