did stuff
This commit is contained in:
parent
fd83e268ef
commit
0eb43289a4
@ -1,11 +1,62 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
from flask_classful import FlaskView
|
from flask_classful import FlaskView
|
||||||
from utils import json_required
|
from utils import json_required
|
||||||
|
import requests
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper
|
||||||
|
|
||||||
|
|
||||||
class ClassifyView(FlaskView):
|
class ClassifyView(FlaskView):
|
||||||
|
|
||||||
@json_required
|
@json_required
|
||||||
def post(self):
|
def post(self):
|
||||||
return jsonify(request.json)
|
|
||||||
|
request.json
|
||||||
|
|
||||||
|
_, temp_model_name = tempfile.mkstemp()
|
||||||
|
temp_means_name = temp_model_name + "MEANS"
|
||||||
|
|
||||||
|
r = requests.get("http://model-service/model/$default/details")
|
||||||
|
r.raise_for_status()
|
||||||
|
|
||||||
|
model_details = r.json()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
r = requests.get("http://model-service/model/$default")
|
||||||
|
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.raise_for_status()
|
||||||
|
|
||||||
|
with open(temp_means_name, 'wb') as f:
|
||||||
|
f.write(r.content)
|
||||||
|
|
||||||
|
if model_details['type'] == 'knn':
|
||||||
|
classifier, mean, std, classes, mid_window, mid_step, short_window, short_step, compute_beat \
|
||||||
|
= load_model_knn(temp_model_name)
|
||||||
|
|
||||||
|
else:
|
||||||
|
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)
|
||||||
|
|
||||||
|
finally: # bruuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuh
|
||||||
|
try:
|
||||||
|
os.remove(temp_model_name)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.remove(temp_means_name)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return jsonify({})
|
||||||
|
Reference in New Issue
Block a user