main.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import cv2
  3. from anytext_pipeline import AnyTextPipeline
  4. from utils import save_images
  5. seed = 66273235
  6. # seed_everything(seed)
  7. pipe = AnyTextPipeline(
  8. ckpt_path="/Users/cwq/code/github/IOPaint/iopaint/model/anytext/anytext_v1.1_fp16.ckpt",
  9. font_path="/Users/cwq/code/github/AnyText/anytext/font/SourceHanSansSC-Medium.otf",
  10. use_fp16=False,
  11. device="mps",
  12. )
  13. img_save_folder = "SaveImages"
  14. rgb_image = cv2.imread(
  15. "/Users/cwq/code/github/AnyText/anytext/example_images/ref7.jpg"
  16. )[..., ::-1]
  17. masked_image = cv2.imread(
  18. "/Users/cwq/code/github/AnyText/anytext/example_images/edit7.png"
  19. )[..., ::-1]
  20. rgb_image = cv2.resize(rgb_image, (512, 512))
  21. masked_image = cv2.resize(masked_image, (512, 512))
  22. # results: list of rgb ndarray
  23. results, rtn_code, rtn_warning = pipe(
  24. prompt='A cake with colorful characters that reads "EVERYDAY", best quality, extremely detailed,4k, HD, supper legible text, clear text edges, clear strokes, neat writing, no watermarks',
  25. 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",
  26. image=rgb_image,
  27. masked_image=masked_image,
  28. num_inference_steps=20,
  29. strength=1.0,
  30. guidance_scale=9.0,
  31. height=rgb_image.shape[0],
  32. width=rgb_image.shape[1],
  33. seed=seed,
  34. sort_priority="y",
  35. )
  36. if rtn_code >= 0:
  37. save_images(results, img_save_folder)
  38. print(f"Done, result images are saved in: {img_save_folder}")