Report errors if Stable Diffusion failed to generate an image

This commit is contained in:
cmdr2 2022-08-24 13:33:58 +05:30
parent c1c876e12d
commit 83e3288177
2 changed files with 21 additions and 11 deletions

View File

@ -119,6 +119,12 @@ async function makeImage() {
let outputMsg = document.querySelector('#outputMsg')
function logError(msg, res) {
outputMsg.innerHTML = '<span style="color: red">Error: ' + msg + '</span>'
console.log('request error', res)
setStatus('request', 'error', 'error')
}
let reqBody = {
prompt: document.querySelector('#prompt').value,
num_outputs: document.querySelector('#num_outputs').value,
@ -139,19 +145,24 @@ async function makeImage() {
},
body: JSON.stringify(reqBody)
})
if (res.status != 200) {
logError('Stable Diffusion had an error: ' + await res.text() + '. This happens some times. Maybe modify the prompt or seed a bit?', res)
res = undefined
} else {
res = await res.json()
if (res.status !== 'succeeded') {
let msg = ''
if (res.detail !== undefined) {
outputMsg.innerHTML = 'Error: ' + res.detail[0].msg + " in " + JSON.stringify(res.detail[0].loc)
msg = res.detail[0].msg + " in " + JSON.stringify(res.detail[0].loc)
} else {
outputMsg.innerHTML = 'Error: ' + res
msg = res
}
outputMsg.innerHTML = '<span style="color: red">' + outputMsg.innerHTML + '</span>'
console.log('request error', res)
setStatus('request', 'error', 'error')
logError(msg, res)
res = undefined
}
}
} catch (e) {
console.log('request error', e)
setStatus('request', 'error', 'error')

View File

@ -49,7 +49,6 @@ async def image(req : ImageRequest):
del data['input']['seed']
res = requests.post(PREDICT_URL, json=data)
print(res)
return res.json()
@app.get('/ding.mp3')