Spaces:
Runtime error
Runtime error
seikin_alexey
commited on
Commit
·
7436a10
1
Parent(s):
31f7fb2
app3.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4 |
import warnings
|
5 |
warnings.filterwarnings("ignore")
|
6 |
|
7 |
-
# Function to get the list of audio files in the 'rec/'
|
8 |
def get_audio_files_list(directory="rec"):
|
9 |
try:
|
10 |
return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
@@ -32,34 +32,18 @@ emotion_dict = {
|
|
32 |
def predict_emotion(selected_audio):
|
33 |
file_path = os.path.join("rec", selected_audio)
|
34 |
out_prob, score, index, text_lab = learner.classify_file(file_path)
|
35 |
-
|
|
|
36 |
|
37 |
# Get the list of audio files for the dropdown
|
38 |
audio_files_list = get_audio_files_list()
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
return file_path
|
44 |
-
|
45 |
-
# Gradio components
|
46 |
-
dropdown = gr.Dropdown(label="Select Audio", choices=audio_files_list)
|
47 |
-
audio_player = gr.Audio(source="file", label="Listen to the selected audio")
|
48 |
-
|
49 |
-
# Update the audio player when a new selection is made from the dropdown
|
50 |
-
def update_audio(selected_audio):
|
51 |
-
return get_audio_file_path(selected_audio)
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# Update the Gradio interface to use both the dropdown and the audio player as inputs
|
57 |
-
interface = gr.Interface(
|
58 |
-
fn=predict_emotion,
|
59 |
-
inputs=[dropdown, audio_player],
|
60 |
-
outputs="text",
|
61 |
-
title="ML Speech Emotion Detection",
|
62 |
-
description="Speechbrain powered wav2vec 2.0 pretrained model on IEMOCAP dataset using Gradio."
|
63 |
-
)
|
64 |
|
|
|
65 |
interface.launch()
|
|
|
4 |
import warnings
|
5 |
warnings.filterwarnings("ignore")
|
6 |
|
7 |
+
# Function to get the list of audio files in the 'rec/' directory
|
8 |
def get_audio_files_list(directory="rec"):
|
9 |
try:
|
10 |
return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
|
|
32 |
def predict_emotion(selected_audio):
|
33 |
file_path = os.path.join("rec", selected_audio)
|
34 |
out_prob, score, index, text_lab = learner.classify_file(file_path)
|
35 |
+
emotion = emotion_dict[text_lab[0]]
|
36 |
+
return emotion, file_path # Return both emotion and file path
|
37 |
|
38 |
# Get the list of audio files for the dropdown
|
39 |
audio_files_list = get_audio_files_list()
|
40 |
|
41 |
+
# Loading Gradio interface
|
42 |
+
inputs = gr.Dropdown(label="Select Audio", choices=audio_files_list)
|
43 |
+
outputs = [gr.outputs.Textbox(label="Predicted Emotion"), gr.outputs.Audio(label="Play Audio")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
title = "ML Speech Emotion Detection"
|
46 |
+
description = "Speechbrain powered wav2vec 2.0 pretrained model on IEMOCAP dataset using Gradio."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
interface = gr.Interface(fn=predict_emotion, inputs=inputs, outputs=outputs, title=title, description=description)
|
49 |
interface.launch()
|