Update app.py
Browse files
app.py
CHANGED
|
@@ -101,8 +101,8 @@ def main():
|
|
| 101 |
#Load the WAV file using torchaudio
|
| 102 |
if file_extension in [".wav", ".flac"]:
|
| 103 |
wav, sample_rate = torchaudio.load("test.wav")
|
| 104 |
-
st.markdown("Before unsquueze wav")
|
| 105 |
-
st.markdown(wav)
|
| 106 |
file_extension_ori =".wav"
|
| 107 |
#Unsqueeze for line 176
|
| 108 |
wav= wav.unsqueeze(0)
|
|
@@ -194,49 +194,52 @@ def main():
|
|
| 194 |
elif action == "Detect Watermark":
|
| 195 |
detect_watermark_button = st.button("Detect Watermark", key="detect_watermark_btn")
|
| 196 |
|
| 197 |
-
if audio_file:
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
#print(watermarked_audio.squeeze())
|
| 206 |
-
# squeeze = watermarked_audio.squeeze(1)
|
| 207 |
-
# shape = squeeze.size()
|
| 208 |
|
| 209 |
if detect_watermark_button:
|
| 210 |
with st.spinner("Detecting..."):
|
| 211 |
result, message = detector.detect_watermark(watermarked_audio, sample_rate=default_sr, message_threshold=0.5)
|
|
|
|
| 212 |
st.markdown(result)
|
| 213 |
print(f"\nThis is likely a watermarked audio: {result}")
|
| 214 |
|
| 215 |
# Run on an unwatermarked audio
|
| 216 |
-
tmp_input_audio_file = os.path.join("/tmp/", audio_file.name)
|
| 217 |
-
file_extension = os.path.splitext(tmp_input_audio_file)[1].lower()
|
| 218 |
-
if file_extension in [".wav", ".flac"]:
|
| 219 |
-
with open("test.wav", "wb") as f:
|
| 220 |
-
f.write(audio_file.getbuffer())
|
| 221 |
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
#Load the WAV file using torchaudio
|
| 227 |
-
|
| 228 |
-
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
|
| 239 |
result2, message2 = detector.detect_watermark(wav3, sample_rate=default_sr, message_threshold=0.5)
|
|
|
|
| 240 |
print(f"This is likely an unwatermarked audio: {result2}")
|
| 241 |
st.markdown(result2)
|
| 242 |
|
|
|
|
| 101 |
#Load the WAV file using torchaudio
|
| 102 |
if file_extension in [".wav", ".flac"]:
|
| 103 |
wav, sample_rate = torchaudio.load("test.wav")
|
| 104 |
+
# st.markdown("Before unsquueze wav")
|
| 105 |
+
# st.markdown(wav)
|
| 106 |
file_extension_ori =".wav"
|
| 107 |
#Unsqueeze for line 176
|
| 108 |
wav= wav.unsqueeze(0)
|
|
|
|
| 194 |
elif action == "Detect Watermark":
|
| 195 |
detect_watermark_button = st.button("Detect Watermark", key="detect_watermark_btn")
|
| 196 |
|
| 197 |
+
# if audio_file:
|
| 198 |
+
# #1st attempt
|
| 199 |
+
# watermark = model.get_watermark(wav, default_sr)
|
| 200 |
+
# watermarked_audio = wav + watermark
|
| 201 |
+
# print(watermarked_audio.size())
|
| 202 |
+
# size = watermarked_audio.size()
|
| 203 |
+
# #st.markdown(size)
|
| 204 |
+
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
if detect_watermark_button:
|
| 207 |
with st.spinner("Detecting..."):
|
| 208 |
result, message = detector.detect_watermark(watermarked_audio, sample_rate=default_sr, message_threshold=0.5)
|
| 209 |
+
st.markdown("This is likely a watermarked audio:")
|
| 210 |
st.markdown(result)
|
| 211 |
print(f"\nThis is likely a watermarked audio: {result}")
|
| 212 |
|
| 213 |
# Run on an unwatermarked audio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
+
audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3"], accept_multiple_files=False)
|
| 216 |
+
|
| 217 |
+
if audio_file:
|
| 218 |
+
tmp_input_audio_file = os.path.join("/tmp/", audio_file.name)
|
| 219 |
+
file_extension = os.path.splitext(tmp_input_audio_file)[1].lower()
|
| 220 |
+
if file_extension in [".wav", ".flac"]:
|
| 221 |
+
with open("test.wav", "wb") as f:
|
| 222 |
+
f.write(audio_file.getbuffer())
|
| 223 |
+
|
| 224 |
+
elif file_extension == ".mp3":
|
| 225 |
+
with open("test.mp3", "wb") as f:
|
| 226 |
+
f.write(audio_file.getbuffer())
|
| 227 |
|
| 228 |
#Load the WAV file using torchaudio
|
| 229 |
+
if file_extension in [".wav", ".flac"]:
|
| 230 |
+
wav, sample_rate = torchaudio.load("test.wav")
|
| 231 |
|
| 232 |
+
elif file_extension == ".mp3":
|
| 233 |
+
# Load an MP3 file
|
| 234 |
+
audio = AudioSegment.from_mp3("test.mp3")
|
| 235 |
|
| 236 |
+
# Export it as a WAV file
|
| 237 |
+
audio.export("test.wav", format="wav")
|
| 238 |
+
wav3, sample_rate = torchaudio.load("test.wav")
|
| 239 |
+
wav3= wav3.unsqueeze(0)
|
| 240 |
|
| 241 |
result2, message2 = detector.detect_watermark(wav3, sample_rate=default_sr, message_threshold=0.5)
|
| 242 |
+
st.markdown("This is likely an unwatermarked audio:")
|
| 243 |
print(f"This is likely an unwatermarked audio: {result2}")
|
| 244 |
st.markdown(result2)
|
| 245 |
|