Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --outdir function for web #373

Merged
merged 5 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ldm/dream/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CanceledException(Exception):

class DreamServer(BaseHTTPRequestHandler):
model = None
outdir = None
canceled = Event()

def do_GET(self):
Expand Down Expand Up @@ -91,7 +92,7 @@ def do_POST(self):

images_generated = 0 # helps keep track of when upscaling is started
images_upscaled = 0 # helps keep track of when upscaling is completed
pngwriter = PngWriter("./outputs/img-samples/")
pngwriter = PngWriter(self.outdir)

prefix = pngwriter.unique_prefix()
# if upscaling is requested, then this will be called twice, once when
Expand All @@ -104,7 +105,7 @@ def image_done(image, seed, upscaled=False):

# Append post_data to log, but only once!
if not upscaled:
with open("./outputs/img-samples/dream_web_log.txt", "a") as log:
with open(os.path.join(self.outdir, "dream_web_log.txt"), "a") as log:
log.write(f"{path}: {json.dumps(config)}\n")

self.wfile.write(bytes(json.dumps(
Expand Down Expand Up @@ -132,7 +133,7 @@ def image_done(image, seed, upscaled=False):
{'event':action,'processed_file_cnt':f'{x}/{iterations}'}
) + '\n',"utf-8"))

step_writer = PngWriter('./outputs/intermediates/')
step_writer = PngWriter(os.path.join(self.outdir, "intermediates"))
step_index = 1
def image_progress(sample, step):
if self.canceled.is_set():
Expand Down
5 changes: 3 additions & 2 deletions scripts/dream.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def main():

cmd_parser = create_cmd_parser()
if opt.web:
dream_server_loop(t2i, opt.host, opt.port)
dream_server_loop(t2i, opt.host, opt.port, opt.outdir)
else:
main_loop(t2i, opt.outdir, opt.prompt_as_dir, cmd_parser, infile)

Expand Down Expand Up @@ -316,7 +316,7 @@ def get_next_command(infile=None) -> str: #command string
print(f'#{command}')
return command

def dream_server_loop(t2i, host, port):
def dream_server_loop(t2i, host, port, outdir):
print('\n* --web was specified, starting web server...')
# Change working directory to the stable-diffusion directory
os.chdir(
Expand All @@ -325,6 +325,7 @@ def dream_server_loop(t2i, host, port):

# Start server
DreamServer.model = t2i
DreamServer.outdir = outdir
dream_server = ThreadingDreamServer((host, port))
print(">> Started Stable Diffusion dream server!")
if host == '0.0.0.0':
Expand Down