import json | |
from typing import List | |
import requests as r | |
import base64 | |
import mimetypes | |
ENDPOINT_URL="" | |
HF_TOKEN="" | |
def predict(path_to_audio:str=None): | |
# read audio file | |
with open(path_to_audio, "rb") as i: | |
b = i.read() | |
# get mimetype | |
content_type= mimetypes.guess_type(path_to_audio)[0] | |
headers= { | |
"Authorization": f"Bearer {HF_TOKEN}", | |
"Content-Type": content_type | |
} | |
response = r.post(ENDPOINT_URL, headers=headers, data=b) | |
return response.json() | |
prediction = predict(path_to_audio="sample.wav") | |
prediction | |