From 48720298a1178b02949850a5c702002cb7ebab99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A6=CF=86?= <42910943+Brawlence@users.noreply.github.com> Date: Wed, 29 Mar 2023 13:03:12 +0300 Subject: [PATCH] Group files by date & Uniquify filenames with int ( epoch seconds ) --- extensions/sd_api_pictures/script.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/extensions/sd_api_pictures/script.py b/extensions/sd_api_pictures/script.py index 8996fcb266..9f26d163eb 100644 --- a/extensions/sd_api_pictures/script.py +++ b/extensions/sd_api_pictures/script.py @@ -1,6 +1,7 @@ import base64 import io import re +import time from pathlib import Path import gradio as gr @@ -9,6 +10,7 @@ import requests import torch from PIL import Image +from datetime import date torch._C._jit_set_profiling_mode(False) @@ -71,7 +73,6 @@ def give_VRAM_priority(actor): streaming_state = shared.args.no_stream # remember if chat streaming was enabled picture_response = False # specifies if the next model response should appear as a picture -pic_id = 0 def remove_surrounded_chars(string): # this expression matches to 'as few symbols as possible (0 upwards) between any asterisks' OR @@ -104,7 +105,7 @@ def input_modifier(string): # Get and save the Stable Diffusion-generated picture def get_SD_pictures(description): - global params, pic_id + global params if params['manage_VRAM']: give_VRAM_priority('SD') @@ -129,10 +130,10 @@ def get_SD_pictures(description): for img_str in r['images']: image = Image.open(io.BytesIO(base64.b64decode(img_str.split(",",1)[0]))) if params['save_img']: - output_file = Path(f'extensions/sd_api_pictures/outputs/{pic_id:06d}.png') + output_file = Path(f'extensions/sd_api_pictures/outputs/{date.today().strftime("%Y_%m_%d")}/{shared.character}_{int(time.time())}.png') + output_file.parent.mkdir(parents=True, exist_ok=True) image.save(output_file.as_posix()) - visible_result = visible_result + f'{description}\n' - pic_id += 1 + visible_result = visible_result + f'{description}\n' else: # lower the resolution of received images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history image.thumbnail((300, 300)) @@ -153,7 +154,7 @@ def output_modifier(string): """ This function is applied to the model outputs. """ - global pic_id, picture_response, params + global picture_response, params if not picture_response: return string