Kabatubare commited on
Commit
1c53cc7
1 Parent(s): 5a8e50c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -1,19 +1,14 @@
1
  import gradio as gr
2
- import torchaudio
3
  from audioseal import AudioSeal
4
  import torch
5
  import numpy as np
6
  import traceback
7
- import logging
8
-
9
- # Set up logging to file in the current directory
10
- logging.basicConfig(filename='app.log', filemode='w', level=logging.DEBUG)
11
 
12
  # Function to handle audio data as NumPy arrays
13
  def detect_watermark(audio_data, sample_rate):
14
  try:
15
  # Extract the audio array from the tuple (audio_data, sample_rate)
16
- audio_array, _ = audio_data # Gradio passes the sample_rate separately, so it's ignored here
17
 
18
  # Ensure audio_array is 2D (channels, samples). If it's mono, add an axis.
19
  if audio_array.ndim == 1:
@@ -24,7 +19,7 @@ def detect_watermark(audio_data, sample_rate):
24
 
25
  # Ensure waveform is 2D (batch, channels, samples) for AudioSeal
26
  if waveform.ndim == 2:
27
- waveform = waveform.unsqueeze(0) # Add batch dimension if necessary
28
 
29
  # Initialize and use the AudioSeal detector
30
  detector = AudioSeal.load_detector("audioseal_detector_16bits")
@@ -34,18 +29,17 @@ def detect_watermark(audio_data, sample_rate):
34
  detection_result = "AI-generated" if result else "genuine"
35
  return f"This audio is likely {detection_result} based on watermark detection."
36
  except Exception as e:
37
- logging.error(f"An error occurred: {e}")
38
  traceback_str = ''.join(traceback.format_tb(e.__traceback__))
39
- logging.error(traceback_str)
40
- return "An error occurred. Please check the log file for details."
41
 
42
- ## Corrected Gradio interface definition
43
  interface = gr.Interface(fn=detect_watermark,
44
  inputs=[gr.Audio(label="Upload your audio", type="numpy"),
45
- gr.Number(label="Sample Rate", value=44100, visible=False)], # Sample rate is now passed but not visible to the user
46
  outputs="text",
47
  title="Deep Fake Defender: AI Voice Cloning Detection",
48
  description="Upload an audio file to check if it's AI-generated or genuine.")
49
 
50
  if __name__ == "__main__":
51
- interface.launch()
 
1
  import gradio as gr
 
2
  from audioseal import AudioSeal
3
  import torch
4
  import numpy as np
5
  import traceback
 
 
 
 
6
 
7
  # Function to handle audio data as NumPy arrays
8
  def detect_watermark(audio_data, sample_rate):
9
  try:
10
  # Extract the audio array from the tuple (audio_data, sample_rate)
11
+ audio_array, _ = audio_data
12
 
13
  # Ensure audio_array is 2D (channels, samples). If it's mono, add an axis.
14
  if audio_array.ndim == 1:
 
19
 
20
  # Ensure waveform is 2D (batch, channels, samples) for AudioSeal
21
  if waveform.ndim == 2:
22
+ waveform = waveform.unsqueeze(0)
23
 
24
  # Initialize and use the AudioSeal detector
25
  detector = AudioSeal.load_detector("audioseal_detector_16bits")
 
29
  detection_result = "AI-generated" if result else "genuine"
30
  return f"This audio is likely {detection_result} based on watermark detection."
31
  except Exception as e:
32
+ error_message = f"An error occurred: {str(e)}"
33
  traceback_str = ''.join(traceback.format_tb(e.__traceback__))
34
+ full_error_message = f"{error_message}\n{traceback_str}"
35
+ return full_error_message
36
 
 
37
  interface = gr.Interface(fn=detect_watermark,
38
  inputs=[gr.Audio(label="Upload your audio", type="numpy"),
39
+ gr.Number(label="Sample Rate", value=44100, visible=False)],
40
  outputs="text",
41
  title="Deep Fake Defender: AI Voice Cloning Detection",
42
  description="Upload an audio file to check if it's AI-generated or genuine.")
43
 
44
  if __name__ == "__main__":
45
+ interface.launch(debug=True)