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.3 kB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """TODO: Add docstring."""
  2. import pyarrow as pa
  3. from dora import DoraStatus
  4. class Operator:
  5. """Inferring object from images."""
  6. def __init__(self):
  7. """TODO: Add docstring."""
  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. """TODO: Add docstring."""
  17. if dora_event["type"] == "INPUT" and dora_event["id"] == "file":
  18. input = dora_event["value"][0].as_py()
  19. with open(input["path"]) as file:
  20. self.last_file = file.read()
  21. self.last_path = input["path"]
  22. self.last_metadata = dora_event["metadata"]
  23. with open(input["path"], "w") as file:
  24. file.write(input["raw"])
  25. send_output(
  26. "saved_file",
  27. pa.array(
  28. [
  29. {
  30. "raw": input["raw"],
  31. "path": input["path"],
  32. "origin": dora_event["id"],
  33. },
  34. ],
  35. ),
  36. dora_event["metadata"],
  37. )
  38. return DoraStatus.CONTINUE