app.py
CHANGED
|
@@ -1,18 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load model
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def predict(audio):
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Gradio UI
|
| 12 |
gr.Interface(
|
| 13 |
fn=predict,
|
| 14 |
-
inputs=gr.Audio(
|
| 15 |
outputs=gr.Label(num_top_classes=3),
|
| 16 |
title="π Keyword Spotting",
|
| 17 |
-
|
|
|
|
| 18 |
).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load model - use the correct Hugging Face model ID
|
| 5 |
+
# Remove the '/spaces/' prefix and use just the username/model-name format
|
| 6 |
+
classifier = pipeline("audio-classification", model="Hnin/Audio_Classification_On_Key_spotting")
|
| 7 |
|
| 8 |
def predict(audio):
|
| 9 |
+
if audio is None:
|
| 10 |
+
return {"Error": "No audio provided"}
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
preds = classifier(audio)
|
| 14 |
+
return {p["label"]: p["score"] for p in preds}
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return {"Error": f"Prediction failed: {str(e)}"}
|
| 17 |
|
| 18 |
# Gradio UI
|
| 19 |
gr.Interface(
|
| 20 |
fn=predict,
|
| 21 |
+
inputs=gr.Audio(sources=["microphone"], type="filepath"), # Updated parameter name
|
| 22 |
outputs=gr.Label(num_top_classes=3),
|
| 23 |
title="π Keyword Spotting",
|
| 24 |
+
description="Upload an audio file or record from microphone for keyword spotting classification",
|
| 25 |
+
examples=["example1.wav", "example2.wav"] # Make sure these files exist
|
| 26 |
).launch()
|