123456789101112131415161718import gradio as grfrom transformers import pipeline# Load modelclassifier = pipeline("audio-classification", model="/spaces/Hnin/Audio_Classification_On_Key_spotting")def predict(audio):preds = classifier(audio)return {p["label"]: p["score"] for p in preds}# Gradio UIgr.Interface(fn=predict,inputs=gr.Audio(source="microphone", type="filepath"),outputs=gr.Label(num_top_classes=3),title="🔊 Keyword Spotting",examples=["example1.wav", "example2.wav"]).launch()1234567891011121314151617181920212223242526import gradio as grfrom transformers import pipeline# 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}except Exception as e:return {"Error": f"Prediction failed: {str(e)}"}# Gradio UIgr.Interface(fn=predict,inputs=gr.Audio(sources=["microphone"], type="filepath"), # Updated parameter nameoutputs=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"] # Make sure these files exist).launch()
app.py+14-6