diff --git a/ldm/dream/server.py b/ldm/dream/server.py index 4170547be0..e64eefd2c9 100644 --- a/ldm/dream/server.py +++ b/ldm/dream/server.py @@ -15,6 +15,16 @@ class DreamServer(BaseHTTPRequestHandler): self.end_headers() with open("./static/dream_web/index.html", "rb") as content: self.wfile.write(content.read()) + elif self.path == "/config.js": + # unfortunately this import can't be at the top level, since that would cause a circular import + from ldm.gfpgan.gfpgan_tools import gfpgan_model_exists + self.send_response(200) + self.send_header("Content-type", "application/javascript") + self.end_headers() + config = { + 'gfpgan_model_exists': gfpgan_model_exists + } + self.wfile.write(bytes("let config = " + json.dumps(config) + ";\n", "utf-8")) else: path = "." + self.path cwd = os.path.realpath(os.getcwd()) @@ -37,6 +47,9 @@ class DreamServer(BaseHTTPRequestHandler): self.send_header("Content-type", "application/json") self.end_headers() + # unfortunately this import can't be at the top level, since that would cause a circular import + from ldm.gfpgan.gfpgan_tools import gfpgan_model_exists + content_length = int(self.headers['Content-Length']) post_data = json.loads(self.rfile.read(content_length)) prompt = post_data['prompt'] @@ -47,7 +60,7 @@ class DreamServer(BaseHTTPRequestHandler): height = int(post_data['height']) cfgscale = float(post_data['cfgscale']) sampler_name = post_data['sampler'] - gfpgan_strength = float(post_data['gfpgan_strength']) + gfpgan_strength = float(post_data['gfpgan_strength']) if gfpgan_model_exists else 0 upscale_level = post_data['upscale_level'] upscale_strength = post_data['upscale_strength'] upscale = [int(upscale_level),float(upscale_strength)] if upscale_level != '' else None @@ -70,7 +83,7 @@ class DreamServer(BaseHTTPRequestHandler): # the images are first generated, and then again when after upscaling # is complete. The upscaling replaces the original file, so the second # entry should not be inserted into the image list. - def image_done(image, seed, upscaled=False): + def image_done(image, seed, upscaled=False): pngwriter.write_image(image, seed, upscaled) # Append post_data to log, but only once! diff --git a/ldm/gfpgan/gfpgan_tools.py b/ldm/gfpgan/gfpgan_tools.py index f775e33a45..29786342a5 100644 --- a/ldm/gfpgan/gfpgan_tools.py +++ b/ldm/gfpgan/gfpgan_tools.py @@ -10,16 +10,18 @@ from scripts.dream import create_argv_parser arg_parser = create_argv_parser() opt = arg_parser.parse_args() +model_path = os.path.join(opt.gfpgan_dir, opt.gfpgan_model_path) +gfpgan_model_exists = os.path.isfile(model_path) def _run_gfpgan(image, strength, prompt, seed, upsampler_scale=4): print(f'\n* GFPGAN - Restoring Faces: {prompt} : seed:{seed}') + gfpgan = None with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=DeprecationWarning) warnings.filterwarnings('ignore', category=UserWarning) try: - model_path = os.path.join(opt.gfpgan_dir, opt.gfpgan_model_path) - if not os.path.isfile(model_path): + if not gfpgan_model_exists: raise Exception('GFPGAN model not found at path ' + model_path) sys.path.append(os.path.abspath(opt.gfpgan_dir)) diff --git a/static/dream_web/index.html b/static/dream_web/index.html index 158e559314..459e78b035 100644 --- a/static/dream_web/index.html +++ b/static/dream_web/index.html @@ -6,6 +6,7 @@ +
@@ -66,18 +67,19 @@ • -The options below require the GFPGAN and ESRGAN packages to be installed
- - - - - - +The options below require the GFPGAN and ESRGAN packages to be installed
+ + + + + + +