Views
No views yet
pip install torch torchvision transformers diffusers einops pillow1from transformers import AutoModel
2from PIL import Image
3import torch
4
5# Load model
6device = "cuda" if torch.cuda.is_available() else "cpu"
7model = AutoModel.from_pretrained(
8 "blowing-up-groundhogs/eruku",
9 trust_remote_code=True
10)
11model.to(device)
12model.eval()
13
14# Load a style image (handwritten/typewritten text sample)
15style_image = Image.open("style_sample.png")
16
17# Generate text in that style
18result = model.generate_handwriting(
19 style_image=style_image,
20 gen_text="Hello, World!",
21 style_text="", # Optional: transcription of style image
22 cfg_scale=1.25, # Classifier-free guidance scale
23)
24
25# Save the result
26result.save("generated.png")style_image): A PIL Image containing handwritten or typewritten text that serves as the style reference. The model will replicate this style.gen_text): The text you want to render in the extracted style.style_text, optional): The transcription of the text in the style image. Providing this helps the model better understand the style, but it's not required.| Parameter | Type | Default | Description |
|---|---|---|---|
style_image | PIL.Image | Required | Reference style image |
gen_text | str | Required | Text to generate |
style_text | str | "" | Optional transcription of style image |
cfg_scale | float | 1.25 | Classifier-free guidance scale |
max_new_tokens | int | 512 | Maximum generation tokens |
1.0: No guidance (faster but may drift from prompt)1.25: Recommended default - good balance1.5-2.0: Stronger adherence to prompt>2.0: May cause artifacts1import torch
2from torchvision import transforms as T
3
4# Prepare style image manually
5style_img = Image.open("style.png").convert('RGB')
6width, height = style_img.size
7new_width = int(64 * width / height)
8style_img = style_img.resize((new_width, 64), Image.LANCZOS)
9style_tensor = T.ToTensor()(style_img).to(device)
10
11# Get model inputs
12inputs = model.get_model_inputs(
13 style_img=[style_tensor],
14 style_len=style_tensor.shape[-1],
15 max_img_len=1024*1024
16)
17
18# Generate with full control
19with torch.inference_mode():
20 output_img, special_sequence = model.generate(
21 decoder_inputs_embeds_vae=inputs['decoder_inputs_embeds'],
22 style_text=["Style text here"],
23 gen_text=["Text to generate"],
24 cfg_scale=1.25,
25 max_new_tokens=512
26 )1@InProceedings{pippi2025zeroshot,
2 author = {Pippi, Vittorio and Quattrini, Fabio and Cascianelli, Silvia and Tonioni, Alessio and Cucchiara, Rita},
3 title = {Zero-Shot Styled Text Image Generation, but Make It Autoregressive},
4 booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
5 month = {June},
6 year = {2025},
7 pages = {7910-7919}
8}
9
10@inproceedings{zaccagnino2026autoregressive,
11 author = {Carmine Zaccagnino and Fabio Quattrini and Vittorio Pippi and Silvia Cascianelli and Alessio Tonioni and Rita Cucchiara},
12 title = {Autoregressive Styled Text Image Generation, but Make it Reliable},
13 booktitle = {Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision},
14 month = {March},
15 year = {2026}
16}