123454567891011128913141516171819201421222324172526import gradio as grfrom transformers import pipeline
# Load modelclassifier = pipeline("audio-classification", model="/spaces/Hnin/Audio_Classification_On_Key_spotting")# Load model - use the correct Hugging Face model ID# Remove the '/spaces/' prefix and use just the username/model-name formatclassifier = pipeline("audio-classification", model="Hnin/Audio_Classification_On_Key_spotting")
def predict(audio): if audio is None: return {"Error": "No audio provided"} try: preds = classifier(audio) return {p["label"]: p["score"] for p in preds} preds = classifier(audio) return {p["label"]: p["score"] for p in preds} except Exception as e: return {"Error": f"Prediction failed: {str(e)}"}
# Gradio UIgr.Interface( fn=predict, inputs=gr.Audio(source="microphone", type="filepath"), inputs=gr.Audio(sources=["microphone"], type="filepath"), # Updated parameter name outputs=gr.Label(num_top_classes=3), title="🔊 Keyword Spotting", description="Upload an audio file or record from microphone for keyword spotting classification", examples=["example1.wav", "example2.wav"] examples=["example1.wav", "example2.wav"] # Make sure these files exist).launch()app.py+14-6