forked from dora-rs/dora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_saver_op.py
44 lines (37 loc) · 1.16 KB
/
file_saver_op.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pyarrow as pa
from dora import DoraStatus
class Operator:
"""
Inferring object from images
"""
def __init__(self):
self.last_file = ""
self.last_path = ""
self.last_netadata = None
def on_event(
self,
dora_event,
send_output,
) -> DoraStatus:
if dora_event["type"] == "INPUT" and dora_event["id"] == "file":
input = dora_event["value"][0].as_py()
with open(input["path"], "r") as file:
self.last_file = file.read()
self.last_path = input["path"]
self.last_metadata = dora_event["metadata"]
with open(input["path"], "w") as file:
file.write(input["raw"])
send_output(
"saved_file",
pa.array(
[
{
"raw": input["raw"],
"path": input["path"],
"origin": dora_event["id"],
}
]
),
dora_event["metadata"],
)
return DoraStatus.CONTINUE