Kabatubare commited on
Commit
3b392fa
·
verified ·
1 Parent(s): 3c69ff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -12,18 +12,16 @@ local_model_path = "./"
12
  extractor = AutoFeatureExtractor.from_pretrained(local_model_path)
13
  model = AutoModelForAudioClassification.from_pretrained(local_model_path)
14
 
15
- def predict_voice(audio_file):
16
  """
17
  Predicts whether a voice is real or spoofed from an audio file.
18
 
19
  Args:
20
- audio_file: The input audio file to be classified.
21
 
22
  Returns:
23
  A string with the prediction and confidence level.
24
  """
25
- # Gradio passes the audio file as a tuple (file_name, file_path). We only need the file_path.
26
- audio_file_path = audio_file[1]
27
 
28
  # Load the audio file. Adjust the loading mechanism based on your audio file format.
29
  waveform, sample_rate = sf.read(audio_file_path)
@@ -49,11 +47,9 @@ def predict_voice(audio_file):
49
  result = f"The voice is classified as '{label}' with a confidence of {confidence:.2f}%."
50
  return result
51
 
52
-
53
- # Setting up the Gradio interface
54
  iface = gr.Interface(
55
  fn=predict_voice,
56
- inputs=gr.Audio(type="filepath", label="Upload Audio File"), # Corrected usage
57
  outputs=gr.Textbox(label="Prediction"),
58
  title="Voice Authenticity Detection",
59
  description="Detects whether a voice is real or AI-generated. Upload an audio file to see the results.",
 
12
  extractor = AutoFeatureExtractor.from_pretrained(local_model_path)
13
  model = AutoModelForAudioClassification.from_pretrained(local_model_path)
14
 
15
+ def predict_voice(audio_file_path):
16
  """
17
  Predicts whether a voice is real or spoofed from an audio file.
18
 
19
  Args:
20
+ audio_file_path: The file path of the uploaded audio file to be classified.
21
 
22
  Returns:
23
  A string with the prediction and confidence level.
24
  """
 
 
25
 
26
  # Load the audio file. Adjust the loading mechanism based on your audio file format.
27
  waveform, sample_rate = sf.read(audio_file_path)
 
47
  result = f"The voice is classified as '{label}' with a confidence of {confidence:.2f}%."
48
  return result
49
 
 
 
50
  iface = gr.Interface(
51
  fn=predict_voice,
52
+ inputs=gr.Audio(type="filepath", label="Upload Audio File"), # Ensure filepath is passed
53
  outputs=gr.Textbox(label="Prediction"),
54
  title="Voice Authenticity Detection",
55
  description="Detects whether a voice is real or AI-generated. Upload an audio file to see the results.",