From 18fe647d05ec366d2ea3ab8c38306b37167cc10c Mon Sep 17 00:00:00 2001 From: Philipp Schmid Date: Tue, 2 Aug 2022 08:05:48 +0000 Subject: [PATCH 1/2] remove /predict route --- README.md | 2 +- src/huggingface_inference_toolkit/webservice_starlette.py | 3 ++- tests/integ/test_container.py | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 13de25fa..69c9fd6d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ docker run -ti -p 5000:5000 -e HF_MODEL_ID=distilbert-base-uncased-distilled-squ ```bash curl --request POST \ - --url http://localhost:5000/predict \ + --url http://localhost:5000 \ --header 'Content-Type: application/json' \ --data '{ "inputs": { diff --git a/src/huggingface_inference_toolkit/webservice_starlette.py b/src/huggingface_inference_toolkit/webservice_starlette.py index 4535edb4..f9e8cfc6 100644 --- a/src/huggingface_inference_toolkit/webservice_starlette.py +++ b/src/huggingface_inference_toolkit/webservice_starlette.py @@ -73,7 +73,7 @@ async def predict(request): pred = inference_handler(deserialized_body) # log request time # TODO: repalce with middleware - logger.info(f"POST /predict | Duration: {(perf_counter()-start_time) *1000:.2f} ms") + logger.info(f"POST {request.url.path} | Duration: {(perf_counter()-start_time) *1000:.2f} ms") # deserialized and resonds with json return Response(Jsoner.serialize(pred)) except Exception as e: @@ -86,6 +86,7 @@ async def predict(request): routes=[ Route("/", health, methods=["GET"]), Route("/health", health, methods=["GET"]), + Route("/", predict, methods=["POST"]), Route("/predict", predict, methods=["POST"]), ], on_startup=[some_startup_task], diff --git a/tests/integ/test_container.py b/tests/integ/test_container.py index 30ece53d..46061120 100644 --- a/tests/integ/test_container.py +++ b/tests/integ/test_container.py @@ -49,14 +49,14 @@ def verify_task(container: DockerClient, task: str, port: int = 5000, framework: or task == "zero-shot-image-classification" ): prediction = requests.post( - f"{BASE_URL}/predict", data=task2input[task], headers={"content-type": "image/x-image"} + f"{BASE_URL}", data=task2input[task], headers={"content-type": "image/x-image"} ).json() elif task == "automatic-speech-recognition" or task == "audio-classification": prediction = requests.post( - f"{BASE_URL}/predict", data=task2input[task], headers={"content-type": "audio/x-audio"} + f"{BASE_URL}", data=task2input[task], headers={"content-type": "audio/x-audio"} ).json() else: - prediction = requests.post(f"{BASE_URL}/predict", json=input).json() + prediction = requests.post(f"{BASE_URL}", json=input).json() assert task2validation[task](result=prediction, snapshot=task2output[task]) is True @@ -193,7 +193,7 @@ def test_cpu_container_custom_pipeline(repository_id) -> None: BASE_URL = "http://localhost:5000" wait_for_container_to_be_ready(BASE_URL) payload = {"inputs": "this is a test"} - prediction = requests.post(f"{BASE_URL}/predict", json=payload).json() + prediction = requests.post(f"{BASE_URL}", json=payload).json() assert prediction == payload # time.sleep(5) container.stop() From 1e099ca754353963ccf460ae56ac0ba2ee1a9985 Mon Sep 17 00:00:00 2001 From: Philipp Schmid Date: Tue, 2 Aug 2022 08:08:15 +0000 Subject: [PATCH 2/2] added condition from iamges build --- .github/workflows/build-container.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-container.yaml b/.github/workflows/build-container.yaml index 34ad186d..24159c11 100644 --- a/.github/workflows/build-container.yaml +++ b/.github/workflows/build-container.yaml @@ -2,8 +2,11 @@ name: "Build applications images" on: push: - # paths: - # - "app/**" + branches: + - main + paths: + - "src/**" + - "dockerfiles/**" workflow_dispatch: concurrency: