refactor: validation

This commit is contained in:
Limitex
2025-11-09 09:21:30 +09:00
parent f6fb30d5aa
commit c4d385be60
4 changed files with 12 additions and 20 deletions
+4 -8
View File
@@ -13,15 +13,11 @@ class ClipTextEncodeUsecase:
def execute(
self, tokenizer: CLIPTokenizer, text_encoder: CLIPTextModel, path: str, text: str
) -> Conditioning:
if not text:
raise ValueError("Text input is empty.")
if path is None:
raise ValueError("Clip path is None.")
if tokenizer is None or text_encoder is None:
raise ValueError("Tokenizer or Text Encoder is None.")
if not isinstance(text, str):
raise TypeError("Text input must be a string.")
if not text.strip():
raise ValueError("Text input is empty or whitespace only.")
embeddings = self.text_encoder_repo.encode(tokenizer, text_encoder, text)
if embeddings is None:
raise RuntimeError("Failed to generate embeddings.")
return Conditioning(conditioning=embeddings, path=path)
+1
View File
@@ -29,4 +29,5 @@ class PipelineUsecase:
text_encoder=pipe.text_encoder, # type: ignore[attr-defined]
path=checkpoint_path,
)
return pipeline, clip
+5 -12
View File
@@ -22,22 +22,14 @@ class SamplerUsecase:
cfg: float,
seed: int,
) -> list[Image]:
if pipeline is None:
raise ValueError("Pipeline is None.")
if vae is None:
raise ValueError("VAE is None.")
if scheduler is None:
raise ValueError("Scheduler is None.")
if positive_embeds is None or negative_embeds is None:
raise ValueError("Conditioning embeddings are None.")
if width <= 0 or height <= 0:
raise ValueError("Width and Height must be positive integers.")
raise ValueError(f"Invalid dimensions: {width}x{height}")
if steps <= 0:
raise ValueError("Steps must be a positive integer.")
raise ValueError(f"Steps must be positive: {steps}")
if cfg < 0.0:
raise ValueError("CFG must be a non-negative float.")
raise ValueError(f"CFG must be non-negative: {cfg}")
if seed < 0:
raise ValueError("Seed must be a non-negative integer.")
raise ValueError(f"Seed must be non-negative: {seed}")
images = self.sampler_repo.sample(
pipeline.pipeline,
@@ -54,4 +46,5 @@ class SamplerUsecase:
if images is None:
raise RuntimeError("Sampler repository returned no images.")
images_domain: list[Image] = [Image(image=img) for img in images]
return images_domain
+2
View File
@@ -15,7 +15,9 @@ class SchedulerUsecase:
raise ValueError("Pipeline is None.")
if not pipeline.path:
raise ValueError("Invalid pipeline to create scheduler.")
scheduler_obj: SchedulerMixin = self.scheduler_repo.create_scheduler(
pipeline.path, self.dtype, scheduler_type
)
return Scheduler(scheduler=scheduler_obj, path=pipeline.path)