Almost there...
This commit is contained in:
parent
edd55d9257
commit
f4e880cb0f
@ -5,6 +5,7 @@ from flask_classful import FlaskView
|
||||
from utils import json_required
|
||||
import requests
|
||||
import tempfile
|
||||
import numpy
|
||||
|
||||
from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper
|
||||
|
||||
@ -14,25 +15,25 @@ class ClassifyView(FlaskView):
|
||||
@json_required
|
||||
def post(self):
|
||||
|
||||
request.json
|
||||
task = request.json # tag, features, model
|
||||
|
||||
_, temp_model_name = tempfile.mkstemp()
|
||||
temp_means_name = temp_model_name + "MEANS"
|
||||
|
||||
r = requests.get("http://model-service/model/$default/details")
|
||||
r = requests.get(f"http://model-service/model/{task['model']}/details")
|
||||
r.raise_for_status()
|
||||
|
||||
model_details = r.json()
|
||||
|
||||
try:
|
||||
|
||||
r = requests.get("http://model-service/model/$default")
|
||||
r = requests.get(f"http://model-service/model/{task['model']}")
|
||||
r.raise_for_status()
|
||||
|
||||
with open(temp_model_name, 'wb') as f:
|
||||
f.write(r.content)
|
||||
|
||||
r = requests.get("http://model-service/model/$default?means")
|
||||
r = requests.get(f"http://model-service/model/{task['model']}?means")
|
||||
r.raise_for_status()
|
||||
|
||||
with open(temp_means_name, 'wb') as f:
|
||||
@ -46,7 +47,8 @@ class ClassifyView(FlaskView):
|
||||
classifier, mean, std, classes, mid_window, mid_step, short_window, short_step, compute_beat \
|
||||
= load_model(temp_model_name)
|
||||
|
||||
# class_id, probability = classifier_wrapper(classifier, model_details['type'], feature_vector)
|
||||
feature_vector = (numpy.array(task['features']) - mean) / std
|
||||
class_id, probability = classifier_wrapper(classifier, model_details['type'], feature_vector)
|
||||
|
||||
finally: # bruuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuh
|
||||
try:
|
||||
@ -59,4 +61,10 @@ class ClassifyView(FlaskView):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
return jsonify({})
|
||||
# TODO: Publish to message queue
|
||||
results = {
|
||||
"class_id": class_id,
|
||||
"probability": probability
|
||||
}
|
||||
|
||||
return jsonify({"status": "OK", "msg": "enqueued"})
|
||||
|
Reference in New Issue
Block a user