Skip to content

Instantly share code, notes, and snippets.

@philschmid
Last active March 25, 2022 17:05
Show Gist options
  • Select an option

  • Save philschmid/e70a19504338177d7742dc4f3a1b9894 to your computer and use it in GitHub Desktop.

Select an option

Save philschmid/e70a19504338177d7742dc4f3a1b9894 to your computer and use it in GitHub Desktop.
from sagemaker.huggingface import HuggingFaceModel
from sagemaker.serializers import DataSerializer
import sagemaker
role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
'HF_MODEL_ID':'facebook/wav2vec2-base-960h',
'HF_TASK':'automatic-speech-recognition'
}
# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
transformers_version='4.17',
pytorch_version='1.10',
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
serializer=DataSerializer(content_type="audio/wave") # serializer for mime-type
)
# send request with file_path
transcription = predictor.predict("path/to/interview.wav")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment