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.

file_saver_op.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import pyarrow as pa
  2. from dora import DoraStatus
  3. class Operator:
  4. """
  5. Infering object from images
  6. """
  7. def __init__(self):
  8. self.last_file = ""
  9. self.last_path = ""
  10. self.last_netadata = None
  11. def on_event(
  12. self,
  13. dora_event,
  14. send_output,
  15. ) -> DoraStatus:
  16. if dora_event["type"] == "INPUT" and dora_event["id"] == "file":
  17. input = dora_event["value"][0].as_py()
  18. with open(input["path"], "r") as file:
  19. self.last_file = file.read()
  20. self.last_path = input["path"]
  21. self.last_metadata = dora_event["metadata"]
  22. with open(input["path"], "w") as file:
  23. file.write(input["raw"])
  24. send_output(
  25. "saved_file",
  26. pa.array(
  27. [
  28. {
  29. "raw": input["raw"],
  30. "path": input["path"],
  31. "origin": dora_event["id"],
  32. }
  33. ]
  34. ),
  35. dora_event["metadata"],
  36. )
  37. return DoraStatus.CONTINUE