Spaces:
Runtime error
Runtime error
Kabatubare
commited on
Commit
•
f03ec98
1
Parent(s):
a7c6ced
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,34 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
import torchaudio
|
4 |
from audioseal import AudioSeal
|
5 |
-
|
6 |
-
|
7 |
-
def watermark_audio(file_info):
|
8 |
-
audio, sr = torchaudio.load(file_info)
|
9 |
-
model = AudioSeal.load_generator("audioseal_wm_16bits")
|
10 |
-
audios = audio.unsqueeze(0) # Add batch dimension
|
11 |
-
watermarked_audio = model(audios, alpha=1)
|
12 |
-
output = BytesIO()
|
13 |
-
torchaudio.save(output, watermarked_audio.squeeze(0), sr)
|
14 |
-
output.seek(0)
|
15 |
-
return output, 'audio/wav'
|
16 |
|
|
|
17 |
def detect_watermark(file_info):
|
|
|
18 |
audio, sr = torchaudio.load(file_info)
|
19 |
-
|
|
|
|
|
20 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
21 |
-
result, message = detector.detect_watermark(audios, message_threshold=0.5)
|
22 |
-
return f"Watermark Detected: {result}, Message: {message.numpy()}"
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
-
demo.launch()
|
40 |
|
|
|
1 |
+
# Import necessary libraries
|
2 |
import gradio as gr
|
|
|
3 |
import torchaudio
|
4 |
from audioseal import AudioSeal
|
5 |
+
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Function to detect watermarks in the audio and determine if it's AI-generated
|
8 |
def detect_watermark(file_info):
|
9 |
+
# Load the audio file from the uploaded file
|
10 |
audio, sr = torchaudio.load(file_info)
|
11 |
+
audio = audio.unsqueeze(0) # Add batch dimension as expected by the AudioSeal detector
|
12 |
+
|
13 |
+
# Initialize the AudioSeal detector
|
14 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
|
|
|
|
15 |
|
16 |
+
# Detect watermarks in the audio
|
17 |
+
result, message = detector.detect_watermark(audio, message_threshold=0.5)
|
18 |
+
|
19 |
+
# Interpret the detection result
|
20 |
+
detection_result = "AI-generated" if result else "genuine"
|
21 |
+
return f"This audio is likely {detection_result} based on watermark detection."
|
22 |
+
|
23 |
+
# Define Gradio interface
|
24 |
+
interface = gr.Interface(fn=detect_watermark,
|
25 |
+
inputs=gr.Audio(source="upload", type="file", label="Upload your audio"),
|
26 |
+
outputs="text",
|
27 |
+
title="Deep Fake Defender: AI Voice Cloning Detection",
|
28 |
+
description="Upload an audio file to check if it's AI-generated or genuine.")
|
29 |
+
|
30 |
+
# Launch the Gradio app
|
31 |
+
if __name__ == "__main__":
|
32 |
+
interface.launch()
|
33 |
|
|
|
34 |
|