|
1 | 1 | # AnyTextPipeline Pipeline |
2 | 2 |
|
3 | | -From the repo [page](https://github.com/tyxsspa/AnyText) |
| 3 | +Project page: https://aigcdesigngroup.github.io/homepage_anytext |
4 | 4 |
|
5 | 5 | "AnyText comprises a diffusion pipeline with two primary elements: an auxiliary latent module and a text embedding module. The former uses inputs like text glyph, position, and masked image to generate latent features for text generation or editing. The latter employs an OCR model for encoding stroke data as embeddings, which blend with image caption embeddings from the tokenizer to generate texts that seamlessly integrate with the background. We employed text-control diffusion loss and text perceptual loss for training to further enhance writing accuracy." |
6 | 6 |
|
7 | | -For any usage questions, please refer to the [paper](https://arxiv.org/abs/2311.03054). |
| 7 | +Each text line that needs to be generated should be enclosed in double quotes. For any usage questions, please refer to the [paper](https://arxiv.org/abs/2311.03054). |
8 | 8 |
|
9 | 9 |
|
10 | 10 | ```py |
11 | 11 | import torch |
12 | 12 | from diffusers import DiffusionPipeline |
13 | 13 | from anytext_controlnet import AnyTextControlNetModel |
14 | | -from diffusers import DDIMScheduler |
15 | 14 | from diffusers.utils import load_image |
16 | 15 |
|
17 | | - |
18 | 16 | # I chose a font file shared by an HF staff: |
19 | 17 | !wget https://huggingface.co/spaces/ysharma/TranslateQuotesInImageForwards/resolve/main/arial-unicode-ms.ttf |
20 | 18 |
|
21 | | -# load control net and stable diffusion v1-5 |
22 | 19 | anytext_controlnet = AnyTextControlNetModel.from_pretrained("tolgacangoz/anytext-controlnet", torch_dtype=torch.float16, |
23 | 20 | variant="fp16",) |
24 | 21 | pipe = DiffusionPipeline.from_pretrained("tolgacangoz/anytext", font_path="arial-unicode-ms.ttf", |
25 | | - controlnet=anytext_controlnet, torch_dtype=torch.float16, |
26 | | - trust_remote_code=True, |
27 | | - ).to("cuda") |
28 | | - |
29 | | -pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) |
30 | | -# uncomment following line if PyTorch>=2.0 is not installed for memory optimization |
31 | | -#pipe.enable_xformers_memory_efficient_attention() |
32 | | - |
33 | | -# uncomment following line if you want to offload the model to CPU for memory optimization |
34 | | -# also remove the `.to("cuda")` part |
35 | | -#pipe.enable_model_cpu_offload() |
| 22 | + controlnet=anytext_controlnet, torch_dtype=torch.float16, |
| 23 | + trust_remote_code=False, # One needs to give permission to run this pipeline's code |
| 24 | + ).to("cuda") |
36 | 25 |
|
37 | 26 | # generate image |
38 | 27 | prompt = 'photo of caramel macchiato coffee on the table, top-down perspective, with "Any" "Text" written on it using cream' |
39 | 28 | draw_pos = load_image("https://raw.githubusercontent.com/tyxsspa/AnyText/refs/heads/main/example_images/gen9.png") |
40 | 29 | image = pipe(prompt, num_inference_steps=20, mode="generate", draw_pos=draw_pos, |
41 | | - ).images[0] |
| 30 | + ).images[0] |
42 | 31 | image |
43 | 32 | ``` |
0 commit comments