def parse_voice(): """ We receive a recording and the id of the text that we have sent and send back the differences bettween the recording and the text :return: """ if request.method == "POST": # recordingul preprocess = PreprocessData() calculator = builder() f = request.files['recording'] # id-ul textului id_text = int(request.form.getlist('id_text')[0]) filename = f.filename f.save(os.path.join("webapi/UPLOAD_FOLDER_RECORDINGS", filename)) # aflam ce a zis de fapt vorbitorul said = preprocess.get_text_from_wav( os.path.join("webapi/UPLOAD_FOLDER_RECORDINGS", filename)) # vrem sa determinam asemanarea dintre ce a zis si ce trebuia sa zica # nr_mistakes = preprocess.check_slurred_speech(said, int(id_text[0])) user = User.query.filter_by(username=get_jwt_identity()).first() preprocess.write_recording_data( user, os.path.join("webapi/UPLOAD_FOLDER_RECORDINGS", filename), id_text) score = calculator.detect_speech_abnormalities(user.username) if score > 5: return jsonify({"response": "Suna la 112!"}) else: return jsonify({"response": "Esti ok!"}) return "Request unauthorized"
def check_symmetry_normal_photo(): """ We received a normal photo of the user and we will return an array with the most important data :return: """ if request.method == 'POST': preprocess = PreprocessData() calculator = builder() f = request.files['image'] filename = f.filename f.save(os.path.join(app.config['UPLOAD_FOLDER_PHOTOS'], filename)) x = User.query.filter_by(username=get_jwt_identity()).first() output = preprocess.write_mouth_eyes_data_tojson( x, os.path.join(app.config['UPLOAD_FOLDER_PHOTOS'], filename)) if output == "Error": return jsonify({"response": "Imposibil de procesat imaginea"}) score = calculator.detect_moutheyes_abnormalities(x.username) print(score) if score > 4.3: return jsonify({"response": "Suna la 112!"}) else: return jsonify({"response": "Esti ok!"}) return "Request unauthorized"
def write_mouth_eyes_data_tojson(self, userdb, path_received_image): create_json_file(userdb.username + "now") now_data = self.return_face_parts(path_received_image) if now_data == "Error": return "Error" calculator = builder() assymetry_mouth = calculator.get_mouth_asymmetry(now_data['mouth']) assymetry_eyes = calculator.get_eyes_asymmetry(now_data['left_eye'], now_data['right_eye']) distance_corners = calculator.calculate_distance_between_corners( now_data['mouth_corners']) vertical_distance = calculator.calculcate_vertical_distance( now_data['vertical_points']) data = { 'mouth': assymetry_mouth, 'eyes': assymetry_eyes, 'distance_corners': distance_corners, 'vertical_distance': vertical_distance } write_data("normal_photo", data, userdb.username + "now") create_json_file(userdb.username + "db") db_data = self.return_face_parts(userdb.normal_photo.photo_name) calculator = builder() assymetry_mouth = calculator.get_mouth_asymmetry(db_data['mouth']) assymetry_eyes = calculator.get_eyes_asymmetry(db_data['left_eye'], db_data['right_eye']) distance_corners = calculator.calculate_distance_between_corners( db_data['mouth_corners']) vertical_distance = calculator.calculcate_vertical_distance( db_data['vertical_points']) data = { 'mouth': assymetry_mouth, 'eyes': assymetry_eyes, 'distance_corners': distance_corners, 'vertical_distance': vertical_distance } write_data("normal_photo", data, userdb.username + "db")
def parseVoice(): if request.method == "POST": preprocess = PreprocessData() calculator = builder() id_text = int(request.form.getlist('recording_id_text')[0]) text = (request.form.getlist('text')[0]) user = User.query.filter_by(username=get_jwt_identity()).first() preprocess.write_recording_data(user, text, id_text) score = calculator.detect_speech_abnormalities(user.username) print(score) if score >= 2: return jsonify({'response': 'Suna la 112!'}) else: return jsonify({'response': 'Esti ok!'}) return 'Unauthorized'
def send_final_result(): """ At this point we have all the necessary data to make a comparision between the database and the info we have received now. We will return True or False :return: """ if request.method == "POST": # todo build the dictionary for the class that takes decidsion calculator = builder() user = User.query.filter_by(username=get_jwt_identity()).first() score = calculator.caculate_total_score(user.username) print(score) if score > 15: return jsonify({"response": "Call 911"}) else: return jsonify({"response": "Esti ok! Calmeaza-te!"}) return "Unauthorized Request"
def send_texting_test(): """ We received the text_id and the input_text which the user had to text :return: """ if request.method == 'POST': preprocess = PreprocessData() calculator = builder() id_text = int(request.form.getlist('id_text')[0]) input_text = request.form.getlist('input_text')[0] differences = preprocess.check_similarity(id_text, input_text) user = User.query.filter_by(username=get_jwt_identity()).first() preprocess.write_texting_data(user, input_text, id_text) score = calculator.detect_typing_abnormalities(user.username) print(score) if score > 0.5: return jsonify({"response": "Suna la 112"}) return jsonify({"response": "Esti ok!"}) return "Request unauthorized"
def get_smiley_corners(): """ We received a smiling photo of the user and we will return an array with the most important data :return: """ if request.method == 'POST': preprocess = PreprocessData() calculator = builder() f = request.files['image'] filename = f.filename f.save(os.path.join("webapi/UPLOAD_FOLDER_PHOTOS", filename)) x = User.query.filter_by(username=get_jwt_identity()).first() preprocess.write_smiling_data_tojson( x, os.path.join("webapi/UPLOAD_FOLDER_PHOTOS", filename)) score = calculator.detect_smiling_abnormalities(x.username) print(score) if score > 1: return jsonify({"response": "Suna la 112!"}) else: return jsonify({"response": "Esti ok!"}) return "Request unauthorized"
def write_smiling_data_tojson(self, userdb, path_received_image): now_data = self.return_face_parts(path_received_image) calculator = builder() distance_corners = (calculator.calculate_distance_between_corners( now_data['mouth_corners'])) / 10 vertical_distance = calculator.calculcate_vertical_distance( now_data['vertical_points']) smiling_data = { "distance_corners": distance_corners, "vertical_distance": vertical_distance } write_data("smiling_data", smiling_data, userdb.username + "now") db_data = self.return_face_parts(userdb.smiling_photo.photo_name) distance_corners = (calculator.calculate_distance_between_corners( db_data['mouth_corners'])) / 10 vertical_distance = calculator.calculcate_vertical_distance( db_data['vertical_points']) smiling_data = { "distance_corners": distance_corners, "vertical_distance": vertical_distance } write_data("smiling_data", smiling_data, userdb.username + "db")