mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-03-11 13:38:44 +01:00
Merge branch 'beta' into mdiller_themes
This commit is contained in:
commit
f170c2611c
ui
@ -197,7 +197,7 @@ def load_model_real_esrgan(real_esrgan_to_use):
|
|||||||
|
|
||||||
print('loaded ', real_esrgan_to_use, 'to', device, 'precision', precision)
|
print('loaded ', real_esrgan_to_use, 'to', device, 'precision', precision)
|
||||||
|
|
||||||
def get_base_path(disk_path, session_id, prompt, ext, suffix=None):
|
def get_base_path(disk_path, session_id, prompt, img_id, ext, suffix=None):
|
||||||
if disk_path is None: return None
|
if disk_path is None: return None
|
||||||
if session_id is None: return None
|
if session_id is None: return None
|
||||||
if ext is None: raise Exception('Missing ext')
|
if ext is None: raise Exception('Missing ext')
|
||||||
@ -206,7 +206,6 @@ def get_base_path(disk_path, session_id, prompt, ext, suffix=None):
|
|||||||
os.makedirs(session_out_path, exist_ok=True)
|
os.makedirs(session_out_path, exist_ok=True)
|
||||||
|
|
||||||
prompt_flattened = filename_regex.sub('_', prompt)[:50]
|
prompt_flattened = filename_regex.sub('_', prompt)[:50]
|
||||||
img_id = str(uuid.uuid4())[-8:]
|
|
||||||
|
|
||||||
if suffix is not None:
|
if suffix is not None:
|
||||||
return os.path.join(session_out_path, f"{prompt_flattened}_{img_id}_{suffix}.{ext}")
|
return os.path.join(session_out_path, f"{prompt_flattened}_{img_id}_{suffix}.{ext}")
|
||||||
@ -317,6 +316,8 @@ def do_mk_img(req: Request):
|
|||||||
opt_f = 8
|
opt_f = 8
|
||||||
opt_ddim_eta = 0.0
|
opt_ddim_eta = 0.0
|
||||||
opt_init_img = req.init_image
|
opt_init_img = req.init_image
|
||||||
|
img_id = base64.b64encode(int(time.time()).to_bytes(8, 'big')).decode() # Generate unique ID based on time.
|
||||||
|
img_id = img_id.translate({43:None, 47:None, 61:None})[-8:] # Remove + / = and keep last 8 chars.
|
||||||
|
|
||||||
print(req.to_string(), '\n device', device)
|
print(req.to_string(), '\n device', device)
|
||||||
|
|
||||||
@ -474,9 +475,9 @@ def do_mk_img(req: Request):
|
|||||||
|
|
||||||
if req.save_to_disk_path is not None:
|
if req.save_to_disk_path is not None:
|
||||||
if return_orig_img:
|
if return_orig_img:
|
||||||
img_out_path = get_base_path(req.save_to_disk_path, req.session_id, prompts[0], req.output_format)
|
img_out_path = get_base_path(req.save_to_disk_path, req.session_id, prompts[0], img_id, req.output_format)
|
||||||
save_image(img, img_out_path)
|
save_image(img, img_out_path)
|
||||||
meta_out_path = get_base_path(req.save_to_disk_path, req.session_id, prompts[0], 'txt')
|
meta_out_path = get_base_path(req.save_to_disk_path, req.session_id, prompts[0], img_id, 'txt')
|
||||||
save_metadata(meta_out_path, req, prompts[0], opt_seed)
|
save_metadata(meta_out_path, req, prompts[0], opt_seed)
|
||||||
|
|
||||||
if return_orig_img:
|
if return_orig_img:
|
||||||
@ -503,7 +504,7 @@ def do_mk_img(req: Request):
|
|||||||
response_image = ResponseImage(data=filtered_img_data, seed=req.seed)
|
response_image = ResponseImage(data=filtered_img_data, seed=req.seed)
|
||||||
res.images.append(response_image)
|
res.images.append(response_image)
|
||||||
if req.save_to_disk_path is not None:
|
if req.save_to_disk_path is not None:
|
||||||
filtered_img_out_path = get_base_path(req.save_to_disk_path, req.session_id, prompts[0], req.output_format, "_".join(filters_applied))
|
filtered_img_out_path = get_base_path(req.save_to_disk_path, req.session_id, prompts[0], img_id, req.output_format, "_".join(filters_applied))
|
||||||
save_image(filtered_image, filtered_img_out_path)
|
save_image(filtered_image, filtered_img_out_path)
|
||||||
response_image.path_abs = filtered_img_out_path
|
response_image.path_abs = filtered_img_out_path
|
||||||
del filtered_image
|
del filtered_image
|
||||||
@ -541,7 +542,7 @@ Negative Prompt: {req.negative_prompt}
|
|||||||
Stable Diffusion Model: {req.use_stable_diffusion_model + '.ckpt'}
|
Stable Diffusion Model: {req.use_stable_diffusion_model + '.ckpt'}
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(meta_out_path, 'w') as f:
|
with open(meta_out_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(metadata)
|
f.write(metadata)
|
||||||
except:
|
except:
|
||||||
print('could not save the file', traceback.format_exc())
|
print('could not save the file', traceback.format_exc())
|
||||||
|
10
ui/server.py
10
ui/server.py
@ -187,13 +187,13 @@ async def setAppConfig(req : SetAppConfigRequest):
|
|||||||
config_bat_path = os.path.join(CONFIG_DIR, 'config.bat')
|
config_bat_path = os.path.join(CONFIG_DIR, 'config.bat')
|
||||||
config_sh_path = os.path.join(CONFIG_DIR, 'config.sh')
|
config_sh_path = os.path.join(CONFIG_DIR, 'config.sh')
|
||||||
|
|
||||||
with open(config_json_path, 'w') as f:
|
with open(config_json_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(config_json_str)
|
f.write(config_json_str)
|
||||||
|
|
||||||
with open(config_bat_path, 'w') as f:
|
with open(config_bat_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(config_bat_str)
|
f.write(config_bat_str)
|
||||||
|
|
||||||
with open(config_sh_path, 'w') as f:
|
with open(config_sh_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(config_sh_str)
|
f.write(config_sh_str)
|
||||||
|
|
||||||
return {'OK'}
|
return {'OK'}
|
||||||
@ -206,7 +206,7 @@ def getConfig(default_val={}):
|
|||||||
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
|
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
|
||||||
if not os.path.exists(config_json_path):
|
if not os.path.exists(config_json_path):
|
||||||
return default_val
|
return default_val
|
||||||
with open(config_json_path, 'r') as f:
|
with open(config_json_path, 'r', encoding='utf-8') as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
@ -216,7 +216,7 @@ def getConfig(default_val={}):
|
|||||||
def setConfig(config):
|
def setConfig(config):
|
||||||
try:
|
try:
|
||||||
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
|
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
|
||||||
with open(config_json_path, 'w') as f:
|
with open(config_json_path, 'w', encoding='utf-8') as f:
|
||||||
return json.dump(config, f)
|
return json.dump(config, f)
|
||||||
except:
|
except:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
Loading…
Reference in New Issue
Block a user