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

**URL:** <https://discuss.huggingface.co/t/fix-sample-code-to-deploy-and-inference-tasks-using-audio-image-files/25527>\
**Category:** Amazon SageMaker\
**Created:** [November 4, 2022, 10:07am UTC](https://discuss.huggingface.co/t/fix-sample-code-to-deploy-and-inference-tasks-using-audio-image-files/25527 "2022-11-04T10:07:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sohoha](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@sohoha](https://discuss.huggingface.co/u/sohoha)\
**Post date:** [November 4, 2022, 10:07am UTC](https://discuss.huggingface.co/t/fix-sample-code-to-deploy-and-inference-tasks-using-audio-image-files/25527/1 "2022-11-04T10:07:39Z")

</div>

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.

 ![Screen Shot 0004-11-04 at 19.06.34](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/d3bf3eddda4ab8e6ae7e62e8159c9551def915f5.png)

I use below models for example.

> **[facebook/wav2vec2-large-960h · Hugging Face](https://huggingface.co/facebook/wav2vec2-large-960h)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

```python
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.

```python
# 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?

---

<div class="post-metadata">

**Author:** ![sohoha](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@sohoha](https://discuss.huggingface.co/u/sohoha)\
**Post date:** [November 15, 2022, 12:30am UTC](https://discuss.huggingface.co/t/fix-sample-code-to-deploy-and-inference-tasks-using-audio-image-files/25527/2 "2022-11-15T00:30:53Z")

</div>

Does anyone know where to contribute that?

---

<div class="post-metadata">

**Author:** ![marshmellow77](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/marshmellow77/32/3279_2.png) [@marshmellow77](https://discuss.huggingface.co/u/marshmellow77)\
**Post date:** [November 21, 2022, 12:53pm UTC](https://discuss.huggingface.co/t/fix-sample-code-to-deploy-and-inference-tasks-using-audio-image-files/25527/3 "2022-11-21T12:53:45Z")

</div>

@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?
