mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix long hex-encoded error message from legacy server
- closes issue #618
This commit is contained in:
parent
9461c8127d
commit
34fa6e38e7
@ -61,6 +61,7 @@ import json
|
|||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import copy
|
import copy
|
||||||
|
import base64
|
||||||
from ldm.dream.conditioning import split_weighted_subprompts
|
from ldm.dream.conditioning import split_weighted_subprompts
|
||||||
|
|
||||||
SAMPLER_CHOICES = [
|
SAMPLER_CHOICES = [
|
||||||
@ -593,7 +594,7 @@ def format_metadata(opt,
|
|||||||
if opt.init_img:
|
if opt.init_img:
|
||||||
rfc_dict['type'] = 'img2img'
|
rfc_dict['type'] = 'img2img'
|
||||||
rfc_dict['strength_steps'] = rfc_dict.pop('strength')
|
rfc_dict['strength_steps'] = rfc_dict.pop('strength')
|
||||||
rfc_dict['orig_hash'] = sha256(image_dict['init_img'])
|
rfc_dict['orig_hash'] = calculate_init_img_hash(opt.init_img)
|
||||||
rfc_dict['sampler'] = 'ddim' # FIX ME WHEN IMG2IMG SUPPORTS ALL SAMPLERS
|
rfc_dict['sampler'] = 'ddim' # FIX ME WHEN IMG2IMG SUPPORTS ALL SAMPLERS
|
||||||
else:
|
else:
|
||||||
rfc_dict['type'] = 'txt2img'
|
rfc_dict['type'] = 'txt2img'
|
||||||
@ -612,6 +613,23 @@ def format_metadata(opt,
|
|||||||
'images' : images,
|
'images' : images,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# image can either be a file path on disk or a base64-encoded
|
||||||
|
# representation of the file's contents
|
||||||
|
def calculate_init_img_hash(image_string):
|
||||||
|
prefix = 'data:image/png;base64,'
|
||||||
|
hash = None
|
||||||
|
if image_string.startswith(prefix):
|
||||||
|
imagebase64 = image_string[len(prefix):]
|
||||||
|
imagedata = base64.b64decode(imagebase64)
|
||||||
|
with open('outputs/test.png','wb') as file:
|
||||||
|
file.write(imagedata)
|
||||||
|
sha = hashlib.sha256()
|
||||||
|
sha.update(imagedata)
|
||||||
|
hash = sha.hexdigest()
|
||||||
|
else:
|
||||||
|
hash = sha256(image_string)
|
||||||
|
return hash
|
||||||
|
|
||||||
# Bah. This should be moved somewhere else...
|
# Bah. This should be moved somewhere else...
|
||||||
def sha256(path):
|
def sha256(path):
|
||||||
sha = hashlib.sha256()
|
sha = hashlib.sha256()
|
||||||
|
@ -145,7 +145,6 @@ class DreamServer(BaseHTTPRequestHandler):
|
|||||||
opt = build_opt(post_data, self.model.seed, gfpgan_model_exists)
|
opt = build_opt(post_data, self.model.seed, gfpgan_model_exists)
|
||||||
|
|
||||||
self.canceled.clear()
|
self.canceled.clear()
|
||||||
print(f">> Request to generate with prompt: {opt.prompt}")
|
|
||||||
# In order to handle upscaled images, the PngWriter needs to maintain state
|
# In order to handle upscaled images, the PngWriter needs to maintain state
|
||||||
# across images generated by each call to prompt2img(), so we define it in
|
# across images generated by each call to prompt2img(), so we define it in
|
||||||
# the outer scope of image_done()
|
# the outer scope of image_done()
|
||||||
|
Loading…
Reference in New Issue
Block a user