Fix sample code to deploy and inference tasks using audio/image files

I noticed that automated generated snippet on Hugging Face model’s page doesn’t work for models of images/audios.

For example, at automatic-speech-recognition task following snippet is produced.

I use below models for example.

from sagemaker.huggingface import HuggingFaceModel
import sagemaker

role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
	'HF_MODEL_ID':'facebook/wav2vec2-large-960h',
	'HF_TASK':'automatic-speech-recognition'
}

# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
	transformers_version='4.17.0',
	pytorch_version='1.10.2',
	py_version='py38',
	env=hub,
	role=role, 
)

# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
	initial_instance_count=1, # number of instances
	instance_type='ml.m5.xlarge' # ec2 instance type
)

predictor.predict({
	'inputs': "sample1.flac"
})

However, prediction part doesn’t work.

For audio/image data, we should use DataSerializer.

# deploy model to SageMaker Inference
audio_serializer = DataSerializer(content_type='audio/x-audio')
predictor = huggingface_model.deploy(
	initial_instance_count=1, # number of instances
	instance_type='ml.m5.xlarge', # ec2 instance type
    serializer=audio_serializer
)

audio_path = "sample1.flac"

res = predictor.predict(data=audio_path)
print(res)

How can I update this snippet?

Does anyone know where to contribute that?

@philschmid - what’s the best way to do this? @sohoha is happy to provide the correct code snippet, he just needs to know how … Is it possible to raise issues or PRs for this?