Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
|
|
|
| 3 |
from transformers import AutoModelForAudioClassification, AutoFeatureExtractor
|
| 4 |
|
| 5 |
# Load model directly from HF Hub
|
| 6 |
repo_name = "m7k-run/ast-genre-classifier"
|
| 7 |
model = AutoModelForAudioClassification.from_pretrained(repo_name)
|
| 8 |
feature_extractor = AutoFeatureExtractor.from_pretrained(repo_name)
|
| 9 |
-
|
| 10 |
def predict(audio):
|
|
|
|
|
|
|
| 11 |
inputs = feature_extractor(
|
| 12 |
-
|
| 13 |
-
sampling_rate=
|
| 14 |
return_tensors="pt"
|
| 15 |
)
|
| 16 |
|
|
@@ -23,7 +25,7 @@ def predict(audio):
|
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=predict,
|
| 26 |
-
inputs=gr.Audio(type="
|
| 27 |
outputs=gr.Label(),
|
| 28 |
title="Audio Classifier"
|
| 29 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
import librosa
|
| 4 |
from transformers import AutoModelForAudioClassification, AutoFeatureExtractor
|
| 5 |
|
| 6 |
# Load model directly from HF Hub
|
| 7 |
repo_name = "m7k-run/ast-genre-classifier"
|
| 8 |
model = AutoModelForAudioClassification.from_pretrained(repo_name)
|
| 9 |
feature_extractor = AutoFeatureExtractor.from_pretrained(repo_name)
|
|
|
|
| 10 |
def predict(audio):
|
| 11 |
+
audio_array, _ = librosa.load(audio, sr=16000)
|
| 12 |
+
|
| 13 |
inputs = feature_extractor(
|
| 14 |
+
audio_array,
|
| 15 |
+
sampling_rate=16000,
|
| 16 |
return_tensors="pt"
|
| 17 |
)
|
| 18 |
|
|
|
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=predict,
|
| 28 |
+
inputs=gr.Audio(type="filepath"),
|
| 29 |
outputs=gr.Label(),
|
| 30 |
title="Audio Classifier"
|
| 31 |
)
|