You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # Python Dataflow Example
  2. This examples shows how to create and connect dora operators and custom nodes in Python.
  3. ## Overview
  4. The [`dataflow.yml`](./dataflow.yml) defines a simple dataflow graph with the following three nodes:
  5. - a webcam node, that connects to your webcam and feed the dataflow with webcam frame as jpeg compressed bytearray.
  6. - an object detection node, that apply Yolo v5 on the webcam image. The model is imported from Pytorch Hub. The output is the bouding box of each object detected, the confidence and the class. You can have more info here: https://pytorch.org/hub/ultralytics_yolov5/
  7. - a window plotting node, that will retrieve the webcam image and the Yolov5 bounding box and join the two together.
  8. ## Getting started
  9. ```bash
  10. cargo run --example python-operator-dataflow
  11. ```
  12. ## Installation
  13. ```bash
  14. conda create -n example_env python=3.12
  15. pip install -r requirements.txt
  16. ```
  17. ## Run the dataflow
  18. - Start the object detection dataflow alone:
  19. ```bash
  20. dora start dataflow.yml
  21. ```
  22. - Start the llm dataflow:
  23. ```bash
  24. dora start dataflow_llm.yml
  25. ```
  26. Within the window you can ask question such as:
  27. ```bash
  28. ask how are you
  29. change bounding box plot to red
  30. change confidence value to percentage
  31. change object detection to only detect person
  32. send 200 200 200 400 to topic line
  33. record
  34. ```
  35. ```bash
  36. wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/keyboard_op.py
  37. wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/microphone_op.py
  38. wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/whisper_op.py
  39. wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/sentence_transformers_op.py
  40. wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/llm_op.py
  41. wget https://raw.githubusercontent.com/dora-rs/dora/v0.3.2/examples/python-operator-dataflow/file_saver_op.py
  42. ```
  43. and adding the following to the dataflow configuration:
  44. ```yaml
  45. nodes:
  46. - id: webcam
  47. operator:
  48. python: webcam.py
  49. inputs:
  50. tick: dora/timer/millis/50
  51. outputs:
  52. - image
  53. - id: object_detection
  54. operator:
  55. python: object_detection.py
  56. inputs:
  57. image: webcam/image
  58. outputs:
  59. - bbox
  60. - id: plot
  61. operator:
  62. python: plot.py
  63. inputs:
  64. image: webcam/image
  65. bbox: object_detection/bbox
  66. line: llm/line
  67. keyboard_buffer: keyboard/buffer
  68. user_message: keyboard/submitted
  69. assistant_message: llm/assistant_message
  70. ## Speech to text
  71. - id: keyboard
  72. custom:
  73. source: keyboard_op.py
  74. outputs:
  75. - buffer
  76. - submitted
  77. - record
  78. - ask
  79. - send
  80. - change
  81. inputs:
  82. recording: whisper/text
  83. - id: microphone
  84. operator:
  85. python: microphone_op.py
  86. inputs:
  87. record: keyboard/record
  88. outputs:
  89. - audio
  90. - id: whisper
  91. operator:
  92. python: whisper_op.py
  93. inputs:
  94. audio: microphone/audio
  95. outputs:
  96. - text
  97. ## Code Modifier
  98. - id: vectordb
  99. operator:
  100. python: sentence_transformers_op.py
  101. inputs:
  102. query: keyboard/change
  103. saved_file: file_saver/saved_file
  104. outputs:
  105. - raw_file
  106. - id: llm
  107. operator:
  108. python: llm_op.py
  109. inputs:
  110. code_modifier: vectordb/raw_file
  111. assistant: keyboard/ask
  112. message_sender: keyboard/send
  113. outputs:
  114. - modified_file
  115. - line
  116. - assistant_message
  117. - id: file_saver
  118. operator:
  119. python: file_saver_op.py
  120. inputs:
  121. file: llm/modified_file
  122. outputs:
  123. - saved_file
  124. ```
  125. 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.
  126. 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.
  127. The end result is then saved using the file saver