Spaces:
Runtime error
Runtime error
Kabatubare
commited on
Commit
•
a4ace8a
1
Parent(s):
0ea07d6
Update
Browse files
app.py
CHANGED
@@ -6,27 +6,33 @@ import traceback
|
|
6 |
|
7 |
def detect_watermark(audio_file_path):
|
8 |
try:
|
9 |
-
# Load the audio file
|
10 |
waveform, sample_rate = torchaudio.load(audio_file_path)
|
11 |
|
12 |
-
# Ensure waveform
|
13 |
-
if waveform.ndim
|
14 |
-
waveform = waveform.unsqueeze(0)
|
15 |
|
16 |
-
# Initialize
|
17 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
# Interpret
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
|
|
|
24 |
except Exception as e:
|
25 |
-
# Log the error with traceback for debugging
|
26 |
error_traceback = traceback.format_exc()
|
27 |
return f"Error occurred: {e}\n\n{error_traceback}"
|
28 |
|
29 |
-
# Define Gradio interface
|
30 |
interface = gr.Interface(
|
31 |
fn=detect_watermark,
|
32 |
inputs=gr.Audio(label="Upload your audio", type="filepath"),
|
|
|
6 |
|
7 |
def detect_watermark(audio_file_path):
|
8 |
try:
|
9 |
+
# Load the audio file
|
10 |
waveform, sample_rate = torchaudio.load(audio_file_path)
|
11 |
|
12 |
+
# Ensure waveform has a batch dimension for processing
|
13 |
+
if waveform.ndim < 3:
|
14 |
+
waveform = waveform.unsqueeze(0)
|
15 |
|
16 |
+
# Initialize the AudioSeal detector
|
17 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
18 |
+
|
19 |
+
# Set a conservative threshold for watermark detection
|
20 |
+
message_threshold = 0.7 # A higher threshold means more confidence is required to classify as AI-generated
|
21 |
+
|
22 |
+
result, confidence = detector.detect_watermark(waveform, message_threshold=message_threshold)
|
23 |
|
24 |
+
# Interpret the detection result
|
25 |
+
if result:
|
26 |
+
detection_result = f"AI-generated with confidence {confidence}"
|
27 |
+
else:
|
28 |
+
detection_result = "Genuine or the AI watermark is undetectable at the current threshold"
|
29 |
|
30 |
+
return f"This audio is likely {detection_result}."
|
31 |
except Exception as e:
|
|
|
32 |
error_traceback = traceback.format_exc()
|
33 |
return f"Error occurred: {e}\n\n{error_traceback}"
|
34 |
|
35 |
+
# Define the Gradio interface
|
36 |
interface = gr.Interface(
|
37 |
fn=detect_watermark,
|
38 |
inputs=gr.Audio(label="Upload your audio", type="filepath"),
|