|
|
|
from transformers import pipeline |
|
|
|
|
|
model_text_emotion = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") |
|
|
|
|
|
model_speech_emotion = pipeline("audio-classification", model="aherzberg/ser_model_fixed_label") |
|
|
|
|
|
model_voice2text = pipeline("automatic-speech-recognition", model="openai/whisper-tiny.en") |
|
|
|
|
|
def infere_text_emotion(text): |
|
return model_text_emotion(text)[0]["label"].capitalize() |
|
|
|
|
|
def infere_speech_emotion(text): |
|
|
|
emotions_dict = {"angry": "Anger", "disgust": "Disgust", "fear": "Fear", "happy": "Joy", "neutral": "Neutral", "sad": "Sadness"} |
|
inference = model_speech_emotion(text)[0]["label"] |
|
return emotions_dict[inference] |
|
|
|
|
|
def infere_voice2text(audio_file): |
|
return model_voice2text(audio_file)["text"] |
|
|