File size: 1,608 Bytes
f4f5a40
488d50e
f03ec98
e7c7540
811d3ce
dff69a4
e4b1e14
d7a0eb1
a4ace8a
e4b1e14
e7c7540
a4ace8a
 
 
270455b
a4ace8a
d7a0eb1
a4ace8a
 
 
 
 
270455b
a4ace8a
 
 
 
 
105e8bf
a4ace8a
d7a0eb1
811d3ce
105e8bf
811d3ce
a4ace8a
270455b
 
de47a16
270455b
 
 
 
f03ec98
 
faee536
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from audioseal import AudioSeal
import torch
import torchaudio
import traceback

def detect_watermark(audio_file_path):
    try:
        # Load the audio file
        waveform, sample_rate = torchaudio.load(audio_file_path)

        # Ensure waveform has a batch dimension for processing
        if waveform.ndim < 3:
            waveform = waveform.unsqueeze(0)

        # Initialize the AudioSeal detector
        detector = AudioSeal.load_detector("audioseal_detector_16bits")
        
        # Set a conservative threshold for watermark detection
        message_threshold = 0.7  # A higher threshold means more confidence is required to classify as AI-generated
        
        result, confidence = detector.detect_watermark(waveform, message_threshold=message_threshold)

        # Interpret the detection result
        if result:
            detection_result = f"AI-generated with confidence {confidence}"
        else:
            detection_result = "Genuine or the AI watermark is undetectable at the current threshold"

        return f"This audio is likely {detection_result}."
    except Exception as e:
        error_traceback = traceback.format_exc()
        return f"Error occurred: {e}\n\n{error_traceback}"

# Define the Gradio interface
interface = gr.Interface(
    fn=detect_watermark,
    inputs=gr.Audio(label="Upload your audio", type="filepath"),
    outputs="text",
    title="Deep Fake Defender: AI Voice Cloning Detection",
    description="Upload an audio file to check if it's AI-generated or genuine."
)

if __name__ == "__main__":
    interface.launch()