Internal error is faced when I upload an audio file in fastAPI
Hello, I am new to FastAPI I have to build and API for my deep learning audio classification model.
I have attempted to do this:
@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile = File(...)):
y, sr = librosa.load(file.filename)
print(file.filename)
S = librosa.feature.melspectrogram(
y, sr=sr, n_fft=2048, hop_length=512, n_mels=128)
mfccs = librosa.feature.mfcc(S=librosa.power_to_db(S), n_mfcc=40)
# mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=40)
return mfccs
#return {"filename": file.filename}
if __name__ == "__main__":
# load model
model = load_model("trained_heartbeat_classifier.h5")
classify_file = sys.argv[1]
x_test = []
x_test.append(create_upload_file(classify_file, 0.5))
x_test = np.asarray(x_test)
x_test = x_test.reshape(x_test.shape[0], x_test.shape[1], x_test.shape[2], 1)
pred = model.predict(x_test, verbose=1)
# print(pred)
pred_class = model.predict_classes(x_test)
if pred_class[0]:
print("\nNormal heartbeat")
print("confidence:", pred[0][1])
else:
print("\nAbnormal heartbeat")
print("confidence:", pred[0][0])
but I got the error when I upload an audio file: Internal Server Error
and in the terminal, it shows file not found.
So do we have to save an audio file in any temp folder?