m7k-run commited on
Commit
e01013c
·
verified ·
1 Parent(s): 5b541ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
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
- audio["array"],
13
- sampling_rate=audio["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="numpy"),
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
  )