Kabatubare commited on
Commit
dff69a4
1 Parent(s): df940fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -3,31 +3,28 @@ import torchaudio
3
  from audioseal import AudioSeal
4
  import torch
5
  from io import BytesIO
 
 
 
 
 
 
 
6
 
7
- # Adjusted function to handle Gradio's file input correctly
8
- def detect_watermark(file_info):
9
- # Gradio passes the uploaded file as a tuple of (filename, fileobject)
10
- _, file_object = file_info
11
-
12
- # Use BytesIO object for compatibility with torchaudio.load
13
- audio, sr = torchaudio.load(file_object)
14
- audio = audio.unsqueeze(0) # Add batch dimension
15
-
16
  # Initialize and use the AudioSeal detector
17
  detector = AudioSeal.load_detector("audioseal_detector_16bits")
18
- result, message = detector.detect_watermark(audio, message_threshold=0.5)
19
 
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
- # Updated Gradio interface without the 'source' keyword argument
25
  interface = gr.Interface(fn=detect_watermark,
26
- inputs=gr.Audio(type="file", label="Upload your audio"),
27
  outputs="text",
28
  title="Deep Fake Defender: AI Voice Cloning Detection",
29
  description="Upload an audio file to check if it's AI-generated or genuine.")
30
 
31
  if __name__ == "__main__":
32
  interface.launch()
33
-
 
3
  from audioseal import AudioSeal
4
  import torch
5
  from io import BytesIO
6
+ import numpy as np
7
+
8
+ # Function to handle audio data as NumPy arrays
9
+ def detect_watermark(audio_data, sample_rate):
10
+ # Convert NumPy array to tensor
11
+ waveform = torch.tensor(audio_data, dtype=torch.float32)
12
+ waveform = waveform.unsqueeze(0) # Add batch dimension if necessary
13
 
 
 
 
 
 
 
 
 
 
14
  # Initialize and use the AudioSeal detector
15
  detector = AudioSeal.load_detector("audioseal_detector_16bits")
16
+ result, message = detector.detect_watermark(waveform, message_threshold=0.5)
17
 
18
  # Interpret and return the detection result
19
  detection_result = "AI-generated" if result else "genuine"
20
  return f"This audio is likely {detection_result} based on watermark detection."
21
 
22
+ # Define Gradio interface with adjusted input to handle NumPy arrays
23
  interface = gr.Interface(fn=detect_watermark,
24
+ inputs=[gr.Audio(label="Upload your audio", type="numpy"), gr.Number(label="Sample Rate", default=44100)],
25
  outputs="text",
26
  title="Deep Fake Defender: AI Voice Cloning Detection",
27
  description="Upload an audio file to check if it's AI-generated or genuine.")
28
 
29
  if __name__ == "__main__":
30
  interface.launch()