Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from transformers import AutoFeatureExtractor, AutoModelForAudioClassification
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
from torch.nn.functional import softmax
|
|
|
6 |
|
7 |
# Path to the local directory where the model files are stored within the Space
|
8 |
local_model_path = "./"
|
@@ -23,9 +24,12 @@ def predict_voice(audio_file):
|
|
23 |
"""
|
24 |
# Gradio passes the audio file as a tuple (file_name, file_path). We only need the file_path.
|
25 |
audio_file_path = audio_file[1]
|
|
|
|
|
|
|
26 |
|
27 |
# Convert the input audio file to model's expected format.
|
28 |
-
inputs = extractor(
|
29 |
|
30 |
# Generate predictions from the model.
|
31 |
with torch.no_grad(): # Ensure no gradients are calculated
|
@@ -45,6 +49,7 @@ def predict_voice(audio_file):
|
|
45 |
result = f"The voice is classified as '{label}' with a confidence of {confidence:.2f}%."
|
46 |
return result
|
47 |
|
|
|
48 |
# Setting up the Gradio interface
|
49 |
iface = gr.Interface(
|
50 |
fn=predict_voice,
|
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
from torch.nn.functional import softmax
|
6 |
+
import soundfile as sf
|
7 |
|
8 |
# Path to the local directory where the model files are stored within the Space
|
9 |
local_model_path = "./"
|
|
|
24 |
"""
|
25 |
# Gradio passes the audio file as a tuple (file_name, file_path). We only need the file_path.
|
26 |
audio_file_path = audio_file[1]
|
27 |
+
|
28 |
+
# Load the audio file. Adjust the loading mechanism based on your audio file format.
|
29 |
+
waveform, sample_rate = sf.read(audio_file_path)
|
30 |
|
31 |
# Convert the input audio file to model's expected format.
|
32 |
+
inputs = extractor(waveform, return_tensors="pt", sampling_rate=sample_rate)
|
33 |
|
34 |
# Generate predictions from the model.
|
35 |
with torch.no_grad(): # Ensure no gradients are calculated
|
|
|
49 |
result = f"The voice is classified as '{label}' with a confidence of {confidence:.2f}%."
|
50 |
return result
|
51 |
|
52 |
+
|
53 |
# Setting up the Gradio interface
|
54 |
iface = gr.Interface(
|
55 |
fn=predict_voice,
|