<jupyter_start><jupyter_text>Demo: Remote iteration with an OpenCV Script, using an open source OpenCV ImageWe are using the filter_edges method that is available in the adjoining module - image.py> filter_edges  Step I: Run the filter_edges example within Jupyter Notebook First<jupyter_code>from image import filter_edges
inp = "image.jpg" # This should be a path to an image that is available locally 
out = "edges.png" # This is the path to where we want to create the image
filter_edges(inp, out)
# Invoke the helper method that displays the image in Jupyter
display_images([inp, out])<jupyter_output><empty_output><jupyter_text>Step II: Create a Flyte Task for this functionIn this case we will use an SdkRawContainerTask. A raw container task is essentially a container task, where we tell Flyte, that this container does not have flytekit. So all the inputs and outputs should be auto-mounted and uploaded.The task can use an open source container `docker.io/jjanzic/docker-python3-opencv`. This container has python and OpenCV already installed. Hot load the codeIf you notice the edges task accepts 2 inputs"image": the image to be converted"script": the script to execute. It is assumed the script to be executed is available in some bucket (s3) that is accessible by your Flyte task. CommandThe most important part is the command```python["python", "/inputs/script", "/inputs/image", "/outputs/edges"],```the command is just running python and the passed in script. Note the input name and output nameThe input name is the name of the "input variable". If this was a list of images, then this would be a directory.The output is also the name of the "output variable"The names are extremely important, as Flyte will only download the image locally to a file that has the name that matches the variable name. Also it will upload a file whose name matches the output variable name. The extension of the file does not matter.<jupyter_code>from flytekit.common.tasks.raw_container import SdkRawContainerTask
from flytekit.sdk.types import Types

edges = SdkRawContainerTask(
    input_data_dir="/inputs",
    output_data_dir="/outputs",
    inputs={"image": Types.Blob, "script": Types.Blob},
    outputs={"edges": Types.Blob},
    image="docker.io/jjanzic/docker-python3-opencv",
    command=["python", "/inputs/script", "/inputs/image", "/outputs/edges"],
)<jupyter_output><empty_output><jupyter_text>Step IIIa: Just for this excerciseTo make the dynamic loading of the script work, we have to **upload the script to some s3 bucket**. Since we are testing this locally, I have originally created an s3 client that points to Flyte installed minio. Upload the code there too<jupyter_code>script_path="s3://my-s3-bucket/code/image.py"
upload_file("image.py", script_path)
example_image="https://www.naturephotographysimplified.com/wp-content/uploads/2019/06/How-to-get-sharp-images-Birds-in-flight-Bharatpur-Bird-Sanctuary-bird-Photography-by-Prathap-DK-bronze-winged-jacana-Greater-Spotted-Eagle-750x500.jpg"<jupyter_output><empty_output><jupyter_text>Step III: Launch an execution for the taskThis creates an execution of just the task. Remember in Flyte, Task is a standalone top level entity, so you can execute it<jupyter_code>exc = edges.register_and_launch("flyteexamples", "development", inputs={"image":example_image, "script":script_path})

print_console_url(exc)

exc.wait_for_completion()
#exc.outputs
# Outputs are not working with Minio<jupyter_output><empty_output><jupyter_text>Step IV: Optional. Create a WorkflowOfcourse you can use this task in a workflow. We are creating a trivial workflow in this case that has only one task<jupyter_code>from flytekit.sdk.workflow import workflow_class, Input, Output
@workflow_class
class EdgeDetector(object):
    script = Input(Types.Blob)
    image = Input(Types.Blob)
    edge_task = edges(script=script, image=image)
    out =  Output(edge_task.outputs.edges, sdk_type=Types.Blob)

EdgeDetector_lp = EdgeDetector.create_launch_plan()<jupyter_output><empty_output><jupyter_text>Step V: Optional. Register and execute the workflowTo make the dynamic loading of the script work, we have to upload the script to some s3 bucket. Since we are testing this locally, I have originally created an s3 client that points to Flyte installed minio. Upload the code there too```pythons3.Bucket('my-s3-bucket').upload_file('image.py','code/image.py')```<jupyter_code>edges.register(name="EdgeDetectorFunc", project="flyteexamples", domain="development", version="5")
EdgeDetector.register(name="EdgeDetector", project="flyteexamples", domain="development", version="5")
EdgeDetector_lp.register(name="EdgeDetector", project="flyteexamples", domain="development", version="5")
exc = EdgeDetector_lp.execute("flyteexamples", "development", inputs={"image":example_image, "script":script_path})
print_console_url(exc)<jupyter_output><empty_output><jupyter_text>Step VI: Visualize the resultsYou can retrieve the results and visualize them here<jupyter_code>key="/gn/ff554920363ff4da1903-edge-task-0/edges"
s3.Bucket('my-s3-bucket').download_file(key,'edges.png')
display_images(["edges.png"])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09377416860015468, 'fraction_numerical': 0.008507347254447023, 'mean_word_length': 6.12534435261708, 'pattern_counts': {'":': 9, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '67023', 'license': 'Apache-2.0', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1490, 'n_words': 531, 'path': 'sample-notebooks/raw-container.ipynb', 'repo_name': 'evalsocket/flytekit', 'size': '5172'}