Spaces:
Runtime error
Runtime error
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() | |