def music_emotions(self, audio: TypeAudio): """ :param audio: audio file with music song """ features = get_audio_features(audio) if len(features) == 0: return result_error(ERROR_MESSAGE_INVALID_FEATURES) emotions = predict_topk_emotions(np.array(features), k=3) if len(emotions) == 0: return result_error(ERROR_MESSAGE_MODEL_FAIL_EMOTIONS) return result_emotions(emotions)
def step2_page(self, hash: str) -> str: """ Step 2 - Redirect with features file hash - Displaying emotion choice :param hash: part of file name with cached song features :return: """ features = AppServerController.get_features_by_hash(hash) if features is None: return self.render_step1_page() emotions = predict_topk_emotions(features, k=3) return self.render_step2_page(emotions)
def music_fonts(self, audio: Optional[TypeAudio] = None, emotion: Optional[str] = None): """ :param audio: audio file with music song :param emotion: emotion, selected by user """ if emotion is not None and emotion not in EMOTIONS: return result_error(ERROR_MESSAGE_UNKNOWN_EMOTION % (emotion, ', '.join(EMOTIONS))) if emotion is not None: emotions = [emotion] else: features = get_audio_features(audio) if len(features) == 0: return result_error(ERROR_MESSAGE_INVALID_FEATURES) emotions = predict_topk_emotions(np.array(features), k=3) emotion_fonts = {} for emotion in emotions: emotion_fonts[emotion] = get_fonts(emotion) return result_emotion_fonts(emotion_fonts)