def wrap(*args, **kwargs): try: if not request.headers.get('Authorization'): return Failure('You are not authorize to access this api, kindly to authenticate for request a valid token to access the api.', 401) else: data = request.headers.get('Authorization') token = str.replace(str(data), 'Bearer ', '') user_id = decode_auth_token(token) user = is_valid_user(user_id) if user: g.user = user return f(*args, **kwargs) else: return Failure('Your token session expired, please log in again.', 401) except Exception as e: exception_message = str(e) return Failure(exception_message)
def detect_emoji(): try: emoji_input = request.form['emoji_input'] print('Emoji Input: {0}'.format(emoji_input)) emoji_image = detect_emotion(emoji_input) print('Emoji path: {0}'.format(emoji_image)) return Success({'message': 'Completed.', 'data': emoji_image}) except Exception as error: return Failure({'message': str(error)}, debug=True)
def change_password(): email=request.form['email'] old_password = request.form['old_password'] new_password = request.form['new_password'] status, error = user_change_password(email, old_password, new_password) if not error: message = Success({'status':'success', 'message':'Successfully password changed.'}) return message return Failure(error)
def register(): first_name = request.form['first_name'] last_name = request.form['last_name'] email = request.form['email'] password = request.form['password'] user, error, token = create_user(first_name, last_name, email, password) if not error: message = Success({ 'status': 'sucess', 'message': 'Successfully registered.', 'auth_token': token, }) return message return Failure(error)
def upload_speech(): try: if request.method == "POST": filepath = dti_path + '\\ai_engine\\data\\file.wav' audit_file = request.files["audio_data"] with open(filepath, 'wb') as audio: audit_file.save(audio) print('file uploaded successfully') emotion_results = process_speech(filepath) result = '' for emotion_result in emotion_results: result = result + emotion_result + ';' return Success({'message': 'Completed.', 'data': result}) except Exception as error: return Failure({'message': str(error)}, debug=True)
def choose_upload(): try: if request.method == "POST": file = request.files["file"] file.save(os.path.join("ai_api", file.filename)) emotion_results = process_speech( 'D:/IDE/PythonProject/emojidetect2/ai_api/ai_api/' + file.filename) result = '' for emotion_result in emotion_results: result = result + emotion_result + ';' if emotion_results[1] == 'weak sad': return render_template("weaksad.html", message="success") elif emotion_results[1] == 'mid sad': return render_template("midsad.html", message="success") elif emotion_results[1] == 'very sad': return render_template("verysad.html", message="success") elif emotion_results[1] == 'weak fear': return render_template("weakfear.html", message="success") elif emotion_results[1] == 'mid fear': return render_template("midfear.html", message="success") elif emotion_results[1] == 'very fear': return render_template("veryfear.html", message="success") #return Success({'message': 'Completed.', 'data': result}) return render_template( "result.html", message="success", ) #return Success({'message': 'Completed.', 'data': result}) except Exception as error: return Failure({'message': str(error)}, debug=True)
def wrapped(*args, **kwargs): action = request.path user_actions = get_current_user_actions() if is_valid_action(user_actions, action): return f(*args, **kwargs) return Failure('Permission denined', 403)