File size: 1,545 Bytes
24e04bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Caption templates.

A single fixed template would teach the LoRA to render text only inside that
one sentence, and would fight other checkpoints' prompting styles -- which
directly undermines the plug-and-play goal. So: the scene wording varies, and
the quoted Hindi string is the one invariant anchor.
"""
from __future__ import annotations

import random

# Templates that name the language explicitly.
NAMED = [
    'a sign with the Hindi text "{t}"',
    'a photo of a sign reading "{t}" in Hindi',
    'Hindi text "{t}" on a {surface}',
    'a {surface} with Hindi writing "{t}"',
    'Devanagari text "{t}" on a {surface}',
    '"{t}" written in Hindi on a {surface}',
]

# Templates that do NOT name the language. ~20% of samples use these so the
# model does not come to depend on the trigger phrase.
UNNAMED = [
    'a {surface} with the text "{t}"',
    'a sign that reads "{t}"',
    '"{t}" printed on a {surface}',
    'text "{t}" on a {surface}',
]

SURFACES = [
    "sign", "signboard", "poster", "banner", "shop sign", "plaque",
    "billboard", "notice board", "label", "book cover", "wall", "board",
]

STYLES = [
    "", "", "", "",  # most samples get no style suffix
    ", photograph", ", high resolution", ", sharp focus",
    ", clean design", ", studio lighting", ", flat design",
]


def make_caption(text: str, rng: random.Random) -> str:
    named = rng.random() > 0.20
    tpl = rng.choice(NAMED if named else UNNAMED)
    cap = tpl.format(t=text, surface=rng.choice(SURFACES))
    return cap + rng.choice(STYLES)