Commit 7c5c7526 authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

add predict route

parent d818b9b9
......@@ -3,4 +3,32 @@ import random
from flask import Flask, request, jsonify
from keyword_spotting_service import Keyword_Spotting_service
app = Flask(__name__)
\ No newline at end of file
app = Flask(__name__)
@app.route("/predict", methods=["POST"])
def predict():
# get audio file and save it
audio_file = request.files["file"]
file_name = str(random.randint(0, 100000))
audio_file.save((file_name))
# get file name
predict_file_name = audio_file.filename
predict_file_name = predict_file_name.split("/")
new_predict_file_name = predict_file_name[1]
new_predict_file_name = new_predict_file_name.split(".")
FPFN = new_predict_file_name[0]
print(f"{FPFN}")
# invoke keyword spotting service
kss = Keyword_Spotting_service()
# make a prediction
predicted_keyword = kss.predict(file_name, FPFN)
# remove the audio file
os.remove(file_name)
# send back the predicted keword in json format
data = {"Keyword": predicted_keyword}
return jsonify(data)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment