| @@ -1,5 +1,6 @@ | |||||
| """ | """ | ||||
| # dora-rs | |||||
| # dora-rs. | |||||
| This is the dora python client for interacting with dora dataflow. | This is the dora python client for interacting with dora dataflow. | ||||
| You can install it via: | You can install it via: | ||||
| ```bash | ```bash | ||||
| @@ -28,8 +29,7 @@ from .dora import ( | |||||
| class DoraStatus(Enum): | class DoraStatus(Enum): | ||||
| """Dora status to indicate if operator `on_input` loop | |||||
| should be stopped. | |||||
| """Dora status to indicate if operator `on_input` loop should be stopped. | |||||
| Args: | Args: | ||||
| Enum (u8): Status signaling to dora operator to | Enum (u8): Status signaling to dora operator to | ||||
| @@ -16,6 +16,7 @@ class Enum: | |||||
| @typing.final | @typing.final | ||||
| class Node: | class Node: | ||||
| """The custom node API lets you integrate `dora` into your application. | """The custom node API lets you integrate `dora` into your application. | ||||
| It allows you to retrieve input and send output in any fashion you want. | It allows you to retrieve input and send output in any fashion you want. | ||||
| Use with: | Use with: | ||||
| @@ -28,7 +29,8 @@ class Node: | |||||
| """ | """ | ||||
| def __init__(self, node_id: str=None) -> None: | def __init__(self, node_id: str=None) -> None: | ||||
| """The custom node API lets you integrate `dora` into your application. | |||||
| """Use the custom node API to embed `dora` into your application. | |||||
| It allows you to retrieve input and send output in any fashion you want. | It allows you to retrieve input and send output in any fashion you want. | ||||
| Use with: | Use with: | ||||
| @@ -41,21 +43,23 @@ class Node: | |||||
| """ | """ | ||||
| def dataflow_descriptor(self) -> dict: | def dataflow_descriptor(self) -> dict: | ||||
| """Returns the full dataflow descriptor that this node is part of. | |||||
| """Return the full dataflow descriptor that this node is part of. | |||||
| This method returns the parsed dataflow YAML file. | This method returns the parsed dataflow YAML file. | ||||
| """ | """ | ||||
| def dataflow_id(self) -> str: | def dataflow_id(self) -> str: | ||||
| """Returns the dataflow id.""" | |||||
| """Return the dataflow id.""" | |||||
| def merge_external_events(self, subscription: dora.Ros2Subscription) -> None: | def merge_external_events(self, subscription: dora.Ros2Subscription) -> None: | ||||
| """Merge an external event stream with dora main loop. | """Merge an external event stream with dora main loop. | ||||
| This currently only work with ROS2. | This currently only work with ROS2. | ||||
| """ | """ | ||||
| def next(self, timeout: float=None) -> dict: | def next(self, timeout: float=None) -> dict: | ||||
| """`.next()` gives you the next input that the node has received. | """`.next()` gives you the next input that the node has received. | ||||
| It blocks until the next event becomes available. | It blocks until the next event becomes available. | ||||
| You can use timeout in seconds to return if no input is available. | You can use timeout in seconds to return if no input is available. | ||||
| It will return `None` when all senders has been dropped. | It will return `None` when all senders has been dropped. | ||||
| @@ -14,7 +14,7 @@ from pyarrow import cuda | |||||
| def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]: | def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]: | ||||
| """Converts a Pytorch tensor into a pyarrow buffer containing the IPC handle and its metadata. | |||||
| """Convert a Pytorch tensor into a pyarrow buffer containing the IPC handle and its metadata. | |||||
| Example Use: | Example Use: | ||||
| ```python | ```python | ||||
| @@ -35,7 +35,7 @@ def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]: | |||||
| def ipc_buffer_to_ipc_handle(handle_buffer: pa.array) -> cuda.IpcMemHandle: | def ipc_buffer_to_ipc_handle(handle_buffer: pa.array) -> cuda.IpcMemHandle: | ||||
| """Converts a buffer containing a serialized handler into cuda IPC MemHandle. | |||||
| """Convert a buffer containing a serialized handler into cuda IPC MemHandle. | |||||
| example use: | example use: | ||||
| ```python | ```python | ||||
| @@ -57,7 +57,7 @@ def ipc_buffer_to_ipc_handle(handle_buffer: pa.array) -> cuda.IpcMemHandle: | |||||
| def cudabuffer_to_numba(buffer: cuda.CudaBuffer, metadata: dict) -> DeviceNDArray: | def cudabuffer_to_numba(buffer: cuda.CudaBuffer, metadata: dict) -> DeviceNDArray: | ||||
| """Converts a pyarrow CUDA buffer to numba. | |||||
| """Convert a pyarrow CUDA buffer to numba. | |||||
| example use: | example use: | ||||
| ```python | ```python | ||||
| @@ -81,7 +81,7 @@ def cudabuffer_to_numba(buffer: cuda.CudaBuffer, metadata: dict) -> DeviceNDArra | |||||
| def cudabuffer_to_torch(buffer: cuda.CudaBuffer, metadata: dict) -> torch.Tensor: | def cudabuffer_to_torch(buffer: cuda.CudaBuffer, metadata: dict) -> torch.Tensor: | ||||
| """Converts a pyarrow CUDA buffer to a torch tensor. | |||||
| """Convert a pyarrow CUDA buffer to a torch tensor. | |||||
| example use: | example use: | ||||
| ```python | ```python | ||||
| @@ -7,14 +7,16 @@ class Operator: | |||||
| """Template docstring.""" | """Template docstring.""" | ||||
| def __init__(self): | def __init__(self): | ||||
| """Called on initialisation.""" | |||||
| """Perform initialization tasks.""" | |||||
| def on_event( | def on_event( | ||||
| self, | self, | ||||
| dora_event, | dora_event, | ||||
| send_output, | send_output, | ||||
| ) -> DoraStatus: | ) -> DoraStatus: | ||||
| """Args: | |||||
| """TODO :Description. | |||||
| Args: | |||||
| dora_event: Event containing an `id`, `data` and `metadata`. | dora_event: Event containing an `id`, `data` and `metadata`. | ||||
| send_output Callable[[str, bytes | pa.Array, Optional[dict]], None]: | send_output Callable[[str, bytes | pa.Array, Optional[dict]], None]: | ||||
| Function for sending output to the dataflow: | Function for sending output to the dataflow: | ||||
| @@ -38,4 +40,4 @@ class Operator: | |||||
| return DoraStatus.CONTINUE | return DoraStatus.CONTINUE | ||||
| def __del__(self): | def __del__(self): | ||||
| """Called before being deleted.""" | |||||
| """Perform actions before being deleted.""" | |||||
| @@ -66,7 +66,7 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME_OR_PATH, use_fast=True) | |||||
| def extract_python_code_blocks(text): | def extract_python_code_blocks(text): | ||||
| """Extracts Python code blocks from the given text that are enclosed in triple backticks with a python language identifier. | |||||
| """Extract Python code blocks from the given text that are enclosed in triple backticks with a python language identifier. | |||||
| Parameters | Parameters | ||||
| ---------- | ---------- | ||||
| @@ -90,7 +90,7 @@ def extract_python_code_blocks(text): | |||||
| def extract_json_code_blocks(text): | def extract_json_code_blocks(text): | ||||
| """Extracts json code blocks from the given text that are enclosed in triple backticks with a json language identifier. | |||||
| """Extract json code blocks from the given text that are enclosed in triple backticks with a json language identifier. | |||||
| Parameters | Parameters | ||||
| ---------- | ---------- | ||||
| @@ -113,7 +113,7 @@ def extract_json_code_blocks(text): | |||||
| def remove_last_line(python_code): | def remove_last_line(python_code): | ||||
| """Removes the last line from a given string of Python code. | |||||
| """Remove the last line from a given string of Python code. | |||||
| Parameters | Parameters | ||||
| ---------- | ---------- | ||||
| @@ -132,6 +132,7 @@ def remove_last_line(python_code): | |||||
| def calculate_similarity(source, target): | def calculate_similarity(source, target): | ||||
| """Calculate a similarity score between the source and target strings. | """Calculate a similarity score between the source and target strings. | ||||
| This uses the edit distance relative to the length of the strings. | This uses the edit distance relative to the length of the strings. | ||||
| """ | """ | ||||
| edit_distance = pylcs.edit_distance(source, target) | edit_distance = pylcs.edit_distance(source, target) | ||||
| @@ -142,9 +143,7 @@ def calculate_similarity(source, target): | |||||
| def find_best_match_location(source_code, target_block): | def find_best_match_location(source_code, target_block): | ||||
| """Find the best match for the target_block within the source_code by searching line by line, | |||||
| considering blocks of varying lengths. | |||||
| """ | |||||
| """Find the best match for the target_block within the source_code by searching line by line, considering blocks of varying lengths.""" | |||||
| source_lines = source_code.split("\n") | source_lines = source_code.split("\n") | ||||
| target_lines = target_block.split("\n") | target_lines = target_block.split("\n") | ||||
| @@ -47,7 +47,7 @@ def search(query_embedding, corpus_embeddings, paths, raw, k=5, file_extension=N | |||||
| class Operator: | class Operator: | ||||
| """ """ | |||||
| """TODO: Add docstring.""" | |||||
| def __init__(self): | def __init__(self): | ||||
| ## TODO: Add a initialisation step | ## TODO: Add a initialisation step | ||||
| @@ -13,7 +13,7 @@ IMAGE_RESIZE_RATIO = float(os.getenv("IMAGE_RESIZE_RATIO", "1.0")) | |||||
| def extract_bboxes(json_text): | def extract_bboxes(json_text): | ||||
| """Extracts bounding boxes from a JSON string with markdown markers and returns them as a NumPy array. | |||||
| """Extract bounding boxes from a JSON string with markdown markers and return them as a NumPy array. | |||||
| Parameters | Parameters | ||||
| ---------- | ---------- | ||||
| @@ -13,7 +13,7 @@ IMAGE_RESIZE_RATIO = float(os.getenv("IMAGE_RESIZE_RATIO", "1.0")) | |||||
| def extract_bboxes(json_text) -> (np.ndarray, np.ndarray): | def extract_bboxes(json_text) -> (np.ndarray, np.ndarray): | ||||
| """Extracts bounding boxes from a JSON string with markdown markers and returns them as a NumPy array. | |||||
| """Extract bounding boxes from a JSON string with markdown markers and return them as a NumPy array. | |||||
| Parameters | Parameters | ||||
| ---------- | ---------- | ||||
| @@ -82,7 +82,7 @@ stop = True | |||||
| def extract_bboxes(json_text) -> (np.ndarray, np.ndarray): | def extract_bboxes(json_text) -> (np.ndarray, np.ndarray): | ||||
| """Extracts bounding boxes from a JSON string with markdown markers and returns them as a NumPy array. | |||||
| """Extract bounding boxes from a JSON string with markdown markers and return them as a NumPy array. | |||||
| Parameters | Parameters | ||||
| ---------- | ---------- | ||||
| @@ -21,7 +21,7 @@ class DemoApp: | |||||
| self.stop = False | self.stop = False | ||||
| def on_new_frame(self): | def on_new_frame(self): | ||||
| """This method is called from non-main thread, therefore cannot be used for presenting UI.""" | |||||
| """on_new_frame method is called from non-main thread, therefore cannot be used for presenting UI.""" | |||||
| self.event.set() # Notify the main thread to stop waiting and process new frame. | self.event.set() # Notify the main thread to stop waiting and process new frame. | ||||
| def on_stream_stopped(self): | def on_stream_stopped(self): | ||||
| @@ -34,7 +34,7 @@ def play_audio( | |||||
| def main(): | def main(): | ||||
| """Main function for the node.""" | |||||
| """Run main function for the node.""" | |||||
| node = Node() | node = Node() | ||||
| stream = None | stream = None | ||||
| audio = np.array([]) | audio = np.array([]) | ||||