Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,12 @@ config = AutoConfig.from_pretrained("SeyedAli/Persian-Speech-Emotion-HuBert-V1")
|
|
7 |
model = Wav2Vec2FeatureExtractor.from_pretrained("SeyedAli/Persian-Speech-Emotion-HuBert-V1")
|
8 |
|
9 |
def speech_file_to_array_fn(path, sampling_rate):
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
resampler = torchaudio.transforms.Resample(_sampling_rate)
|
12 |
speech = resampler(speech_array).squeeze().numpy()
|
13 |
return speech
|
@@ -24,8 +29,8 @@ def predict(path, sampling_rate):
|
|
24 |
outputs = [{"Label": config.id2label[i], "Score": f"{round(score * 100, 3):.1f}%"} for i, score in enumerate(scores)]
|
25 |
return outputs
|
26 |
|
27 |
-
def SER(
|
28 |
-
return predict(
|
29 |
|
30 |
iface = gr.Interface(fn=SER, inputs="audio", outputs="text")
|
31 |
iface.launch(share=False)
|
|
|
7 |
model = Wav2Vec2FeatureExtractor.from_pretrained("SeyedAli/Persian-Speech-Emotion-HuBert-V1")
|
8 |
|
9 |
def speech_file_to_array_fn(path, sampling_rate):
|
10 |
+
with tempfile.NamedTemporaryFile(suffix=".wav") as temp_audio_file:
|
11 |
+
# Copy the contents of the uploaded audio file to the temporary file
|
12 |
+
temp_audio_file.write(open(path, "rb").read())
|
13 |
+
temp_audio_file.flush()
|
14 |
+
# Load the audio file using torchaudio
|
15 |
+
speech_array, _sampling_rate = torchaudio.load(temp_audio_file.name)
|
16 |
resampler = torchaudio.transforms.Resample(_sampling_rate)
|
17 |
speech = resampler(speech_array).squeeze().numpy()
|
18 |
return speech
|
|
|
29 |
outputs = [{"Label": config.id2label[i], "Score": f"{round(score * 100, 3):.1f}%"} for i, score in enumerate(scores)]
|
30 |
return outputs
|
31 |
|
32 |
+
def SER(audio):
|
33 |
+
return predict(audio,model.sampling_rate)
|
34 |
|
35 |
iface = gr.Interface(fn=SER, inputs="audio", outputs="text")
|
36 |
iface.launch(share=False)
|