test_anytext.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. from sorawm.iopaint.tests.utils import assert_equal, check_device, get_config
  3. os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
  4. from pathlib import Path
  5. import pytest
  6. import torch
  7. from sorawm.iopaint.model_manager import ModelManager
  8. from sorawm.iopaint.schema import HDStrategy
  9. current_dir = Path(__file__).parent.absolute().resolve()
  10. save_dir = current_dir / "result"
  11. save_dir.mkdir(exist_ok=True, parents=True)
  12. @pytest.mark.parametrize("device", ["cuda", "mps"])
  13. def test_anytext(device):
  14. sd_steps = check_device(device)
  15. model = ModelManager(
  16. name="Sanster/AnyText",
  17. device=torch.device(device),
  18. disable_nsfw=True,
  19. sd_cpu_textencoder=False,
  20. )
  21. cfg = get_config(
  22. strategy=HDStrategy.ORIGINAL,
  23. prompt='Characters written in chalk on the blackboard that says "DADDY", best quality, extremely detailed,4k, HD, supper legible text, clear text edges, clear strokes, neat writing, no watermarks',
  24. negative_prompt="low-res, bad anatomy, extra digit, fewer digits, cropped, worst quality, low quality, watermark, unreadable text, messy words, distorted text, disorganized writing, advertising picture",
  25. sd_steps=sd_steps,
  26. sd_guidance_scale=9.0,
  27. sd_seed=66273235,
  28. sd_match_histograms=True,
  29. )
  30. assert_equal(
  31. model,
  32. cfg,
  33. f"anytext.png",
  34. img_p=current_dir / "anytext_ref.jpg",
  35. mask_p=current_dir / "anytext_mask.jpg",
  36. )