Spaces:
Runtime error
Runtime error
Commit
·
3967e54
1
Parent(s):
1f93035
Switch to gradio API call
Browse files
app.py
CHANGED
|
@@ -11,28 +11,18 @@ title="Whisper to Emotion"
|
|
| 11 |
|
| 12 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
task="automatic-speech-recognition",
|
| 16 |
-
model="openai/whisper-large-v2",
|
| 17 |
-
chunk_length_s=30,
|
| 18 |
-
device=device,
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
all_special_ids = whisper_model.tokenizer.all_special_ids
|
| 22 |
-
transcribe_token_id = all_special_ids[-5]
|
| 23 |
-
translate_token_id = all_special_ids[-6]
|
| 24 |
|
| 25 |
emotion_classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion')
|
| 26 |
|
| 27 |
def translate_and_classify(audio):
|
| 28 |
-
task = "Transcribe in Spoken Language"
|
| 29 |
-
whisper_model.model.config.forced_decoder_ids = [[2, transcribe_token_id if task=="Transcribe in Spoken Language" else translate_token_id]]
|
| 30 |
-
text = whisper_model(audio)["text"]
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
detected_emotion = emotion[0]["label"]
|
| 34 |
print("Detected Emotion: ", detected_emotion)
|
| 35 |
-
return
|
| 36 |
|
| 37 |
css = """
|
| 38 |
.gradio-container {
|
|
|
|
| 11 |
|
| 12 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 13 |
|
| 14 |
+
whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
emotion_classifier = pipeline("text-classification",model='bhadresh-savani/distilbert-base-uncased-emotion')
|
| 17 |
|
| 18 |
def translate_and_classify(audio):
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
text_result = whisper(audio, None, "transcribe", fn_index=0)
|
| 21 |
+
|
| 22 |
+
emotion = emotion_classifier(text_result)
|
| 23 |
detected_emotion = emotion[0]["label"]
|
| 24 |
print("Detected Emotion: ", detected_emotion)
|
| 25 |
+
return text_result, detected_emotion
|
| 26 |
|
| 27 |
css = """
|
| 28 |
.gradio-container {
|