diff --git a/scripts/dream.py b/scripts/dream.py index 857b5637aa..d8a1eaa54d 100755 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -292,8 +292,8 @@ def main_loop(gen, opt, infile): continue print('Outputs:') - log_path = os.path.join(current_outdir, 'dream_log.txt') - write_log_message(results, log_path) + log_path = os.path.join(current_outdir, 'dream_log') + write_log_message(results, log_path ,('txt', 'md')) print() print('goodbye!') @@ -339,17 +339,29 @@ def dream_server_loop(gen, host, port, outdir): dream_server.server_close() -def write_log_message(results, log_path): +def write_log_message(results, log_path, file_types): """logs the name of the output image, prompt, and prompt args to the terminal and log file""" global output_cntr log_lines = [f'{path}: {prompt}\n' for path, prompt in results] for l in log_lines: output_cntr += 1 print(f'[{output_cntr}] {l}',end='') + for file_type in file_types: + if file_type == 'txt': + with open(log_path + '.txt', 'a', encoding='utf-8') as file: + file.writelines(log_lines) + elif file_type == 'md' or file_type == 'markdown': + md_lines = [] + for path,prompt in results: + file_name = os.path.basename(path) + md_lines.append(f'## {file_name}\n![]({file_name})\n{prompt}\n') + with open(log_path + '.md', 'a', encoding='utf-8') as file: + file.writelines(md_lines) + else: + print(f"'{file_type}' format is not supported, so write in plain text") + with open(log_path + '.' + file_type, 'a', encoding='utf-8') as file: + file.writelines(log_lines) - with open(log_path, 'a', encoding='utf-8') as file: - file.writelines(log_lines) - if __name__ == '__main__': main()