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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -2,13 +2,14 @@ import gradio as gr
2
  from audioseal import AudioSeal
3
  import torch
4
  import torchaudio
 
5
 
6
  def detect_watermark(audio_filepath):
7
  try:
8
  # Load the audio file using torchaudio
9
  waveform, sample_rate = torchaudio.load(audio_filepath)
10
 
11
- # Ensure waveform is 2D (channels, samples). If it's mono, add an axis.
12
  if waveform.ndim == 2:
13
  waveform = waveform.unsqueeze(0) # Add batch dimension
14
 
@@ -19,12 +20,16 @@ def detect_watermark(audio_filepath):
19
  # Interpret and return the detection result
20
  detection_result = "AI-generated" if result else "genuine"
21
  return f"This audio is likely {detection_result} based on watermark detection."
22
-
23
  except Exception as e:
24
- # Return the error message directly
25
- return f"Error occurred: {e}"
26
-
27
- # Define Gradio interface
 
 
 
 
28
  interface = gr.Interface(
29
  fn=detect_watermark,
30
  inputs=gr.Audio(label="Upload your audio", type="filepath"),
@@ -35,4 +40,3 @@ interface = gr.Interface(
35
 
36
  if __name__ == "__main__":
37
  interface.launch()
38
-
 
2
  from audioseal import AudioSeal
3
  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
  # 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"),
 
40
 
41
  if __name__ == "__main__":
42
  interface.launch()