Integrations¶
aana.integrations.haystack
¶
AanaDeploymentComponent
¶
Wrapper for Aana deployments to run as HayStack Components.
Example
deployment_handle = await AanaDeploymentHandle.create("my_deployment")
haystack_component = AanaDeploymentComponent(deployment_handle, "my_method")
haystack_component.warm_up() # This is currently a no-op, but subject to change.
component_result = haystack_component.run(my_input_prompt="This is an input prompt")
PARAMETER | DESCRIPTION |
---|---|
deployment_handle |
the Aana Ray deployment to be wrapped (must be a class Deployment)
TYPE:
|
method_name |
the name of the method on the deployment to call inside the component's
TYPE:
|
Source code in aana/integrations/haystack/deployment_component.py
warm_up
¶
Warms up the deployment to a ready state.
As we run off an existing deployment handle, this is currently a no-op.
run
¶
Run the component. This is the primary interface for Haystack Components.
PARAMETER | DESCRIPTION |
---|---|
*args |
the arguments to pass to the deployment run function
DEFAULT:
|
**kwargs |
the keyword arguments to pass to the deployment run function
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
The return value of the deployment's run function |
Source code in aana/integrations/haystack/deployment_component.py
aana.integrations.external.av
¶
pyAVWrapper
¶
Bases: AbstractAudioLibrary
Class for audio handling using PyAV library.
read_file
¶
Read an audio file from path and return it as a numpy array.
PARAMETER | DESCRIPTION |
---|---|
path |
The path of the file to read.
TYPE:
|
sample_rate |
sample rate of the audio, default is 16000.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The audio file as a numpy array. |
Source code in aana/integrations/external/av.py
read_from_bytes
¶
Read audio bytes and return as a numpy array.
PARAMETER | DESCRIPTION |
---|---|
content |
The content of the file to read.
TYPE:
|
sample_rate |
sample rate of the audio, default is 16000.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The file as a numpy array. |
Source code in aana/integrations/external/av.py
write_file
¶
Write an audio file in wav format to the path from numpy array.
PARAMETER | DESCRIPTION |
---|---|
path |
The path of the file to write.
TYPE:
|
audio |
The audio to write.
TYPE:
|
sample_rate |
The sample rate of the audio to save, default is 16000.
TYPE:
|
Source code in aana/integrations/external/av.py
write_to_bytes
¶
Write bytes using the audio library from numpy array.
PARAMETER | DESCRIPTION |
---|---|
audio |
The audio to write.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The audio as bytes.
TYPE:
|
Source code in aana/integrations/external/av.py
write_audio_bytes
¶
Write an audio file in wav format to path from the normalized audio bytes.
PARAMETER | DESCRIPTION |
---|---|
path |
The path of the file to write.
TYPE:
|
audio |
The audio to in 16-bit PCM byte write.
TYPE:
|
sample_rate |
The sample rate of the audio, default is 16000.
TYPE:
|
Source code in aana/integrations/external/av.py
load_audio
¶
Open an audio file and read as mono waveform, resampling as necessary.
PARAMETER | DESCRIPTION |
---|---|
file |
The audio/video file to open.
TYPE:
|
sample_rate |
The sample rate to resample the audio if necessary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The content of the audio as bytes.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
if ffmpeg fails to convert and load the audio. |
Source code in aana/integrations/external/av.py
ignore_invalid_frames
¶
Filter out invalid frames from the input generator.
PARAMETER | DESCRIPTION |
---|---|
frames |
The input generator of frames.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
Generator
|
av.audio.frame.AudioFrame: Valid audio frames. |
RAISES | DESCRIPTION |
---|---|
StopIteration
|
When the input generator is exhausted. |
Source code in aana/integrations/external/av.py
group_frames
¶
Group audio frames and yield groups of frames based on the specified number of samples.
PARAMETER | DESCRIPTION |
---|---|
frames |
The input generator of audio frames.
TYPE:
|
num_samples |
The target number of samples for each group.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
Generator
|
av.audio.frame.AudioFrame: Grouped audio frames. |
Source code in aana/integrations/external/av.py
resample_frames
¶
Resample audio frames using the provided resampler.
PARAMETER | DESCRIPTION |
---|---|
frames |
The input generator of audio frames.
TYPE:
|
resampler |
The audio resampler.
|
YIELDS | DESCRIPTION |
---|---|
Generator
|
av.audio.frame.AudioFrame: Resampled audio frames. |
Source code in aana/integrations/external/av.py
aana.integrations.external.decord
¶
FramesDict
¶
Bases: TypedDict
Represents a set of frames with ids, timestamps and total duration.
ATTRIBUTE | DESCRIPTION |
---|---|
frames |
the extracted frames
TYPE:
|
timestamps |
the timestamps of the extracted frames
TYPE:
|
duration |
the total duration of the video
TYPE:
|
frame_ids |
the ids of the extracted frames
TYPE:
|
extract_frames
¶
Extract frames from a video using decord.
PARAMETER | DESCRIPTION |
---|---|
video |
the video to extract frames from
TYPE:
|
params |
the parameters of the video extraction
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
FramesDict
|
a dictionary containing the extracted frames, frame_ids, timestamps, and duration
TYPE:
|
Source code in aana/integrations/external/decord.py
get_video_duration
¶
Extract video duration using decord.
PARAMETER | DESCRIPTION |
---|---|
video |
the video to get its duration
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
duration of the video
TYPE:
|
RAISES | DESCRIPTION |
---|---|
VideoReadingException
|
if the file is not readable or a valid multimedia file |
Source code in aana/integrations/external/decord.py
generate_frames
¶
Generate frames from a video using decord.
PARAMETER | DESCRIPTION |
---|---|
video |
the video to extract frames from
TYPE:
|
params |
the parameters of the video extraction
TYPE:
|
batch_size |
the number of frames to yield at each iteration
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
FramesDict
|
a dictionary containing the extracted frames, frame ids, timestamps, and duration for each batch
TYPE::
|
Raises: VideoReadingException: if the file is not readable or a valid multimedia file
Source code in aana/integrations/external/decord.py
aana.integrations.external.opencv
¶
OpenCVWrapper
¶
Bases: AbstractImageLibrary
Wrapper class for OpenCV functions.
read_file
¶
Read a file using OpenCV.
PARAMETER | DESCRIPTION |
---|---|
path |
The path of the file to read.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The file as a numpy array in RGB format. |
Source code in aana/integrations/external/opencv.py
read_from_bytes
¶
Read bytes using OpenCV.
PARAMETER | DESCRIPTION |
---|---|
content |
The content of the file to read.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: The file as a numpy array in RGB format. |
Source code in aana/integrations/external/opencv.py
write_file
¶
Write a file using OpenCV.
PARAMETER | DESCRIPTION |
---|---|
path |
The path of the file to write.
TYPE:
|
img |
The image to write.
TYPE:
|
Source code in aana/integrations/external/opencv.py
write_to_bytes
¶
Write bytes using OpenCV.
PARAMETER | DESCRIPTION |
---|---|
img |
The image to write.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bytes
|
The image as bytes.
TYPE:
|
Source code in aana/integrations/external/opencv.py
aana.integrations.external.yt_dlp
¶
get_video_metadata
¶
Fetch video's metadata for a url.
PARAMETER | DESCRIPTION |
---|---|
video_url |
the video input url
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
metadata
|
the metadata of the video
TYPE:
|
RAISES | DESCRIPTION |
---|---|
DownloadException
|
Request does not succeed. |
Source code in aana/integrations/external/yt_dlp.py
download_video
¶
Downloads videos for a VideoInput object.
PARAMETER | DESCRIPTION |
---|---|
video_input |
the video input to download
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Video
|
the video object
TYPE:
|
RAISES | DESCRIPTION |
---|---|
DownloadException
|
Request does not succeed. |