Skip to content

Presets

Return components configured for common tasks.

Every preset is a function that returns an ordinary component with its instructions and operation set, and passes extra keyword arguments, such as backend, to the component. INSTRUCTIONS holds the instructions of the presets that are text generators, extractors or classifiers.

Examples:

>>> from skai import presets
>>> summarizer = presets.summarizer(max_length=50, backend='dummy')
>>> type(summarizer).__name__, summarizer.max_length
('TextToTextGenerator', 50)

animator(instructions=None, duration=2.0, **kwargs)

Return a generator that turns images into short videos.

Parameters:

Name Type Description Default
instructions str | None

A description of the motion.

None
duration float

The length of the videos in seconds.

2.0
**kwargs Any

Other parameters of ImageToVideoGenerator.

{}

Returns:

Type Description
ImageToVideoGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
def animator(instructions: str | None = None, duration: float = 2.0, **kwargs: Any) -> ImageToVideoGenerator:
    """Return a generator that turns images into short videos.

    Args:
        instructions:
            A description of the motion.

        duration:
            The length of the videos in seconds.

        **kwargs:
            Other parameters of `ImageToVideoGenerator`.

    Returns:
        The configured generator.
    """
    return ImageToVideoGenerator(instructions=instructions, duration=duration, **kwargs)

background_remover(**kwargs)

Return a generator that removes the background of images.

Parameters:

Name Type Description Default
**kwargs Any

Other parameters of ImageToImageGenerator.

{}

Returns:

Type Description
ImageToImageGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
320
321
322
323
324
325
326
327
328
329
330
def background_remover(**kwargs: Any) -> ImageToImageGenerator:
    """Return a generator that removes the background of images.

    Args:
        **kwargs:
            Other parameters of `ImageToImageGenerator`.

    Returns:
        The configured generator.
    """
    return ImageToImageGenerator(operation='remove_background', **kwargs)

describer(kind='image', **kwargs)

Return a text generator that describes images, audio, videos or multimodal samples.

Parameters:

Name Type Description Default
kind Kind

The input kind.

'image'
**kwargs Any

Other parameters of the generator.

{}

Returns:

Type Description
BaseSupervisedGenerator

The configured {Kind}ToTextGenerator.

Source code in src/skai/presets/_presets.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def describer(kind: Kind = 'image', **kwargs: Any) -> BaseSupervisedGenerator:
    """Return a text generator that describes images, audio, videos or multimodal samples.

    Args:
        kind:
            The input kind.

        **kwargs:
            Other parameters of the generator.

    Returns:
        The configured `{Kind}ToTextGenerator`.
    """
    return _instructed(kind, INSTRUCTIONS['describer'].format(kind=kind), **kwargs)

diarizer(**kwargs)

Return a segmenter that splits audio into speaker turns.

Parameters:

Name Type Description Default
**kwargs Any

Other parameters of AudioSegmenter.

{}

Returns:

Type Description
AudioSegmenter

The configured segmenter.

Source code in src/skai/presets/_presets.py
278
279
280
281
282
283
284
285
286
287
288
def diarizer(**kwargs: Any) -> AudioSegmenter:
    """Return a segmenter that splits audio into speaker turns.

    Args:
        **kwargs:
            Other parameters of `AudioSegmenter`.

    Returns:
        The configured segmenter.
    """
    return AudioSegmenter(by='speaker', **kwargs)

document_parser(**kwargs)

Return a text generator that transcribes page images as Markdown that keeps their structure.

Parameters:

Name Type Description Default
**kwargs Any

Other parameters of ImageToTextGenerator.

{}

Returns:

Type Description
ImageToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
265
266
267
268
269
270
271
272
273
274
275
def document_parser(**kwargs: Any) -> ImageToTextGenerator:
    """Return a text generator that transcribes page images as Markdown that keeps their structure.

    Args:
        **kwargs:
            Other parameters of `ImageToTextGenerator`.

    Returns:
        The configured generator.
    """
    return ImageToTextGenerator(operation='transcribe', format='markdown', **kwargs)

lip_syncer(**kwargs)

Return a generator that makes the video of every sample speak its audio.

Parameters:

Name Type Description Default
**kwargs Any

Other parameters of MultimodalToVideoGenerator.

{}

Returns:

Type Description
MultimodalToVideoGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
397
398
399
400
401
402
403
404
405
406
407
def lip_syncer(**kwargs: Any) -> MultimodalToVideoGenerator:
    """Return a generator that makes the `video` of every sample speak its `audio`.

    Args:
        **kwargs:
            Other parameters of `MultimodalToVideoGenerator`.

    Returns:
        The configured generator.
    """
    return MultimodalToVideoGenerator(operation='lip_sync', **kwargs)

moderator(labels=None, kind='multimodal', **kwargs)

Return a classifier that labels samples as safe or unsafe.

Parameters:

Name Type Description Default
labels list[str] | None

The labels, ['safe', 'unsafe'] when it is None.

None
kind Kind

The input kind.

'multimodal'
**kwargs Any

Other parameters of the classifier.

{}

Returns:

Type Description
BaseClassifier

The configured {Kind}Classifier.

Source code in src/skai/presets/_presets.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
def moderator(labels: list[str] | None = None, kind: Kind = 'multimodal', **kwargs: Any) -> BaseClassifier:
    """Return a classifier that labels samples as safe or unsafe.

    Args:
        labels:
            The labels, `['safe', 'unsafe']` when it is `None`.

        kind:
            The input kind.

        **kwargs:
            Other parameters of the classifier.

    Returns:
        The configured `{Kind}Classifier`.
    """
    instructions = INSTRUCTIONS['moderator'].format(kind='sample' if kind == 'multimodal' else kind)
    return _CLASSIFIERS[kind](labels=labels or ['safe', 'unsafe'], instructions=instructions, **kwargs)

music_generator(duration=10.0, **kwargs)

Return a generator that creates music from descriptions.

Parameters:

Name Type Description Default
duration float

The length of the music in seconds.

10.0
**kwargs Any

Other parameters of TextToAudioGenerator.

{}

Returns:

Type Description
TextToAudioGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
349
350
351
352
353
354
355
356
357
358
359
360
361
362
def music_generator(duration: float = 10.0, **kwargs: Any) -> TextToAudioGenerator:
    """Return a generator that creates music from descriptions.

    Args:
        duration:
            The length of the music in seconds.

        **kwargs:
            Other parameters of `TextToAudioGenerator`.

    Returns:
        The configured generator.
    """
    return TextToAudioGenerator(operation='music', duration=duration, **kwargs)

object_detector(labels, **kwargs)

Return a segmenter that finds the boxes of objects in images.

Parameters:

Name Type Description Default
labels list[str]

The kinds of objects to find.

required
**kwargs Any

Other parameters of ImageSegmenter.

{}

Returns:

Type Description
ImageSegmenter

The configured segmenter.

Source code in src/skai/presets/_presets.py
291
292
293
294
295
296
297
298
299
300
301
302
303
304
def object_detector(labels: list[str], **kwargs: Any) -> ImageSegmenter:
    """Return a segmenter that finds the boxes of objects in images.

    Args:
        labels:
            The kinds of objects to find.

        **kwargs:
            Other parameters of `ImageSegmenter`.

    Returns:
        The configured segmenter.
    """
    return ImageSegmenter(by='object', labels=labels, **kwargs)

ocr(**kwargs)

Return a text generator that transcribes the text of images as plain text.

Parameters:

Name Type Description Default
**kwargs Any

Other parameters of ImageToTextGenerator.

{}

Returns:

Type Description
ImageToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
252
253
254
255
256
257
258
259
260
261
262
def ocr(**kwargs: Any) -> ImageToTextGenerator:
    """Return a text generator that transcribes the text of images as plain text.

    Args:
        **kwargs:
            Other parameters of `ImageToTextGenerator`.

    Returns:
        The configured generator.
    """
    return ImageToTextGenerator(operation='transcribe', **kwargs)

prompt_writer(target='image', **kwargs)

Return a text generator that writes a generation prompt from every text.

Parameters:

Name Type Description Default
target Literal['image', 'video', 'music']

The kind of generation model the prompt is for.

'image'
**kwargs Any

Other parameters of TextToTextGenerator.

{}

Returns:

Type Description
TextToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def prompt_writer(target: Literal['image', 'video', 'music'] = 'image', **kwargs: Any) -> TextToTextGenerator:
    """Return a text generator that writes a generation prompt from every text.

    Args:
        target:
            The kind of generation model the prompt is for.

        **kwargs:
            Other parameters of `TextToTextGenerator`.

    Returns:
        The configured generator.
    """
    return TextToTextGenerator(instructions=INSTRUCTIONS['prompt_writer'].format(target=target), **kwargs)

question_answerer(question, kind='text', **kwargs)

Return a text generator that answers one question about every sample.

Parameters:

Name Type Description Default
question str

The question.

required
kind Kind

The input kind.

'text'
**kwargs Any

Other parameters of the generator.

{}

Returns:

Type Description
BaseSupervisedGenerator

The configured {Kind}ToTextGenerator.

Source code in src/skai/presets/_presets.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def question_answerer(question: str, kind: Kind = 'text', **kwargs: Any) -> BaseSupervisedGenerator:
    """Return a text generator that answers one question about every sample.

    Args:
        question:
            The question.

        kind:
            The input kind.

        **kwargs:
            Other parameters of the generator.

    Returns:
        The configured `{Kind}ToTextGenerator`.
    """
    return _instructed(kind, INSTRUCTIONS['question_answerer'].format(kind=kind, question=question), **kwargs)

quiz_writer(n_questions=5, **kwargs)

Return a text generator that writes a multiple-choice quiz from every text.

Parameters:

Name Type Description Default
n_questions int

The number of questions.

5
**kwargs Any

Other parameters of TextToTextGenerator.

{}

Returns:

Type Description
TextToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def quiz_writer(n_questions: int = 5, **kwargs: Any) -> TextToTextGenerator:
    """Return a text generator that writes a multiple-choice quiz from every text.

    Args:
        n_questions:
            The number of questions.

        **kwargs:
            Other parameters of `TextToTextGenerator`.

    Returns:
        The configured generator.
    """
    return TextToTextGenerator(instructions=INSTRUCTIONS['quiz_writer'].format(n_questions=n_questions), **kwargs)

rewriter(style='clear and concise', **kwargs)

Return a text generator that rewrites texts in a style.

Parameters:

Name Type Description Default
style str

The style of the rewritten texts.

'clear and concise'
**kwargs Any

Other parameters of TextToTextGenerator.

{}

Returns:

Type Description
TextToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def rewriter(style: str = 'clear and concise', **kwargs: Any) -> TextToTextGenerator:
    """Return a text generator that rewrites texts in a style.

    Args:
        style:
            The style of the rewritten texts.

        **kwargs:
            Other parameters of `TextToTextGenerator`.

    Returns:
        The configured generator.
    """
    return TextToTextGenerator(instructions=INSTRUCTIONS['rewriter'].format(style=style), **kwargs)

script_writer(format='video narration', length='one-minute', **kwargs)

Return a text generator that writes a spoken script from every text.

Parameters:

Name Type Description Default
format str

The kind of script, such as 'video narration' or 'podcast'.

'video narration'
length str

The length of the script, in words a model understands, such as 'one-minute'.

'one-minute'
**kwargs Any

Other parameters of TextToTextGenerator.

{}

Returns:

Type Description
TextToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def script_writer(
    format: str = 'video narration',  # noqa: A002 - the name of the kind of script
    length: str = 'one-minute',
    **kwargs: Any,
) -> TextToTextGenerator:
    """Return a text generator that writes a spoken script from every text.

    Args:
        format:
            The kind of script, such as `'video narration'` or `'podcast'`.

        length:
            The length of the script, in words a model understands, such as `'one-minute'`.

        **kwargs:
            Other parameters of `TextToTextGenerator`.

    Returns:
        The configured generator.
    """
    instructions = INSTRUCTIONS['script_writer'].format(format=format, length=length)
    return TextToTextGenerator(instructions=instructions, **kwargs)

separator(stem='vocals', **kwargs)

Return a generator that separates the vocals or the accompaniment of audio.

Parameters:

Name Type Description Default
stem Literal['vocals', 'accompaniment']

The stem to keep.

'vocals'
**kwargs Any

Other parameters of AudioToAudioGenerator.

{}

Returns:

Type Description
AudioToAudioGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
def separator(stem: Literal['vocals', 'accompaniment'] = 'vocals', **kwargs: Any) -> AudioToAudioGenerator:
    """Return a generator that separates the vocals or the accompaniment of audio.

    Args:
        stem:
            The stem to keep.

        **kwargs:
            Other parameters of `AudioToAudioGenerator`.

    Returns:
        The configured generator.
    """
    return AudioToAudioGenerator(operation='separate', stem=stem, **kwargs)

shot_detector(**kwargs)

Return a segmenter that splits videos into shots locally.

Parameters:

Name Type Description Default
**kwargs Any

Other parameters of VideoSegmenter.

{}

Returns:

Type Description
VideoSegmenter

The configured segmenter.

Source code in src/skai/presets/_presets.py
307
308
309
310
311
312
313
314
315
316
317
def shot_detector(**kwargs: Any) -> VideoSegmenter:
    """Return a segmenter that splits videos into shots locally.

    Args:
        **kwargs:
            Other parameters of `VideoSegmenter`.

    Returns:
        The configured segmenter.
    """
    return VideoSegmenter(by='shot', **kwargs)

storyboarder(n_scenes='a few', **kwargs)

Return an extractor that splits every text into scenes with narration and visuals.

Parameters:

Name Type Description Default
n_scenes int | str

The number of scenes, or words such as 'a few'.

'a few'
**kwargs Any

Other parameters of TextExtractor.

{}

Returns:

Type Description
TextExtractor

The configured extractor, whose only field scenes is a list of records with narration and visual.

Source code in src/skai/presets/_presets.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
def storyboarder(n_scenes: int | str = 'a few', **kwargs: Any) -> TextExtractor:
    """Return an extractor that splits every text into scenes with narration and visuals.

    Args:
        n_scenes:
            The number of scenes, or words such as `'a few'`.

        **kwargs:
            Other parameters of `TextExtractor`.

    Returns:
        The configured extractor, whose only field `scenes` is a list of records with `narration` and `visual`.
    """
    fields = {'scenes': [{'narration': 'the words spoken in the scene', 'visual': 'what the viewer sees'}]}
    instructions = INSTRUCTIONS['storyboarder'].format(n_scenes=n_scenes)
    return TextExtractor(fields=fields, instructions=instructions, **kwargs)

summarizer(max_length='auto', **kwargs)

Return a text generator that summarizes texts.

Parameters:

Name Type Description Default
max_length int | Literal['auto'] | None

The maximum number of words of every summary, or 'auto' to learn it from reference summaries.

'auto'
**kwargs Any

Other parameters of TextToTextGenerator.

{}

Returns:

Type Description
TextToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def summarizer(max_length: int | Literal['auto'] | None = 'auto', **kwargs: Any) -> TextToTextGenerator:
    """Return a text generator that summarizes texts.

    Args:
        max_length:
            The maximum number of words of every summary, or `'auto'` to learn it from reference summaries.

        **kwargs:
            Other parameters of `TextToTextGenerator`.

    Returns:
        The configured generator.
    """
    return TextToTextGenerator(instructions=INSTRUCTIONS['summarizer'], max_length=max_length, **kwargs)

talking_head(avatar, **kwargs)

Return a generator that makes a portrait speak audio.

Parameters:

Name Type Description Default
avatar Any

The portrait.

required
**kwargs Any

Other parameters of AudioToVideoGenerator.

{}

Returns:

Type Description
AudioToVideoGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
def talking_head(avatar: Any, **kwargs: Any) -> AudioToVideoGenerator:
    """Return a generator that makes a portrait speak audio.

    Args:
        avatar:
            The portrait.

        **kwargs:
            Other parameters of `AudioToVideoGenerator`.

    Returns:
        The configured generator.
    """
    return AudioToVideoGenerator(avatar=avatar, **kwargs)

translator(target_language, *, learn_terms=True, **kwargs)

Return a text generator that translates texts and learns a glossary from reference translations.

Parameters:

Name Type Description Default
target_language str

The language of the translations.

required
learn_terms bool

Whether fit learns a glossary of consistently rendered terms.

True
**kwargs Any

Other parameters of TextToTextGenerator.

{}

Returns:

Type Description
TextToTextGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def translator(target_language: str, *, learn_terms: bool = True, **kwargs: Any) -> TextToTextGenerator:
    """Return a text generator that translates texts and learns a glossary from reference translations.

    Args:
        target_language:
            The language of the translations.

        learn_terms:
            Whether `fit` learns a glossary of consistently rendered terms.

        **kwargs:
            Other parameters of `TextToTextGenerator`.

    Returns:
        The configured generator.
    """
    instructions = INSTRUCTIONS['translator'].format(target_language=target_language)
    return TextToTextGenerator(instructions=instructions, learn_terms=learn_terms, **kwargs)

upscaler(scale=2, **kwargs)

Return a generator that upscales images.

Parameters:

Name Type Description Default
scale int

The factor of upscaling.

2
**kwargs Any

Other parameters of ImageToImageGenerator.

{}

Returns:

Type Description
ImageToImageGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
def upscaler(scale: int = 2, **kwargs: Any) -> ImageToImageGenerator:
    """Return a generator that upscales images.

    Args:
        scale:
            The factor of upscaling.

        **kwargs:
            Other parameters of `ImageToImageGenerator`.

    Returns:
        The configured generator.
    """
    return ImageToImageGenerator(operation='upscale', scale=scale, **kwargs)

voice_converter(voice, **kwargs)

Return a generator that says the speech of audio in another voice.

Parameters:

Name Type Description Default
voice Any

One recording or a list of recordings of the target voice.

required
**kwargs Any

Other parameters of AudioToAudioGenerator.

{}

Returns:

Type Description
AudioToAudioGenerator

The configured generator.

Source code in src/skai/presets/_presets.py
365
366
367
368
369
370
371
372
373
374
375
376
377
378
def voice_converter(voice: Any, **kwargs: Any) -> AudioToAudioGenerator:
    """Return a generator that says the speech of audio in another voice.

    Args:
        voice:
            One recording or a list of recordings of the target voice.

        **kwargs:
            Other parameters of `AudioToAudioGenerator`.

    Returns:
        The configured generator.
    """
    return AudioToAudioGenerator(operation='convert_voice', voice=voice, **kwargs)