Kabatubare
commited on
Commit
•
bf69504
1
Parent(s):
e0a67a5
Update app.py
Browse files
app.py
CHANGED
@@ -55,15 +55,20 @@ def watermark_audio(audio_file_path, unique_message):
|
|
55 |
return temp_file.name, hex_message # Display hex message to the user
|
56 |
|
57 |
# Function to detect watermark in audio
|
58 |
-
def detect_watermark(audio_file_path):
|
59 |
waveform, sample_rate = load_and_resample_audio(audio_file_path, target_sample_rate=16000)
|
60 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
61 |
|
62 |
result, message_tensor = detector.detect_watermark(waveform.unsqueeze(0), sample_rate=sample_rate)
|
63 |
binary_message = ''.join(str(bit) for bit in message_tensor[0].tolist())
|
64 |
-
|
65 |
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
# Setup for Gradio interface
|
69 |
style_path = Path("style.css")
|
@@ -84,9 +89,11 @@ with gr.Blocks(css=style) as demo:
|
|
84 |
with gr.Tab("Detect Watermark"):
|
85 |
with gr.Column(scale=6):
|
86 |
audio_input_detect_watermark = gr.Audio(label="Upload Audio File for Watermark Detection", type="filepath")
|
|
|
87 |
detect_watermark_button = gr.Button("Detect Watermark")
|
88 |
watermark_detection_output = gr.Textbox(label="Watermark Detection Result")
|
89 |
-
detected_message_output = gr.Textbox(label="Detected
|
90 |
-
|
|
|
91 |
|
92 |
-
demo.launch()
|
|
|
55 |
return temp_file.name, hex_message # Display hex message to the user
|
56 |
|
57 |
# Function to detect watermark in audio
|
58 |
+
def detect_watermark(audio_file_path, original_hex_message=None):
|
59 |
waveform, sample_rate = load_and_resample_audio(audio_file_path, target_sample_rate=16000)
|
60 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
61 |
|
62 |
result, message_tensor = detector.detect_watermark(waveform.unsqueeze(0), sample_rate=sample_rate)
|
63 |
binary_message = ''.join(str(bit) for bit in message_tensor[0].tolist())
|
64 |
+
detected_hex_message = binary_to_hex(binary_message)
|
65 |
|
66 |
+
# Compare the detected message with the original, if provided
|
67 |
+
match_result = "Not compared"
|
68 |
+
if original_hex_message:
|
69 |
+
match_result = "Match" if detected_hex_message == original_hex_message.upper() else "No Match"
|
70 |
+
|
71 |
+
return result, detected_hex_message, match_result
|
72 |
|
73 |
# Setup for Gradio interface
|
74 |
style_path = Path("style.css")
|
|
|
89 |
with gr.Tab("Detect Watermark"):
|
90 |
with gr.Column(scale=6):
|
91 |
audio_input_detect_watermark = gr.Audio(label="Upload Audio File for Watermark Detection", type="filepath")
|
92 |
+
original_hex_input = gr.Textbox(label="Original Hex Message for Comparison", placeholder="Enter the original hex message here")
|
93 |
detect_watermark_button = gr.Button("Detect Watermark")
|
94 |
watermark_detection_output = gr.Textbox(label="Watermark Detection Result")
|
95 |
+
detected_message_output = gr.Textbox(label="Detected Hex Message")
|
96 |
+
match_result_output = gr.Textbox(label="Match Result")
|
97 |
+
detect_watermark_button.click(fn=detect_watermark, inputs=[audio_input_detect_watermark, original_hex_input], outputs=[watermark_detection_output, detected_message_output, match_result_output])
|
98 |
|
99 |
+
demo.launch()
|