Hnin commited on
Commit
77df70d
Β·
verified Β·
1 Parent(s): 37991fa
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,18 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load model
5
- classifier = pipeline("audio-classification", model="/spaces/Hnin/Audio_Classification_On_Key_spotting")
 
6
 
7
  def predict(audio):
8
- preds = classifier(audio)
9
- return {p["label"]: p["score"] for p in preds}
 
 
 
 
 
 
10
 
11
  # Gradio UI
12
  gr.Interface(
13
  fn=predict,
14
- inputs=gr.Audio(source="microphone", type="filepath"),
15
  outputs=gr.Label(num_top_classes=3),
16
  title="πŸ”Š Keyword Spotting",
17
- examples=["example1.wav", "example2.wav"]
 
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()