from funcy import first, rest from cv_analysis.utils import conj from synthesis.random import rnd from synthesis.text.text_block_generator.paragraph import generate_random_text_lines from synthesis.text.text_block_generator.text_block_generator import TextBlockGenerator from synthesis.text.line_formatter.identity import IdentityLineFormatter class CaptionGenerator(TextBlockGenerator): def __init__(self, caption_start=None): self.line_formatter = IdentityLineFormatter() self.caption_start = caption_start or f"Fig {rnd.randint(1, 20)}" def __call__(self, rectangle, n_sentences): return self.generate_paragraph(rectangle, n_sentences) def generate_paragraph(self, rectangle, n_sentences): lines = generate_random_text_lines(rectangle, self.line_formatter, n_sentences) first_line_modified = f"{self.caption_start}.: {first(lines)}" lines = conj(first_line_modified, rest(lines)) return lines