Kabatubare commited on
Commit
105e8bf
1 Parent(s): 811d3ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -4,12 +4,12 @@ import torch
4
  import torchaudio
5
  import traceback
6
 
7
- def detect_watermark(audio_filepath):
8
  try:
9
  # Load the audio file using torchaudio
10
- waveform, sample_rate = torchaudio.load(audio_filepath)
11
 
12
- # Check waveform dimensions and adjust if necessary
13
  if waveform.ndim == 2:
14
  waveform = waveform.unsqueeze(0) # Add batch dimension
15
 
@@ -20,19 +20,16 @@ def detect_watermark(audio_filepath):
20
  # Interpret and return the detection result
21
  detection_result = "AI-generated" if result else "genuine"
22
  return f"This audio is likely {detection_result} based on watermark detection."
23
-
24
  except Exception as e:
25
  # Log the error with traceback for debugging
26
- error_message = f"An error occurred: {str(e)}"
27
  error_traceback = traceback.format_exc()
28
- full_error_message = f"{error_message}\n\n{error_traceback}"
29
- print(full_error_message) # Consider logging to a file if print statements are not visible
30
- return full_error_message
31
 
32
- # Define Gradio interface with "filepath" type for audio input
33
  interface = gr.Interface(
34
  fn=detect_watermark,
35
- inputs=gr.Audio(label="Upload your audio", type="filepath"),
36
  outputs="text",
37
  title="Deep Fake Defender: AI Voice Cloning Detection",
38
  description="Upload an audio file to check if it's AI-generated or genuine."
@@ -40,3 +37,4 @@ interface = gr.Interface(
40
 
41
  if __name__ == "__main__":
42
  interface.launch()
 
 
4
  import torchaudio
5
  import traceback
6
 
7
+ def detect_watermark(audio_file):
8
  try:
9
  # Load the audio file using torchaudio
10
+ waveform, sample_rate = torchaudio.load(audio_file.name) # Use .name attribute for the file path
11
 
12
+ # Ensure waveform is 2D (channels, samples). If it's mono, add an axis.
13
  if waveform.ndim == 2:
14
  waveform = waveform.unsqueeze(0) # Add batch dimension
15
 
 
20
  # Interpret and return the detection result
21
  detection_result = "AI-generated" if result else "genuine"
22
  return f"This audio is likely {detection_result} based on watermark detection."
23
+
24
  except Exception as e:
25
  # Log the error with traceback for debugging
 
26
  error_traceback = traceback.format_exc()
27
+ return f"Error occurred: {e}\n\n{error_traceback}"
 
 
28
 
29
+ # Define Gradio interface with "file" type for audio input
30
  interface = gr.Interface(
31
  fn=detect_watermark,
32
+ inputs=gr.Audio(label="Upload your audio", type="file"),
33
  outputs="text",
34
  title="Deep Fake Defender: AI Voice Cloning Detection",
35
  description="Upload an audio file to check if it's AI-generated or genuine."
 
37
 
38
  if __name__ == "__main__":
39
  interface.launch()
40
+