diff --git a/README.md b/README.md index 852be949..75080871 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ -Hugging Face Inference Toolkit is for serving 🤗 Transformers models in containers. This library provides default pre-processing, predict and postprocessing for Transformers, Sentence Tranfsformers. It is also possible to define custom `pipeline.py` for customization. The Toolkit is build to work with the [Hugging Face Hub](https://huggingface.co/models). +Hugging Face Inference Toolkit is for serving 🤗 Transformers models in containers. This library provides default pre-processing, predict and postprocessing for Transformers, Sentence Tranfsformers. It is also possible to define custom `handler.py` for customization. The Toolkit is build to work with the [Hugging Face Hub](https://huggingface.co/models). --- ## 💻 Getting Started with Hugging Face Inference Toolkit @@ -124,24 +124,24 @@ HF_ENDPOINT="True" --- -## 🧑🏻‍💻 Custom Pipeline and dependency support +## 🧑🏻‍💻 Custom Handler and dependency support -The Hugging Face Inference Toolkit allows user to provide a custom inference through a `pipeline.py` file which is located in the repository. +The Hugging Face Inference Toolkit allows user to provide a custom inference through a `handler.py` file which is located in the repository. For an example check [https://huggingface.co/philschmid/custom-pipeline-text-classification](https://huggingface.co/philschmid/custom-pipeline-text-classification): ```bash model.tar.gz/ |- pytorch_model.bin |- .... -|- pipeline.py +|- handler.py |- requirements.txt ``` -In this example, `pytroch_model.bin` is the model file saved from training, `pipeline.py` is the custom inference pipeline, and `requirements.txt` is a requirements file to add additional dependencies. +In this example, `pytroch_model.bin` is the model file saved from training, `handler.py` is the custom inference handler, and `requirements.txt` is a requirements file to add additional dependencies. The custom module can override the following methods: ## ☑️ Supported & Tested Tasks -Below you ll find a list of supported and tested transformers and sentence transformers tasks. Each of those are always tested through integration tests. In addition to those tasks you can always provide `custom`, which expect a `pipeline.py` file to be provided. +Below you ll find a list of supported and tested transformers and sentence transformers tasks. Each of those are always tested through integration tests. In addition to those tasks you can always provide `custom`, which expect a `handler.py` file to be provided. ```bash "text-classification", diff --git a/src/huggingface_inference_toolkit/serialization/base.py b/src/huggingface_inference_toolkit/serialization/base.py index 731139c4..38a4a5d8 100644 --- a/src/huggingface_inference_toolkit/serialization/base.py +++ b/src/huggingface_inference_toolkit/serialization/base.py @@ -25,6 +25,8 @@ "audio/x-wav": Audioer, "audio/ogg": Audioer, "audio/x-audio": Audioer, + "audio/webm": Audioer, + "audio/webm;codecs=opus": Audioer, } diff --git a/src/huggingface_inference_toolkit/webservice_starlette.py b/src/huggingface_inference_toolkit/webservice_starlette.py index 933534b7..76ca5478 100644 --- a/src/huggingface_inference_toolkit/webservice_starlette.py +++ b/src/huggingface_inference_toolkit/webservice_starlette.py @@ -82,10 +82,10 @@ async def predict(request): # TODO: repalce with middleware 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)) + return Response(Jsoner.serialize(pred), media_type="application/json") except Exception as e: logger.error(e) - return Response(Jsoner.serialize({"error": str(e)}), status_code=400) + return Response(Jsoner.serialize({"error": str(e)}), status_code=400, media_type="application/json") app = Starlette( diff --git a/tests/resources/audio/sample1.webm b/tests/resources/audio/sample1.webm new file mode 100644 index 00000000..b74348cc Binary files /dev/null and b/tests/resources/audio/sample1.webm differ diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 7ed732ef..b35cb734 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -69,7 +69,7 @@ def test_load_onnx_repository_from_hf(): # onnx model assert "model.onnx" in folder_contents # custom pipeline - assert "pipeline.py" in folder_contents + assert "handler.py" in folder_contents # revision doesn't have tokenizer assert "tokenizer_config.json" in folder_contents