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
|
from utils import json_required
|
||||||
import requests
|
import requests
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import numpy
|
||||||
|
|
||||||
from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper
|
from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper
|
||||||
|
|
||||||
@ -14,25 +15,25 @@ class ClassifyView(FlaskView):
|
|||||||
@json_required
|
@json_required
|
||||||
def post(self):
|
def post(self):
|
||||||
|
|
||||||
request.json
|
task = request.json # tag, features, model
|
||||||
|
|
||||||
_, temp_model_name = tempfile.mkstemp()
|
_, temp_model_name = tempfile.mkstemp()
|
||||||
temp_means_name = temp_model_name + "MEANS"
|
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()
|
r.raise_for_status()
|
||||||
|
|
||||||
model_details = r.json()
|
model_details = r.json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
r = requests.get("http://model-service/model/$default")
|
r = requests.get(f"http://model-service/model/{task['model']}")
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
with open(temp_model_name, 'wb') as f:
|
with open(temp_model_name, 'wb') as f:
|
||||||
f.write(r.content)
|
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()
|
r.raise_for_status()
|
||||||
|
|
||||||
with open(temp_means_name, 'wb') as f:
|
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 \
|
classifier, mean, std, classes, mid_window, mid_step, short_window, short_step, compute_beat \
|
||||||
= load_model(temp_model_name)
|
= 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
|
finally: # bruuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuh
|
||||||
try:
|
try:
|
||||||
@ -59,4 +61,10 @@ class ClassifyView(FlaskView):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
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