Hi all. I'm making an inference deployment. The in...
# ask-community
k
Hi all. I'm making an inference deployment. The inference code is imported from another directory using PYTHONPATH Running flow locally works perfectly. But creating a deployment for it and running it fails due to the package from another directory is missing. What should I do to fix it?
Copy code
import time
import asyncio
from prefect import flow, task
from prefect.artifacts import create_table_artifact
from prefect.deployments import DeploymentImage

from bmt.court.run import execute as detect_court_inference


@task(log_prints=True)
def detect_court_task(file_path: str, format: str, player_class: str):
    time.sleep(3)

    request = {'file_path': 'aicoach/bmt/assets/videos/demo.mp4',
               'format': 'MS',
               'class': 'SL3'}
    args = {
        "use_yolo": True,
        "show_image": False,
        "save_image": False,
    }
    result = detect_court_inference(request, args)

    return result


@flow(persist_result=True, result_serializer="json", cache_result_in_memory=True, log_prints=True)
async def detect_court(file_path: str = "", format: str = "", player_class: str = ""):

    task = detect_court_task.submit(file_path, format, player_class)

    result = task.result()

    await create_table_artifact(table=[result], key="detect-court",
                                description="Detect court in video")

    return result


if __name__ == "__main__":
    # asyncio.run(detect_court()) # It works fine
    detect_court.deploy(
        name="detect-court",
        work_pool_name="default",
        push=False,
        image=DeploymentImage(
            name="detect-court",
        ))
n
hi @KyuWoo Choi ! where are you trying to run your code? is it in a containerized environment like docker / k8s / ECS or is it just as a process someplace?
k
in docker container :)
found it was not because the PYTHONPATH, but symbolic link dirs.
how to force prefect to include dirs & dependent packages when It build docker container? I found some pip deps are missing when I run the code in the container.
n
hi @KyuWoo Choi - how are you including your code in your image?
DeploymentImage
accepts a
dockerfile
kwarg that points to your
Dockerfile
k
I'm using the simple code below
Copy code
detect_court.deploy(
        name="detect-court",
        work_pool_name="default",
        push=False,
        image=DeploymentImage(
            name="detect-court",
        ))
So. Better build custom container image in my case? Can you link the base container Image Dockerfile which prefect use and I can start from?
Oh. It seems like the doc here. https://docs.prefect.io/latest/guides/docker/ Thankks.