Advertisement
Guest User

Untitled

a guest
May 7th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. from pathlib import Path
  2.  
  3. from flytekit import workflow, task, FlyteFile, ContainerTask, kwtypes
  4. import logging
  5.  
  6. logging.basicConfig(level=logging.INFO)
  7.  
  8. translate = ContainerTask(
  9.     name="Translate",
  10.     image="ubuntu:latest",
  11.     input_data_dir="/var/inputs",
  12.     output_data_dir="/var/outputs",
  13.     inputs=kwtypes(input_file=FlyteFile),
  14.     outputs=kwtypes(output_file=FlyteFile),
  15.     command=["/bin/sh", "-c", "cat /var/inputs/input_file | sed -r 's/Hello/Goodbye/g' > /var/outputs/result"],
  16. )
  17.  
  18.  
  19. @task
  20. def read_file() -> FlyteFile:
  21.     return FlyteFile(
  22.         path=Path('hello_world.txt'))
  23.  
  24.  
  25. @task
  26. def translate_file(data: FlyteFile) -> FlyteFile:
  27.     with open(data, 'r') as f:
  28.         logging.info(f'Input: {f.read()}')
  29.  
  30.     out = translate(input_file=data)
  31.     return out,
  32.  
  33.  
  34. @task
  35. def log_result(data: FlyteFile) -> None:
  36.     with open(data, 'r') as f:
  37.         result = f.read()
  38.  
  39.     logging.info(f'Result: {result}')
  40.  
  41.  
  42. @workflow
  43. def main():
  44.     file = read_file()
  45.     outcome = translate_file(file)
  46.     log_result(outcome.out_file)
  47.  
  48.  
  49. if __name__ == "__main__":
  50.     main()
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement