From 0eb43289a4a062b2888eb44a075e3b8f6c574974 Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 15 Apr 2020 02:03:59 +0200 Subject: [PATCH] did stuff --- classification_service/views/classify_view.py | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/classification_service/views/classify_view.py b/classification_service/views/classify_view.py index 9b2edb5..f5e5168 100644 --- a/classification_service/views/classify_view.py +++ b/classification_service/views/classify_view.py @@ -1,11 +1,62 @@ #!/usr/bin/env python3 +import os from flask import request, jsonify from flask_classful import FlaskView from utils import json_required +import requests +import tempfile + +from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper class ClassifyView(FlaskView): @json_required 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({})