Core
Shared building blocks of scikit-ai: media types, requests, backends and component bases.
AnimationRequest(image, motion_prompt=None, duration=2.0, fps=None, seed=None)
dataclass
Ask a backend to turn an image into a short video that starts from it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The first frame of the video. |
required |
motion_prompt
|
str | None
|
A description of the motion. |
None
|
duration
|
float
|
The length of the video in seconds. |
2.0
|
fps
|
int | None
|
The number of frames per second, or |
None
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
Audio(samples, sample_rate)
Hold audio samples and their sample rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
NDArray[floating]
|
The audio samples, with shape |
required |
sample_rate
|
int
|
The number of samples per second. |
required |
Examples:
>>> import numpy as np
>>> from skai.core import Audio
>>> audio = Audio(np.zeros(8000), 16000)
>>> audio.duration
0.5
Source code in src/skai/core/_media.py
96 97 98 | |
duration
property
The length of the audio in seconds.
__repr__()
Return a short description of the audio.
Source code in src/skai/core/_media.py
100 101 102 | |
from_bytes(data)
classmethod
Decode audio from encoded bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The encoded audio, in any format that libsndfile reads. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
The decoded audio. |
Source code in src/skai/core/_media.py
104 105 106 107 108 109 110 111 112 113 114 115 116 | |
resample(sample_rate)
Return the audio mixed to mono and resampled by linear interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
int
|
The new number of samples per second. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The resampled mono audio, or the mono audio itself when the rate is unchanged. |
Source code in src/skai/core/_media.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
save(path)
Write the audio to a WAV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The path of the file to write. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path of the written file. |
Source code in src/skai/core/_media.py
160 161 162 163 164 165 166 167 168 169 170 171 172 | |
to_bytes()
Encode the audio as WAV bytes.
Returns:
| Type | Description |
|---|---|
bytes
|
The WAV-encoded audio. |
Source code in src/skai/core/_media.py
150 151 152 153 154 155 156 157 158 | |
to_mono()
Return the audio mixed down to one channel.
Returns:
| Type | Description |
|---|---|
Audio
|
The mono audio. |
Source code in src/skai/core/_media.py
123 124 125 126 127 128 129 130 131 | |
AudioGenerationRequest(prompt, duration, seed=None)
dataclass
Ask a backend to generate music or a sound from a description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The description of the audio. |
required |
duration
|
float
|
The length of the audio in seconds. |
required |
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
AudioOperationRequest(audio, stem='vocals', voice=None, seed=None)
dataclass
Ask a backend to separate a stem of audio or to convert its voice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
The audio. |
required |
stem
|
str
|
The stem to keep when separating, |
'vocals'
|
voice
|
Audio | None
|
Reference audio of the target voice when converting. |
None
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
AvatarRequest(avatar, audio, seed=None)
dataclass
Ask a backend to animate a portrait so that it speaks an audio track.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
avatar
|
Image
|
The portrait to animate. |
required |
audio
|
Audio
|
The speech the portrait says. |
required |
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
Backend(model=None, *, options=None, max_concurrency=1)
Bases: BaseEstimator
Run component tasks on a model provider.
A backend implements a task by overriding the method of the same name. The tasks a backend supports are the
methods it overrides. Attributes that start with an underscore hold runtime state, such as a client, and are not
pickled. A key of default_models is a task, or '<task>:<input kind>' for a default that depends on the input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
The model to use. The default model of the task is used when it is |
None
|
options
|
dict | None
|
Extra keyword arguments passed to the provider on every call. |
None
|
max_concurrency
|
int
|
The maximum number of requests that run at the same time. |
1
|
Source code in src/skai/core/_backend.py
183 184 185 186 | |
call_options
property
The extra keyword arguments passed to the provider.
__getstate__()
Return the state to pickle without the runtime attributes.
Source code in src/skai/core/_backend.py
188 189 190 191 | |
__sklearn_clone__()
Clone the backend, sharing live objects such as clients, including those inside options.
Source code in src/skai/core/_backend.py
193 194 195 196 197 198 199 200 201 202 | |
animate_avatar(request)
Animate a portrait so that it speaks an audio track.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AvatarRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The video. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | |
animate_image(request)
Turn an image into a short video that starts from it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AnimationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The video. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
classify_audio(request)
Score audio against the labels of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score per label. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
classify_image(request)
Score an image against the labels of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score per label. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
classify_multimodal(request)
Score a multimodal sample against the labels of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score per label. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
classify_text(request)
Score a text against the labels of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score per label. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
classify_video(request)
Score sampled video frames against the labels of a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score per label. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
connect()
Prepare the backend to run requests, for example by creating a client.
Returns:
| Type | Description |
|---|---|
Self
|
The backend. |
Source code in src/skai/core/_backend.py
261 262 263 264 265 266 267 | |
convert_voice(request)
Say the speech of audio in another voice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AudioOperationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The converted speech. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
detect_objects(request)
Find the boxes of the regions of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RegionRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
list[Region]
|
The regions, without masks. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
diarize(request)
Find who speaks when, with what they say.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
DiarizationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Transcript
|
The transcript, with a speaker per segment. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
edit_image(request)
Edit an image with an instruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageEditRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The edited image. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
embed_audio(request)
Embed audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
EmbeddingRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
The embedding vector. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
embed_image(request)
Embed an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
EmbeddingRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
The embedding vector. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
embed_text(request)
Embed a text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
EmbeddingRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
The embedding vector. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
enhance_audio(request)
Remove the noise of audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AudioOperationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The denoised audio. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | |
extract_fields(request)
Extract named fields from a sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ExtractionRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The value of every field, or |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
find_moments(request)
Find the parts of audio or a video that match a description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MomentRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
list[Moment]
|
The moments, in time order. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
fine_tune(request)
Train a model on prompts and their expected answers, and wait until it is ready.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
FineTuneRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The id of the trained model. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
generate_image(request)
Generate an image from a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageGenerationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The image. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
generate_music(request)
Generate music from a description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AudioGenerationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The music. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
generate_sound(request)
Generate a sound from a description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AudioGenerationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The sound. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | |
generate_text(request)
Produce text from a sample by following instructions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
TextGenerationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
generate_video(request)
Generate a video from a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
VideoGenerationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The video. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
lip_sync(request)
Make a video speak new audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
LipSyncRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The video. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
pick_thumbnail(request)
Pick the frame that best represents a video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ThumbnailRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The index of the frame. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
remove_background(request)
Remove the background of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageOperationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
An RGBA image whose background is transparent. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
resolve_model(task, input_kind=None)
Return the model that runs a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The name of the task. |
required |
input_kind
|
str | None
|
The input kind of the sample, which selects a default model of |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
UnsupportedBackendError
|
If no model is given and the task has no default model. |
Source code in src/skai/core/_backend.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
run(task, requests)
Run a task on several requests, keeping their order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The name of the task. |
required |
requests
|
list[Any]
|
The requests. |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
The result of every request, or the exception it raised. |
Source code in src/skai/core/_backend.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
segment_image(request)
Find the masks of the regions of an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RegionRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
list[Region]
|
The regions, with masks. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
separate_audio(request)
Separate a stem of audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
AudioOperationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The stem. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
supported_tasks()
classmethod
Return the tasks that the backend implements.
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
The names of the tasks. |
Source code in src/skai/core/_backend.py
204 205 206 207 208 209 210 211 | |
supports(task, input_kind=None)
classmethod
Return whether the backend runs a task on samples of an input kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The name of the task. |
required |
input_kind
|
str | None
|
The input kind of the samples, or |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the task is supported. |
Source code in src/skai/core/_backend.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
synthesize_speech(request)
Speak a text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
SpeechRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The speech. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
transcribe(request)
Transcribe speech.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
TranscriptionRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Transcript
|
The transcript. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
transcribe_image(request)
Transcribe the text written in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageTranscriptionRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
upscale_image(request)
Upscale an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageOperationRequest
|
The request. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The upscaled image. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the backend does not support the task. |
Source code in src/skai/core/_backend.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
BaseClassifier
Bases: ClassifierMixin, BaseMediaEstimator
Assign labels with zero-shot or few-shot prediction.
__sklearn_tags__()
Declare that the classifier supports multilabel targets.
Source code in src/skai/core/_estimator.py
456 457 458 459 460 | |
fit(X=None, y=None)
Learn the classes and select the few-shot examples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike | None
|
The training samples. They can be |
None
|
y
|
ArrayLike | None
|
The targets, as labels or as a binary indicator matrix for multilabel classification. They can be
|
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The fitted classifier. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skai/core/_estimator.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
predict(X)
Predict the labels of every sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The predicted labels, or a binary indicator matrix for multilabel classification. A failed sample is |
NDArray
|
|
Source code in src/skai/core/_estimator.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
predict_proba(X)
Score every sample against every class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
An array of shape |
NDArray[float64]
|
every column is an independent probability. A failed sample has a row of NaN. |
Source code in src/skai/core/_estimator.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | |
BaseEmbedder
Bases: TransformerMixin, BaseMediaEstimator
Map every sample to a fixed-size vector, learning centering and a projection from the samples in fit.
fit(X=None, y=None)
Embed the samples and learn their mean and, when needed, a projection.
With X, every sample is embedded, the mean is learned for centering, and a PCA projection to dimensions
is learned when the backend cannot shorten embeddings. Without X, a small probe sample is embedded to find the
number of dimensions, and nothing is centered or projected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike | None
|
The samples. |
None
|
y
|
ArrayLike | None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The fitted embedder. |
Source code in src/skai/core/_estimator.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
get_feature_names_out(input_features=None)
Return the names of the embedding dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
ArrayLike | None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[object_]
|
The names |
Source code in src/skai/core/_estimator.py
704 705 706 707 708 709 710 711 712 713 714 715 716 | |
transform(X)
Embed every sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
An array of shape |
Source code in src/skai/core/_estimator.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
BaseExtractor
Bases: TransformerMixin, BaseMediaEstimator
Extract a record of declared fields from every sample, learning from reference records in fit.
predict returns one dict per sample, and transform one column per top-level field.
fit(X=None, y=None)
Resolve the backend and select example pairs of samples and their reference records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike | None
|
The training samples. They can be |
None
|
y
|
ArrayLike | None
|
The reference record of every sample, as dicts keyed by field name. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The fitted extractor. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skai/core/_estimator.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
get_feature_names_out(input_features=None)
Return the top-level field names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
ArrayLike | None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
NDArray[object_]
|
The field names, in the order of |
Source code in src/skai/core/_estimator.py
805 806 807 808 809 810 811 812 813 814 815 816 | |
predict(X)
Extract the record of every sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[object_]
|
One dict per sample whose keys are the field names, or |
Source code in src/skai/core/_estimator.py
776 777 778 779 780 781 782 783 784 785 786 | |
transform(X)
Extract the fields of every sample as columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[object_]
|
An object array of shape |
Source code in src/skai/core/_estimator.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
BaseGenerator
Bases: TransformerMixin, BaseMediaEstimator
Generate one output per sample, returned by both predict and transform.
fit(X=None, y=None)
Validate the parameters and resolve the backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike | None
|
Ignored. The component learns nothing from data. |
None
|
y
|
ArrayLike | None
|
Ignored. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The fitted component. |
Source code in src/skai/core/_estimator.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
predict(X)
Generate one output per sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The outputs, in input order. |
Source code in src/skai/core/_estimator.py
315 316 317 318 319 320 321 322 323 324 325 | |
transform(X)
Generate one output per sample, so the component can be an intermediate pipeline step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
The outputs, in input order. |
Source code in src/skai/core/_estimator.py
327 328 329 330 331 332 333 334 335 336 337 | |
BaseMediaEstimator
Bases: BaseEstimator
Resolve the backend, batch samples and handle failed samples for media components.
A component declares its input kind and its operations as class variables. operations maps every operation to the
backend task that runs it, or to None for an operation that runs locally without a backend. The first operation is
the default, and the parameter named by operation_param selects one at fit. default_backends overrides
default_backend for some operations.
__init_subclass__(**kwargs)
Validate the operation parameter of a component against its operations.
Source code in src/skai/core/_estimator.py
105 106 107 108 109 110 111 | |
__sklearn_tags__()
Declare the input type and the non-deterministic output of the component.
Source code in src/skai/core/_estimator.py
113 114 115 116 117 118 119 | |
BaseMediaGenerator
Bases: BaseGenerator
Generate images, audio or video and return them in the requested output format.
Local operations need the video extra for videos, and no backend.
BaseSegmenter
Bases: BaseSupervisedGenerator
Split every sample into a list of region records, chosen with the by parameter.
Every region is a dict with at least label, score and media, the cropped piece of the sample.
BaseSupervisedGenerator
Bases: BaseGenerator
Generate outputs and learn from reference outputs given as y in fit.
fit(X, y) learns from the references. fit_transform(X, y), which pipelines use for intermediate steps, ignores
y unless use_y=True, because y is then the target of the final step.
fit(X=None, y=None)
Learn from reference outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike | None
|
The training samples. |
None
|
y
|
ArrayLike | None
|
The reference output of every sample, such as its summary or transcript. Without it, the component predicts zero-shot. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The fitted component. |
Source code in src/skai/core/_estimator.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
fit_transform(X, y=None, **fit_params)
Fit and return the outputs, ignoring y unless use_y=True.
Pipelines fit intermediate steps through this method and pass them the target of the final step, so y is
not read as references by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ArrayLike
|
The samples. |
required |
y
|
ArrayLike | None
|
The references, used only when |
None
|
**fit_params
|
Any
|
Ignored. |
{}
|
Returns:
| Type | Description |
|---|---|
NDArray
|
The outputs, in input order. |
Source code in src/skai/core/_estimator.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
ClassificationRequest(sample, labels, descriptions=dict(), instructions=None, examples=(), multi_label=False)
dataclass
Ask a backend to score a sample against a set of labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Sample
|
The text, image, audio, sampled video frames or multimodal sample to classify. |
required |
labels
|
tuple[str, ...]
|
The candidate labels. |
required |
descriptions
|
dict[str, str]
|
Descriptions of the labels, keyed by label. |
dict()
|
instructions
|
str | None
|
Extra guidance on how to assign the labels. |
None
|
examples
|
tuple[tuple[Any, tuple[str, ...]], ...]
|
Labeled examples, as pairs of a sample and its labels. |
()
|
multi_label
|
bool
|
Whether a sample can have several labels. |
False
|
DiarizationRequest(audio, language=None, vocabulary=())
dataclass
Ask a backend to find who speaks when, with what they say.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
The speech to diarize. |
required |
language
|
str | None
|
The language of the speech. It is detected when it is |
None
|
vocabulary
|
tuple[str, ...]
|
Domain terms that the speech may contain. |
()
|
EmbeddingRequest(sample, dimensions=None)
dataclass
Ask a backend to embed a text, an image or audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
str | Image | Audio
|
The text, image or audio to embed. |
required |
dimensions
|
int | None
|
The number of dimensions of the embedding, for backends that can shorten embeddings. |
None
|
ExtractionRequest(sample, fields, instructions=None, examples=())
dataclass
Ask a backend to extract named fields from a sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Sample
|
The text, image, audio, sampled video frames or multimodal sample to extract from. |
required |
fields
|
tuple[tuple[str, Any], ...]
|
The field names and their declarations, in output order. A declaration is a description, a dict of subfields, or a one-element list of either for a list of values. |
required |
instructions
|
str | None
|
Extra guidance on how to extract the fields. |
None
|
examples
|
tuple[tuple[Any, dict[str, Any]], ...]
|
Example pairs of a sample and its reference record. |
()
|
FineTuneError
Bases: RuntimeError
Signal that a fine-tuning job failed or was cancelled.
FineTuneRequest(task, examples)
dataclass
Ask a backend to train a model on prompts and their expected answers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task the model is trained for. |
required |
examples
|
tuple[tuple[Prompt, str], ...]
|
Pairs of a prompt and the answer the model must give. |
required |
ImageEditRequest(image, instruction, mask=None, seed=None)
dataclass
Ask a backend to edit an image with an instruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image to edit. |
required |
instruction
|
str
|
The edit to apply. |
required |
mask
|
Image | None
|
The region to edit, as a grayscale image where white marks the region, or |
None
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
ImageGenerationRequest(prompt, size, style=None, negative_prompt=None, seed=None, reference_images=())
dataclass
Ask a backend to generate an image from a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The description of the image. |
required |
size
|
tuple[int, int]
|
The width and height of the image in pixels. |
required |
style
|
str | None
|
A description of the visual style. |
None
|
negative_prompt
|
str | None
|
A description of what the image must not show. |
None
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
reference_images
|
tuple[Image, ...]
|
Images of a subject that the image must show consistently. |
()
|
ImageOperationRequest(image, scale=2, seed=None)
dataclass
Ask a backend to upscale an image or remove its background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image. |
required |
scale
|
int
|
The factor of upscaling. |
2
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
ImageTranscriptionRequest(image, markdown=False)
dataclass
Ask a backend to transcribe the text written in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image to read. |
required |
markdown
|
bool
|
Whether to keep the page structure as Markdown. |
False
|
InvalidResponseError
Bases: ValueError
Signal that a backend returned a response that does not fit the task.
InvalidSampleError
Bases: TypeError
Signal that a sample has the wrong type for a component.
LipSyncRequest(video, audio, seed=None)
dataclass
MediaReadError
Bases: ValueError
Signal that a media sample cannot be read or decoded.
MissingCredentialError
Bases: RuntimeError
Signal that the environment variable holding a credential is not set.
MissingExtraError
Bases: ImportError
Signal that an optional dependency group is not installed.
Moment(start, end, score)
dataclass
Hold one part of audio or a video that matches a description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float
|
The start time in seconds. |
required |
end
|
float
|
The end time in seconds. |
required |
score
|
float
|
The confidence of the backend. |
required |
MomentRequest(sample, prompt)
dataclass
Ask a backend to find the parts of audio or a video that match a description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Audio | VideoFrames
|
The audio or the sampled video frames. |
required |
prompt
|
str
|
A description of the moments to find. |
required |
MultiRequest
Bases: tuple
Hold several backend requests of one sample, whose results are returned together as a list.
Prompt(system, user, images=(), audio=(), json_output=False)
dataclass
Hold the messages of a prompt for a chat or vision model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
The system message. |
required |
user
|
str
|
The user message. Images are referred to as |
required |
images
|
tuple[Image, ...]
|
The images of the user message, in the order they are referred to. |
()
|
audio
|
tuple[Audio, ...]
|
The audio of the user message, in the order it is referred to. |
()
|
json_output
|
bool
|
Whether the answer must be a JSON object. |
False
|
PromptedBackend(model=None, *, options=None, max_concurrency=1)
Bases: Backend
Run analysis and text tasks by prompting a chat, vision or audio model.
A subclass implements complete, and inherits classification, text generation, field extraction, image
transcription, object detection, moment finding and thumbnail picking for every input kind its models accept:
text, images and video frames always, and audio only when the subclass sets accepts_audio. Video requests
include the audio track only when it sets sends_video_audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
The model to use. The default model of the task is used when it is |
None
|
options
|
dict | None
|
Extra keyword arguments passed to the provider on every call. |
None
|
max_concurrency
|
int
|
The maximum number of requests that run at the same time. |
1
|
Source code in src/skai/core/_backend.py
183 184 185 186 | |
classify_audio(request)
Score audio by asking an audio model for its labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The classification request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score of one for every label the model names and zero for the others. |
Source code in src/skai/core/_backend.py
912 913 914 915 916 917 918 919 920 921 922 | |
classify_image(request)
Score an image by asking the vision model for its labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The classification request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score of one for every label the model names and zero for the others. |
Source code in src/skai/core/_backend.py
900 901 902 903 904 905 906 907 908 909 910 | |
classify_multimodal(request)
Score a multimodal sample by asking the model for its labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The classification request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score of one for every label the model names and zero for the others. |
Source code in src/skai/core/_backend.py
936 937 938 939 940 941 942 943 944 945 946 | |
classify_text(request)
Score a text by asking the model for its labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The classification request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score of one for every label the model names and zero for the others. |
Source code in src/skai/core/_backend.py
888 889 890 891 892 893 894 895 896 897 898 | |
classify_video(request)
Score sampled video frames by asking the vision model for their labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ClassificationRequest
|
The classification request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A score of one for every label the model names and zero for the others. |
Source code in src/skai/core/_backend.py
924 925 926 927 928 929 930 931 932 933 934 | |
complete(prompt, model)
abstractmethod
Return the answer of a model to a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
Prompt
|
The prompt. |
required |
model
|
str
|
The model to prompt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The answer of the model. |
Source code in src/skai/core/_backend.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
detect_objects(request)
Find the boxes of regions by asking the vision model for them as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RegionRequest
|
The region request. |
required |
Returns:
| Type | Description |
|---|---|
list[Region]
|
The regions, without masks. |
Source code in src/skai/core/_backend.py
988 989 990 991 992 993 994 995 996 997 998 999 | |
extract_fields(request)
Extract fields by asking the model for a JSON object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ExtractionRequest
|
The extraction request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The value of every field, or |
Source code in src/skai/core/_backend.py
961 962 963 964 965 966 967 968 969 970 971 972 973 | |
find_moments(request)
Find moments by asking the model for their times as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MomentRequest
|
The moment request. |
required |
Returns:
| Type | Description |
|---|---|
list[Moment]
|
The moments, in time order. |
Source code in src/skai/core/_backend.py
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 | |
generate_text(request)
Produce text from a sample by prompting the model with the instructions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
TextGenerationRequest
|
The text generation request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text. |
Source code in src/skai/core/_backend.py
948 949 950 951 952 953 954 955 956 957 958 959 | |
pick_thumbnail(request)
Pick the frame that best represents a video by asking the vision model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ThumbnailRequest
|
The thumbnail request. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The index of the frame. |
Source code in src/skai/core/_backend.py
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
sends_video_audio_now()
Return whether video requests include the audio track with the current settings.
Returns:
| Type | Description |
|---|---|
bool
|
The class flag |
Source code in src/skai/core/_backend.py
851 852 853 854 855 856 857 | |
supported_tasks()
classmethod
Return the tasks that the backend implements, without classify_audio when it does not accept audio.
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
The names of the tasks. |
Source code in src/skai/core/_backend.py
820 821 822 823 824 825 826 827 828 829 830 | |
supports(task, input_kind=None)
classmethod
Return whether the backend runs a task on samples of an input kind, refusing prompted audio without audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The name of the task. |
required |
input_kind
|
str | None
|
The input kind of the samples, or |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the task is supported. |
Source code in src/skai/core/_backend.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
transcribe_image(request)
Transcribe the text of an image by prompting the vision model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageTranscriptionRequest
|
The image transcription request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text. |
Source code in src/skai/core/_backend.py
975 976 977 978 979 980 981 982 983 984 985 986 | |
Region(label, score, box, mask=None)
dataclass
Hold one region that a backend found in an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The kind of region. |
required |
score
|
float
|
The confidence of the backend. |
required |
box
|
tuple[int, int, int, int]
|
The |
required |
mask
|
Image | None
|
A grayscale image of the input size whose white pixels belong to the region, or |
None
|
RegionRequest(image, labels=(), prompt=None)
dataclass
Ask a backend to find regions of an image, as boxes or masks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image to search. |
required |
labels
|
tuple[str, ...]
|
The kinds of regions to find. |
()
|
prompt
|
str | None
|
A description of the regions to find, used when |
None
|
SampleError
Bases: RuntimeError
Signal that processing one sample failed.
SampleFailureWarning
Bases: UserWarning
Warn that some samples failed and were replaced by missing values.
Segment(start, end, text, speaker=None)
dataclass
Hold one timed piece of a transcript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float
|
The start time in seconds. |
required |
end
|
float
|
The end time in seconds. |
required |
text
|
str
|
The transcribed text. |
required |
speaker
|
str | None
|
The label of the speaker, or |
None
|
SpeechRequest(text, voice=None, language=None, seed=None)
dataclass
Ask a backend to speak a text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to speak. |
required |
voice
|
str | Audio | None
|
A voice name of the backend, or reference audio of the voice to clone. |
None
|
language
|
str | None
|
The language of the text. |
None
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
TextGenerationRequest(sample, instructions, examples=(), max_length=None, glossary=())
dataclass
Ask a backend to produce text from a sample by following instructions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Sample
|
The text, image, audio, sampled video frames or multimodal sample. |
required |
instructions
|
str
|
What to produce. |
required |
examples
|
tuple[tuple[Any, str], ...]
|
Example pairs of a sample and its reference output. |
()
|
max_length
|
int | None
|
The maximum number of words of the output, or |
None
|
glossary
|
tuple[tuple[str, str], ...]
|
Pairs of a term and its required rendering. |
()
|
ThumbnailRequest(frames)
dataclass
Ask a backend to pick the frame that best represents a video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
VideoFrames
|
The sampled frames of the video. |
required |
Transcript(text, segments=())
dataclass
Hold a transcript and its timed segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The full transcribed text. |
required |
segments
|
tuple[Segment, ...]
|
The timed segments or words. |
()
|
TranscriptionRequest(audio, language=None, timestamps=None, vocabulary=())
dataclass
Ask a backend to transcribe speech.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
The speech to transcribe. |
required |
language
|
str | None
|
The language of the speech. It is detected when it is |
None
|
timestamps
|
Timestamps
|
The granularity of the timestamps, or |
None
|
vocabulary
|
tuple[str, ...]
|
Domain terms that the speech may contain, given to the model as context for spelling. |
()
|
UnsupportedBackendError
Bases: ValueError
Signal that a backend is unknown or cannot run a task.
UnusedFitDataWarning
Bases: UserWarning
Warn that the backend cannot use something the component learned in fit.
Video(frames=None, fps=None, audio=None, *, data=None, subtitles=None)
Hold a video as decoded frames or as encoded MP4 bytes.
Either frames and fps or data must be given. The other representation is computed when it is first needed,
which requires the video extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
NDArray[uint8] | None
|
The RGB frames, with shape |
None
|
fps
|
float | None
|
The number of frames per second. |
None
|
audio
|
Audio | None
|
The audio track. |
None
|
data
|
bytes | None
|
The MP4-encoded video. |
None
|
subtitles
|
str | None
|
Subtitles in SRT format, written next to the video by |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
Examples:
>>> import numpy as np
>>> from skai.core import Video
>>> video = Video(np.zeros((50, 64, 64, 3), dtype=np.uint8), fps=25)
>>> video.duration
2.0
Source code in src/skai/core/_media.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
audio
property
The audio track of the video.
duration
property
The length of the video in seconds.
fps
property
The number of frames per second.
frames
property
The RGB frames of the video.
__repr__()
Return a short description of the video.
Source code in src/skai/core/_media.py
227 228 229 230 231 | |
audio_track()
Return the audio track mixed to mono, or silence as long as the video when it has no track.
Returns:
| Type | Description |
|---|---|
Audio
|
The mono audio track. |
Source code in src/skai/core/_media.py
296 297 298 299 300 301 302 303 304 | |
resize(size)
Return a copy whose frames are resized to a width and height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
tuple[int, int]
|
The width and height in pixels. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The resized video, or the video itself when it already has that size. |
Source code in src/skai/core/_media.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
save(path)
Write the video to an MP4 file, and its subtitles to an SRT file of the same name when it has them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The path of the file to write. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path of the written video file. |
Source code in src/skai/core/_media.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
to_bytes()
Encode the video as MP4 bytes.
Returns:
| Type | Description |
|---|---|
bytes
|
The MP4-encoded video. |
Source code in src/skai/core/_media.py
306 307 308 309 310 311 312 313 314 | |
trim(seconds)
Return a copy cut to at most a number of seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float
|
The maximum length in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The trimmed video, or the video itself when it is not longer. |
Source code in src/skai/core/_media.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
VideoFrames(frames, timestamps, duration, audio=None)
dataclass
Hold frames sampled from a video, their times and the audio track.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
tuple[Image, ...]
|
The sampled frames as PIL images. |
required |
timestamps
|
tuple[float, ...]
|
The time of every frame in seconds. |
required |
duration
|
float
|
The length of the video in seconds. |
required |
audio
|
Audio | None
|
The mono audio track of the video, or |
None
|
VideoGenerationRequest(prompt, duration, size, fps=None, style=None, negative_prompt=None, seed=None)
dataclass
Ask a backend to generate a video from a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The description of the video. |
required |
duration
|
float
|
The length of the video in seconds. |
required |
size
|
tuple[int, int]
|
The width and height of the video in pixels. |
required |
fps
|
int | None
|
The number of frames per second, or |
None
|
style
|
str | None
|
A description of the visual style. |
None
|
negative_prompt
|
str | None
|
A description of what the video must not show. |
None
|
seed
|
int | None
|
The seed for backends that support seeding. |
None
|
build_image_prompt(request)
Build the text prompt of an image generation model from a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ImageGenerationRequest
|
The image generation request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The prompt, with the style appended. |
Source code in src/skai/core/_prompts.py
438 439 440 441 442 443 444 445 446 447 448 | |
build_task_prompt(task, request)
Build the prompt that a prompted backend sends for a task and a request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The name of the task. |
required |
request
|
ClassificationRequest | TextGenerationRequest | ExtractionRequest
|
The request of the task. |
required |
Returns:
| Type | Description |
|---|---|
Prompt
|
The prompt. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the task is not answered by prompting. |
Source code in src/skai/core/_prompts.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
check_size(size, owner)
Check that a size parameter is a pair of positive integers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
object
|
The value of the |
required |
owner
|
str
|
The name of the component, used in the error message. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
The width and height. |
Raises:
| Type | Description |
|---|---|
InvalidParameterError
|
If the size is not a |
Source code in src/skai/core/_utils.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
collage(images, columns=None, tile=256)
Lay images out in a grid of square tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list[Image]
|
The images. |
required |
columns
|
int | None
|
The number of columns, the square root of the number of images rounded up when it is |
None
|
tile
|
int
|
The side of every tile in pixels. |
256
|
Returns:
| Type | Description |
|---|---|
Image
|
The collage, with black where there are no images. |
Source code in src/skai/core/_local.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
concatenate_audio(tracks, gap=0.0)
Join audio tracks in order, mixed to mono at the rate of the first one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
list[Audio]
|
The tracks to join. |
required |
gap
|
float
|
The seconds of silence between consecutive tracks. |
0.0
|
Returns:
| Type | Description |
|---|---|
Audio
|
The joined audio. |
Source code in src/skai/core/_local.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
concatenate_video(clips)
Join video clips in order, at the size and frame rate of the first one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clips
|
list[Video]
|
The clips to join. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The joined video, with the joined audio tracks when any clip has one. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no clips are given. |
Source code in src/skai/core/_local.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
crop_to_aspect(video, aspect_ratio, centers)
Crop a video to an aspect ratio, following horizontal subject centers over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
aspect_ratio
|
float
|
The width divided by the height of the output. |
required |
centers
|
list[float]
|
The horizontal center of the subject, from 0 to 1, at evenly spaced times. An empty list centers the crop. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The cropped video. |
Source code in src/skai/core/_local.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
cut_audio(audio, start, end)
Return the part of audio between two times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
The audio. |
required |
start
|
float
|
The start time in seconds. |
required |
end
|
float
|
The end time in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The part of the audio. |
Source code in src/skai/core/_local.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
cut_video(video, start, end)
Return the part of a video between two times, with its audio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
start
|
float
|
The start time in seconds. |
required |
end
|
float
|
The end time in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The part of the video, with at least one frame. |
Source code in src/skai/core/_local.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
draw_seeds(random_state, count)
Draw the seeds that components send to backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_state
|
int | RandomState | None
|
The |
required |
count
|
int
|
The number of seeds. |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
The seeds, reproducible for an integer |
Source code in src/skai/core/_utils.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
encode_png(image)
Encode an image as PNG bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image to encode. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The PNG-encoded image. |
Source code in src/skai/core/_io.py
88 89 90 91 92 93 94 95 96 97 98 99 100 | |
extract_audio(video)
Return the mono audio track of a video, or silence as long as the video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
Returns:
| Type | Description |
|---|---|
Audio
|
The audio track. |
Source code in src/skai/core/_local.py
101 102 103 104 105 106 107 108 109 110 111 | |
find_terms(text)
Find the terms of a text that look like names, products or technical terms.
A term is a token of two or more characters that contains a digit, has an upper-case letter after its first character, or starts with an upper-case letter in the middle of a sentence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to search. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The terms in order of first appearance, with repeats. |
Examples:
>>> from skai.core import find_terms
>>> find_terms('We deploy on Kubernetes with gRPC and Python 3.12.')
['Kubernetes', 'gRPC', 'Python', '3.12']
Source code in src/skai/core/_terms.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
frame_at(video, at)
Return the frame of a video at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
at
|
float
|
The time in seconds, clamped to the video. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The frame. |
Source code in src/skai/core/_local.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
import_optional(module, extra)
Import a module that belongs to an optional dependency group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
str
|
The name of the module to import. |
required |
extra
|
str
|
The name of the optional dependency group that provides the module. |
required |
Returns:
| Type | Description |
|---|---|
ModuleType
|
The imported module. |
Raises:
| Type | Description |
|---|---|
MissingExtraError
|
If the module is not installed. |
Source code in src/skai/core/_utils.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
input_kind_of(sample)
Return the input kind of a read sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
object
|
A text, image, audio, sampled video frames or multimodal sample. |
required |
Returns:
| Type | Description |
|---|---|
str
|
One of |
Source code in src/skai/core/_backend.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
list_backends(task=None, predicate=None, input_kind=None)
List the names of the registered backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str | None
|
Keep only the backends that support this task. |
None
|
predicate
|
Callable[[type[Backend]], bool] | None
|
Keep only the backend classes for which this function returns |
None
|
input_kind
|
str | None
|
Keep only the backends that run the task on samples of this input kind. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The sorted backend names. |
Examples:
>>> from skai.core import list_backends
>>> 'dummy' in list_backends('generate_text')
True
Source code in src/skai/core/_registry.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
mix_audio(tracks, *, volumes=None, duck_under=None, duck_for=None, duck_level=0.25, threshold=0.01)
Mix named tracks, lowering some of them while another one is not silent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracks
|
dict[str, Audio]
|
The tracks to mix, by name. |
required |
volumes
|
dict[str, float] | None
|
The gain of every track, one when it is missing. |
None
|
duck_under
|
list[str] | None
|
The names of the tracks to lower. |
None
|
duck_for
|
str | None
|
The name of the track whose sound lowers the others. |
None
|
duck_level
|
float
|
The gain of the lowered tracks while |
0.25
|
threshold
|
float
|
The RMS level above which |
0.01
|
Returns:
| Type | Description |
|---|---|
Audio
|
A mono track as long as the longest one, clipped to |
Source code in src/skai/core/_local.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
mux(video, audio)
Replace the soundtrack of a video, cut or padded to the length of the video.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
audio
|
Audio
|
The new soundtrack. |
required |
Returns:
| Type | Description |
|---|---|
Video
|
The video with the new soundtrack. |
Source code in src/skai/core/_local.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
place_audio(clips, length=0.0)
Place audio clips at their start times on one silent track.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clips
|
list[tuple[float, Audio]]
|
Pairs of a start time in seconds and a clip. Overlapping clips are added. |
required |
length
|
float
|
The minimum length of the track in seconds. |
0.0
|
Returns:
| Type | Description |
|---|---|
Audio
|
A mono track at the rate of the first clip, long enough for every clip. |
Source code in src/skai/core/_local.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
read_audio(sample, index=0)
Read audio from a path, a URL, bytes, an Audio object or a (samples, sample_rate) tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
object
|
The audio to read. |
required |
index
|
int
|
The position of the sample in the input. |
0
|
Returns:
| Type | Description |
|---|---|
Audio
|
The audio. |
Raises:
| Type | Description |
|---|---|
MediaReadError
|
If the sample cannot be read as audio. |
Source code in src/skai/core/_io.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
read_env(name)
Read the value of the environment variable that holds a credential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the environment variable. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value of the environment variable. |
Raises:
| Type | Description |
|---|---|
MissingCredentialError
|
If the environment variable is not set or is empty. |
Source code in src/skai/core/_utils.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
read_image(sample, index=0)
Read an image from a path, a URL, bytes, a PIL image or a NumPy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
object
|
The image to read. |
required |
index
|
int
|
The position of the sample in the input. |
0
|
Returns:
| Type | Description |
|---|---|
Image
|
The image. |
Raises:
| Type | Description |
|---|---|
MediaReadError
|
If the sample cannot be read as an image. |
Source code in src/skai/core/_io.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
read_input(kind, sample, index, n_frames=None)
Read one sample of an input kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
InputKind
|
The input kind. |
required |
sample
|
object
|
The sample. |
required |
index
|
int
|
The position of the sample in the input. |
required |
n_frames
|
int | None
|
The number of frames to sample from videos, or |
None
|
Returns:
| Type | Description |
|---|---|
object
|
The read sample. |
Source code in src/skai/core/_io.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
read_multimodal(sample, index=0, n_frames=None, required=())
Read a multimodal sample, a dict of named texts, images, audio, videos or transcripts.
Strings are read as texts, unless they are URLs or paths of existing files with a media extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
object
|
The dict, or a pandas row, to read. |
required |
index
|
int
|
The position of the sample in the input. |
0
|
n_frames
|
int | None
|
The number of frames to sample from every video, or |
None
|
required
|
tuple[str, ...]
|
The keys the sample must have. |
()
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The sample, with every part read by its own kind. |
Raises:
| Type | Description |
|---|---|
InvalidSampleError
|
If the sample is not a dict or misses a required key. |
Source code in src/skai/core/_io.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
read_video(sample, index=0)
Read a video from a path, a URL, bytes or a Video object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
object
|
The video to read. |
required |
index
|
int
|
The position of the sample in the input. |
0
|
Returns:
| Type | Description |
|---|---|
Video
|
The video. |
Raises:
| Type | Description |
|---|---|
MediaReadError
|
If the sample cannot be read as a video. |
Source code in src/skai/core/_io.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
read_video_frames(sample, index, n_frames)
Read a video and sample evenly spaced frames of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
object
|
The video to read, or frames that were already sampled. |
required |
index
|
int
|
The position of the sample in the input. |
required |
n_frames
|
int
|
The number of frames to sample. |
required |
Returns:
| Type | Description |
|---|---|
VideoFrames
|
The sampled frames. |
Raises:
| Type | Description |
|---|---|
MediaReadError
|
If the video cannot be decoded. |
Source code in src/skai/core/_io.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
register(name, backend_class)
Register a backend class under a name, so the name can be used in backend strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The provider name, used as |
required |
backend_class
|
type[Backend]
|
The backend class. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
>>> from skai.core import Backend, register
>>> class EchoBackend(Backend):
... def generate_text(self, request):
... return request.sample
>>> register('echo', EchoBackend)
Source code in src/skai/core/_registry.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
sample_frames(video, n_frames)
Sample evenly spaced frames of a video, starting with the first frame.
A video with fewer frames than n_frames gives all of its frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video to sample. |
required |
n_frames
|
int
|
The number of frames to sample. |
required |
Returns:
| Type | Description |
|---|---|
VideoFrames
|
The sampled frames, their times, the length of the video, and its mono audio track when it has one. |
Source code in src/skai/core/_io.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
shot_spans(video, threshold=0.5)
Find the shots of a video from the histogram distance between consecutive frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
threshold
|
float
|
The total variation distance between the color histograms of consecutive frames above which a cut is found, from 0 to 1. |
0.5
|
Returns:
| Type | Description |
|---|---|
list[tuple[float, float]]
|
The |
Source code in src/skai/core/_local.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
sound_spans(audio, threshold=0.01, min_silence=0.3)
Find the parts of audio between silences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
The audio. |
required |
threshold
|
float
|
The RMS level below which audio counts as silent. |
0.01
|
min_silence
|
float
|
The shortest silence in seconds that separates two parts. |
0.3
|
Returns:
| Type | Description |
|---|---|
list[tuple[float, float]]
|
The |
Source code in src/skai/core/_local.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
subtitle(video, transcript, burn=True)
Show a transcript as subtitles, burned into the frames or attached in SRT format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Video
|
The video. |
required |
transcript
|
Any
|
The transcript, in any form that |
required |
burn
|
bool
|
Whether to draw the subtitles on the frames. Otherwise they are attached as |
True
|
Returns:
| Type | Description |
|---|---|
Video
|
The subtitled video. |
Source code in src/skai/core/_local.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
text_spans(text, by, chunk_size=1000)
Split a text into paragraphs, sentences or fixed-size chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text. |
required |
by
|
str
|
|
required |
chunk_size
|
int
|
The number of characters of a chunk. |
1000
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, int]]
|
The |
Source code in src/skai/core/_local.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
to_chat_messages(prompt)
Turn a prompt into chat messages in the OpenAI format, with images as data URLs and audio as WAV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
Prompt
|
The prompt. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
The system and user messages. |
Source code in src/skai/core/_prompts.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
to_cues(transcript, duration)
Turn a transcript into timed subtitle cues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transcript
|
Any
|
A string shown for the whole duration, a |
required |
duration
|
float
|
The length of the video in seconds. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[float, float, str]]
|
The cues as |
Source code in src/skai/core/_local.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
to_data_url(image)
Encode an image as a PNG data URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image
|
The image to encode. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The data URL. |
Source code in src/skai/core/_io.py
103 104 105 106 107 108 109 110 111 112 113 | |
to_object_array(items)
Pack items into a one-dimensional object array without broadcasting them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Iterable[Any]
|
The items to pack. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[object_]
|
The object array that holds the items. |
Source code in src/skai/core/_io.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
to_samples(X, rows=False)
Convert a container of samples into a list of samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Any
|
A list, tuple, NumPy array, pandas Series or single-column DataFrame of samples, or |
required |
rows
|
bool
|
Whether every row of a DataFrame is one multimodal sample, a dict keyed by column. |
False
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
The samples. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skai/core/_io.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
to_srt(cues)
Write subtitle cues in SRT format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cues
|
list[tuple[float, float, str]]
|
The cues as |
required |
Returns:
| Type | Description |
|---|---|
str
|
The SRT text. |
Source code in src/skai/core/_local.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |