Skip to content

Commit

Permalink
Fix added operator
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Apr 2, 2024
1 parent e27a887 commit c382aa5
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 186 deletions.
135 changes: 129 additions & 6 deletions examples/python-operator-dataflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,144 @@ The [`dataflow.yml`](./dataflow.yml) defines a simple dataflow graph with the fo
## Getting started

```bash
cargo run --example python-dataflow
cargo run --example python-operator-dataflow
```

## Installation

To install, you should run the `install.sh` script.
```bash
conda create -n example_env python=3.12
pip install -r requirements.txt
```

## Run the dataflow

- Start the object detection dataflow alone:

```bash
dora start dataflow.yml
```

- Start the llm dataflow:

```bash
install.sh
dora start dataflow_llm.yml
```

## Run the dataflow as a standalone
Within the window you can ask question such as:

- Start the `dora-coordinator`:
```bash
ask how are you
change bounding box plot to red
change confidence value to percentage
change object detection to only detect person
send 200 200 200 400 to topic line
record
```

```bash
wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/keyboard_op.py
wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/microphone_op.py
wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/whisper_op.py
wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/sentence_transformers_op.py
wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/llm_op.py
wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/file_saver_op.py
```
../../target/release/dora-daemon --run-dataflow dataflow.yml

and adding the following to the dataflow configuration:

```yaml
nodes:
- id: webcam
operator:
python: webcam.py
inputs:
tick: dora/timer/millis/50
outputs:
- image

- id: object_detection
operator:
python: object_detection.py
inputs:
image: webcam/image
outputs:
- bbox

- id: plot
operator:
python: plot.py
inputs:
image: webcam/image
bbox: object_detection/bbox
line: llm/line
keyboard_buffer: keyboard/buffer
user_message: keyboard/submitted
assistant_message: llm/assistant_message

## Speech to text
- id: keyboard
custom:
source: keyboard_op.py
outputs:
- buffer
- submitted
- record
- ask
- send
- change
inputs:
recording: whisper/text

- id: microphone
operator:
python: microphone_op.py
inputs:
record: keyboard/record
outputs:
- audio

- id: whisper
operator:
python: whisper_op.py
inputs:
audio: microphone/audio
outputs:
- text

## Code Modifier
- id: vectordb
operator:
python: sentence_transformers_op.py
inputs:
query: keyboard/change
saved_file: file_saver/saved_file
outputs:
- raw_file

- id: llm
operator:
python: llm_op.py
inputs:
code_modifier: vectordb/raw_file
assistant: keyboard/ask
message_sender: keyboard/send
outputs:
- modified_file
- line
- assistant_message

- id: file_saver
operator:
python: file_saver_op.py
inputs:
file: llm/modified_file
outputs:
- saved_file
```
The keyboard, microphone, whisper node, works in a very similar fashion as the object detection dataflow and I'll let you check it out by yourself.
The code modification flow works by first comparing an instruction with a vectordb of operators source code and then feeding the most similar operator to an llm with the instruction for code modification.
The end result is then saved using the file saver
3 changes: 3 additions & 0 deletions examples/python-operator-dataflow/dataflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ nodes:

- id: object_detection
operator:
send_stdout_as: stdout
python: object_detection.py
inputs:
image: webcam/image
outputs:
- bbox
- stdout

- id: plot
operator:
python: plot.py
inputs:
image: webcam/image
bbox: object_detection/bbox
assistant_message: object_detection/stdout
18 changes: 18 additions & 0 deletions examples/python-operator-dataflow/dataflow_llm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ nodes:
- ask
- send
- change
inputs:
recording: whisper/text

- id: microphone
operator:
python: microphone_op.py
inputs:
record: keyboard/record
outputs:
- audio

- id: whisper
operator:
python: whisper_op.py
inputs:
audio: microphone/audio
outputs:
- text

## Code Modifier
- id: vectordb
Expand Down
87 changes: 0 additions & 87 deletions examples/python-operator-dataflow/dataflow_record.yml

This file was deleted.

33 changes: 2 additions & 31 deletions examples/python-operator-dataflow/keyboard_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from pynput.keyboard import Key, Events
import pyarrow as pa
from dora import Node
from tkinter import Tk
import tkinter as tk


node = Node()
Expand All @@ -30,35 +28,8 @@
if event is not None and isinstance(event, Events.Press):
if hasattr(event.key, "char"):
cursor = 0
if ctrl and event.key.char == "v":
r = Tk()
r.update()
try:
selection = r.clipboard_get()
r.withdraw()
r.update()
except tk.TclError:
selection = ""
r.destroy()
buffer_text += selection
node.send_output("buffer", pa.array([buffer_text]))
elif ctrl and event.key.char == "c":
r = Tk()
r.clipboard_clear()
r.clipboard_append(buffer_text)
r.update()
r.destroy()
elif ctrl and event.key.char == "x":
r = Tk()
r.clipboard_clear()
r.clipboard_append(buffer_text)
r.update()
r.destroy()
buffer_text = ""
node.send_output("buffer", pa.array([buffer_text]))
else:
buffer_text += event.key.char
node.send_output("buffer", pa.array([buffer_text]))
buffer_text += event.key.char
node.send_output("buffer", pa.array([buffer_text]))
else:
if event.key == Key.backspace:
buffer_text = buffer_text[:-1]
Expand Down
Loading

0 comments on commit c382aa5

Please sign in to comment.