Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding additional node in the node-hub #620

Merged
merged 19 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions .github/workflows/node-hub-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,8 @@ jobs:

- name: Run Linting and Tests
run: |
for dir in node-hub/*/ ; do
if [ -d "$dir" ]; then
if [ -f "$dir/pyproject.toml" ]; then
echo "Running linting and tests for Python project in $dir..."
(cd "$dir" && pip install .)
(cd "$dir" && poetry run black --check .)
(cd "$dir" && poetry run pylint --disable=C,R --ignored-modules=cv2 **/*.py)
(cd "$dir" && poetry run pytest)
fi

if [ -f "$dir/Cargo.toml" ]; then
echo "Running build and tests for Rust project in $dir..."
(cd "$dir" && cargo build)
(cd "$dir" && cargo test)
fi
fi
done
chmod +x .github/workflows/node_hub_test.sh
.github/workflows/node_hub_test.sh

publish:
needs: [ci]
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/node_hub_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -euo

for dir in node-hub/*/ ; do
if [ -d "$dir" ]; then
if [ -f "$dir/pyproject.toml" ]; then
echo "Running linting and tests for Python project in $dir..."
(cd "$dir" && pip install .)
(cd "$dir" && poetry run black --check .)
(cd "$dir" && poetry run pylint --disable=C,R --ignored-modules=cv2 **/*.py)
(cd "$dir" && poetry run pytest)
fi

if [ -f "$dir/Cargo.toml" ]; then
echo "Running build and tests for Rust project in $dir..."
(cd "$dir" && cargo build)
(cd "$dir" && cargo test)
fi
fi
done
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ examples/**/*.txt

# Removing images.
*.jpg
*.mp3
*.wav
*.png
!docs/src/latency.png

Expand Down
12 changes: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ members = [
"libraries/extensions/telemetry/*",
"node-hub/dora-record",
"node-hub/dora-rerun",
"node-hub/terminal-print",
"libraries/extensions/ros2-bridge",
"libraries/extensions/ros2-bridge/msg-gen",
"libraries/extensions/ros2-bridge/python",
Expand Down
1 change: 1 addition & 0 deletions examples/echo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pt
12 changes: 12 additions & 0 deletions examples/echo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dora echo example

Make sure to have, dora, pip and cargo installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml

# In another terminal
terminal-input
```
22 changes: 22 additions & 0 deletions examples/echo/dataflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
nodes:
- id: terminal-input
build: pip install -e ../../node-hub/terminal-input
path: dynamic
outputs:
- data
inputs:
echo: dora-echo/echo

- id: dora-echo
build: pip install -e ../../node-hub/dora-echo
path: dora-echo
inputs:
input: terminal-input/data
outputs:
- echo

- id: terminal-print
build: cargo build -p terminal-print
path: dynamic
inputs:
echo: dora-echo/echo
1 change: 1 addition & 0 deletions examples/pyarrow-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pt
9 changes: 9 additions & 0 deletions examples/pyarrow-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Dora echo example

Make sure to have, dora, pip and cargo installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml
```
16 changes: 16 additions & 0 deletions examples/pyarrow-test/dataflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
nodes:
- id: pyarrow-sender
build: pip install -e ../../node-hub/pyarrow-sender
path: dynamic
outputs:
- data
env:
DATA: "[1, 2, 3, 4, 5]"

- id: pyarrow-assert
build: pip install -e ../../node-hub/pyarrow-assert
path: pyarrow-assert
inputs:
data: pyarrow-sender/data
env:
DATA: "pa.array([1, 2, 3, 4, 5])"
1 change: 1 addition & 0 deletions examples/speech-to-text/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pt
12 changes: 12 additions & 0 deletions examples/speech-to-text/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dora echo example

Make sure to have, dora, pip and cargo installed.

```bash
dora up
dora build dataflow.yml
dora start dataflow.yml

# In another terminal
terminal-print
```
20 changes: 20 additions & 0 deletions examples/speech-to-text/dataflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
nodes:
- id: dora-microphone
build: pip install -e ../../node-hub/dora-microphone
path: dora-microphone
outputs:
- audio

- id: dora-distil-whisper
build: pip install -e ../../node-hub/dora-distil-whisper
path: dora-distil-whisper
inputs:
input: dora-microphone/audio
outputs:
- text

- id: terminal-print
build: cargo build -p terminal-print
path: dynamic
inputs:
text: dora-distil-whisper/text
3 changes: 3 additions & 0 deletions node-hub/dora-distil-whisper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dora Node for transforming speech to text (English only)

Check example at [examples/speech-to-text](examples/speech-to-text)
11 changes: 11 additions & 0 deletions node-hub/dora-distil-whisper/dora_distil_whisper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
42 changes: 42 additions & 0 deletions node-hub/dora-distil-whisper/dora_distil_whisper/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from dora import Node
import pyarrow as pa
import os

os.environ["TRANSFORMERS_OFFLINE"] = "1"

device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32

model_id = "distil-whisper/distil-large-v3"

model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
use_safetensors=True,
local_files_only=True,
)
model.to(device)

processor = AutoProcessor.from_pretrained(model_id)
pipe = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
feature_extractor=processor.feature_extractor,
max_new_tokens=128,
torch_dtype=torch_dtype,
device=device,
generate_kwargs={"language": "chinese"},
)


def main():
node = Node()
for event in node:
if event["type"] == "INPUT":
audio = event["value"].to_numpy()
result = pipe(audio)
node.send_output("text", pa.array([result["text"]]))
31 changes: 31 additions & 0 deletions node-hub/dora-distil-whisper/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[tool.poetry]
name = "dora-distil-whisper"
version = "0.3.5"
authors = [
"Haixuan Xavier Tao <[email protected]>",
"Enzo Le Van <[email protected]>",
]
description = "Dora dora-distil-whisper"
license = "MIT License"
homepage = "https://github.com/dora-rs/dora.git"
documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/dora-distil-whisper/README.md"
readme = "README.md"
packages = [{ include = "dora_distil_whisper" }]

[tool.poetry.dependencies]
dora-rs = "0.3.5"
numpy = "< 2.0.0"
pyarrow = ">= 5.0.0"
transformers = ">= 4.0.0"
accelerate = "^0.29.2"
torch = "^2.1.1"

[tool.poetry.scripts]
dora-distil-whisper = "dora_distil_whisper.main:main"

[build-system]
requires = ["poetry-core>=1.8.0"]
build-backend = "poetry.core.masonry.api"

[project]
readme = "README.md"
2 changes: 2 additions & 0 deletions node-hub/dora-distil-whisper/tests/test_placeholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_placeholder():
pass
5 changes: 5 additions & 0 deletions node-hub/dora-echo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dora echo node

This node will just echo whatever it receives as is.

Check example at [examples/echo](examples/echo)
11 changes: 11 additions & 0 deletions node-hub/dora-echo/dora_echo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
32 changes: 32 additions & 0 deletions node-hub/dora-echo/dora_echo/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import argparse
import os
from dora import Node

RUNNER_CI = True if os.getenv("CI") == "true" else False


def main():

# Handle dynamic nodes, ask for the name of the node in the dataflow, and the same values as the ENV variables.
parser = argparse.ArgumentParser(description="Simple arrow sender")

parser.add_argument(
"--name",
type=str,
required=False,
help="The name of the node in the dataflow.",
default="echo",
)
args = parser.parse_args()

node = Node(
args.name
) # provide the name to connect to the dataflow if dynamic node

for event in node:
if event["type"] == "INPUT":
node.send_output("echo", event["value"])


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions node-hub/dora-echo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[tool.poetry]
name = "dora-echo"
version = "0.3.5"
authors = [
"Haixuan Xavier Tao <[email protected]>",
"Enzo Le Van <[email protected]>",
]
description = "Dora echo"
license = "MIT License"
homepage = "https://github.com/dora-rs/dora.git"
documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/dora-echo/README.md"
readme = "README.md"
packages = [{ include = "dora_echo" }]

[tool.poetry.dependencies]
dora-rs = "0.3.5"
numpy = "< 2.0.0"
pyarrow = ">= 5.0.0"

[tool.poetry.scripts]
dora-echo = "dora_echo.main:main"

[build-system]
requires = ["poetry-core>=1.8.0"]
build-backend = "poetry.core.masonry.api"

[project]
readme = "README.md"
2 changes: 2 additions & 0 deletions node-hub/dora-echo/tests/test_placeholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_placeholder():
pass
3 changes: 3 additions & 0 deletions node-hub/dora-keyboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dora Node for listening to keyboard input.

Send char only in the `char` output stream, as string, on press.
11 changes: 11 additions & 0 deletions node-hub/dora-keyboard/dora_keyboard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
Loading
Loading