srinikesh1432 commited on
Commit
b165631
·
verified ·
1 Parent(s): 74676ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -1,21 +1,21 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- # Load audio classification pipeline
5
- classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
6
-
7
- def classify_audio(audio):
8
- # audio is (sample_rate, numpy array)
9
- return classifier(audio)
10
-
11
- # Gradio UI
12
- demo = gr.Interface(
13
- fn=classify_audio,
14
- inputs=gr.Audio(type="filepath"),
15
- outputs=gr.Label(num_top_classes=5),
16
- title="Audio Classification",
17
- description="Upload an audio file and classify the sound (e.g., speech, music, etc.)."
18
- )
19
-
20
- if __name__ == "__main__":
21
- demo.launch()
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load audio classification pipeline
5
+ classifier = pipeline("audio-classification", model="superb/wav2vec2-base-superb-ks")
6
+
7
+ def classify_audio(file_path):
8
+ # Hugging Face audio pipeline works best with a filepath
9
+ return classifier(file_path)
10
+
11
+ # Gradio UI
12
+ demo = gr.Interface(
13
+ fn=classify_audio,
14
+ inputs=gr.Audio(type="filepath", label="Upload or Record Audio"),
15
+ outputs=gr.Label(num_top_classes=5),
16
+ title="Audio Classification App",
17
+ description="Upload or record an audio file (mp3, wav, flac, etc.) and classify the sound."
18
+ )
19
+
20
+ if __name__ == "__main__":
21
+ demo.launch()