Spaces:
Runtime error
Runtime error
import gradio as gr | |
from audioseal import AudioSeal | |
import torch | |
import numpy as np | |
import traceback | |
def detect_watermark(audio_data, sample_rate): | |
try: | |
audio_array, _ = audio_data | |
if audio_array.ndim == 1: | |
audio_array = np.expand_dims(audio_array, axis=0) | |
waveform = torch.tensor(audio_array, dtype=torch.float32) | |
if waveform.ndim == 2: | |
waveform = waveform.unsqueeze(0) | |
detector = AudioSeal.load_detector("audioseal_detector_16bits") | |
result, message = detector.detect_watermark(waveform, message_threshold=0.5) | |
detection_result = "AI-generated" if result else "genuine" | |
return f"This audio is likely {detection_result} based on watermark detection." | |
except Exception as e: | |
error_traceback = traceback.format_exc() | |
return f"Error: {str(e)}\n{error_traceback}" | |
interface = gr.Interface(fn=detect_watermark, | |
inputs=[gr.Audio(label="Upload your audio", type="numpy"), | |
gr.Number(label="Sample Rate", value=44100, visible=False)], | |
outputs="text") | |
if __name__ == "__main__": | |
interface.launch() | |