ardneebwar commited on
Commit
7b1bd83
1 Parent(s): 2f30e8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -1,3 +1,43 @@
1
  import gradio as gr
 
 
2
 
3
- gr.Interface.load("models/ardneebwar/wav2vec2-animal-sounds-finetuned-hubert-finetuned-animals").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
 
5
+ username = "ardneebwar" ## Complete your username
6
+ model_id = f"{username}/facebook/hubert-base-ls960"
7
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
8
+ pipe = pipeline("audio-classification", model=model_id, device=device)
9
+
10
+
11
+ def classify_audio(filepath):
12
+ import time
13
+ start_time = time.time()
14
+
15
+ # Assuming `pipe` is your model pipeline for inference
16
+ preds = pipe(filepath)
17
+
18
+ outputs = {}
19
+ for p in preds:
20
+ outputs[p["label"]] = p["score"]
21
+
22
+ end_time = time.time()
23
+ prediction_time = end_time - start_time
24
+
25
+ return outputs, prediction_time
26
+
27
+ title = "🎵 Animal Sound Classifier"
28
+ description = """
29
+ Animal Sound Classifier model (Fine-tuned "ntu-spml/distilhubert") Dataset: ESC-50 from Github (only the animal sounds)
30
+ """
31
+
32
+ filenames = ['dog.wav', 'cat.wav', 'cow.wav']
33
+ filenames = [f"./{f}" for f in filenames]
34
+
35
+ demo = gr.Interface(
36
+ fn=classify_audio,
37
+ inputs=gr.Audio(type="filepath"),
38
+ outputs=[gr.Label(), gr.Number(label="Prediction time (s)")],
39
+ title=title,
40
+ description=description,
41
+ )
42
+
43
+ demo.launch()