Refactor the Prompts class.

This commit is contained in:
hodanov 2024-11-04 08:19:04 +09:00
parent d7b143ce5c
commit a4a161ad83

View File

@ -59,18 +59,36 @@ class Prompts:
msg = "steps should be positive." msg = "steps should be positive."
raise ValueError(msg) raise ValueError(msg)
self.__dict: dict[str, int | str] = { self.__prompt = prompt
"prompt": prompt, self.__n_prompt = n_prompt
"n_prompt": n_prompt, self.__height = height
"height": height, self.__width = width
"width": width, self.__samples = samples
"samples": samples, self.__steps = steps
"steps": steps,
}
@property @property
def dict(self) -> dict[str, int | str]: def prompt(self) -> str:
return self.__dict return self.__prompt
@property
def n_prompt(self) -> str:
return self.__n_prompt
@property
def height(self) -> int:
return self.__height
@property
def width(self) -> int:
return self.__width
@property
def samples(self) -> int:
return self.__samples
@property
def steps(self) -> int:
return self.__steps
class OutputDirectory: class OutputDirectory:
@ -100,8 +118,8 @@ class StableDiffusionOutputManger:
prompts_filename = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time())) prompts_filename = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
output_path = f"{self.__output_directory}/prompts_{prompts_filename}.txt" output_path = f"{self.__output_directory}/prompts_{prompts_filename}.txt"
with Path(output_path).open("wb") as file: with Path(output_path).open("wb") as file:
for name, value in self.__prompts.dict.items(): for key, value in vars(self.__prompts).items():
file.write(f"{name} = {value!r}\n".encode()) file.write(f"{key} = {value!r}\n".encode())
return output_path return output_path