Kabatubare commited on
Commit
3cd4820
·
verified ·
1 Parent(s): cea8753

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -21,11 +21,11 @@ def predict_voice(audio_file):
21
  Returns:
22
  A string with the prediction and confidence level.
23
  """
 
 
 
24
  # Convert the input audio file to model's expected format.
25
- # The following code assumes your audio file is a numpy array.
26
- # You may need to modify this depending on how the audio file is being read.
27
- waveform = np.array(audio_file)
28
- inputs = extractor(waveform, return_tensors="pt", sampling_rate=extractor.sampling_rate)
29
 
30
  # Generate predictions from the model.
31
  with torch.no_grad(): # Ensure no gradients are calculated
@@ -48,7 +48,7 @@ def predict_voice(audio_file):
48
  # Setting up the Gradio interface
49
  iface = gr.Interface(
50
  fn=predict_voice,
51
- inputs=gr.Audio(source="upload", type="file", label="Upload Audio File"),
52
  outputs=gr.Textbox(label="Prediction"),
53
  title="Voice Authenticity Detection",
54
  description="Detects whether a voice is real or AI-generated. Upload an audio file to see the results.",
 
21
  Returns:
22
  A string with the prediction and confidence level.
23
  """
24
+ # Gradio passes the audio file as a tuple (file_name, file_path). We only need the file_path.
25
+ audio_file_path = audio_file[1]
26
+
27
  # Convert the input audio file to model's expected format.
28
+ inputs = extractor(audio_file_path, return_tensors="pt", sampling_rate=extractor.sampling_rate)
 
 
 
29
 
30
  # Generate predictions from the model.
31
  with torch.no_grad(): # Ensure no gradients are calculated
 
48
  # Setting up the Gradio interface
49
  iface = gr.Interface(
50
  fn=predict_voice,
51
+ inputs=gr.Audio(type="filepath", label="Upload Audio File"), # Corrected usage
52
  outputs=gr.Textbox(label="Prediction"),
53
  title="Voice Authenticity Detection",
54
  description="Detects whether a voice is real or AI-generated. Upload an audio file to see the results.",