Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>


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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/huggingface_inference_toolkit/serialization/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"audio/x-wav": Audioer,
"audio/ogg": Audioer,
"audio/x-audio": Audioer,
"audio/webm": Audioer,
"audio/webm;codecs=opus": Audioer,
}


Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_inference_toolkit/webservice_starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Binary file added tests/resources/audio/sample1.webm
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down