Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,16 +25,16 @@ pipe = pipeline(
|
|
25 |
)
|
26 |
|
27 |
# Define the function to classify an audio file
|
28 |
-
def classify_audio(
|
29 |
"""
|
30 |
Takes an audio file path, classifies it using the pipeline,
|
31 |
and returns a dictionary of top labels and their scores.
|
32 |
"""
|
33 |
-
if
|
34 |
return "Please upload an audio file first."
|
35 |
|
36 |
# The pipeline handles the loading, preprocessing, and inference.
|
37 |
-
result = pipe(
|
38 |
# The output is formatted for the Gradio Label component.
|
39 |
return {label['label']: label['score'] for label in result}
|
40 |
|
@@ -43,7 +43,7 @@ app = gr.Interface(
|
|
43 |
fn=classify_audio, # Function to classify audio
|
44 |
inputs=gr.Audio(type="filepath", label="Upload Audio"), # Input for uploading an audio file
|
45 |
outputs=gr.Label(num_top_classes=3, label="Top 3 Predictions"), # Output with top 3 classification results
|
46 |
-
title="
|
47 |
description="Upload an audio file to classify it. This app is optimized to run on all available CPU cores.",
|
48 |
examples=[
|
49 |
# You can add example audio files here if you have them locally
|
|
|
25 |
)
|
26 |
|
27 |
# Define the function to classify an audio file
|
28 |
+
def classify_audio(audio):
|
29 |
"""
|
30 |
Takes an audio file path, classifies it using the pipeline,
|
31 |
and returns a dictionary of top labels and their scores.
|
32 |
"""
|
33 |
+
if audio is None:
|
34 |
return "Please upload an audio file first."
|
35 |
|
36 |
# The pipeline handles the loading, preprocessing, and inference.
|
37 |
+
result = pipe(audio)
|
38 |
# The output is formatted for the Gradio Label component.
|
39 |
return {label['label']: label['score'] for label in result}
|
40 |
|
|
|
43 |
fn=classify_audio, # Function to classify audio
|
44 |
inputs=gr.Audio(type="filepath", label="Upload Audio"), # Input for uploading an audio file
|
45 |
outputs=gr.Label(num_top_classes=3, label="Top 3 Predictions"), # Output with top 3 classification results
|
46 |
+
title="Audio Classification", # App title
|
47 |
description="Upload an audio file to classify it. This app is optimized to run on all available CPU cores.",
|
48 |
examples=[
|
49 |
# You can add example audio files here if you have them locally
|