Zw07 commited on
Commit
9a62502
·
verified ·
1 Parent(s): f3b99f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -26
app.py CHANGED
@@ -170,6 +170,34 @@ def main():
170
  file_name="output.mp3",
171
  mime="audio/mpeg",
172
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  except RuntimeError:
174
  st.error("Please input audio with one channel (mono-channel)")
175
 
@@ -318,33 +346,33 @@ def main():
318
  # # #st.markdown(size)
319
 
320
 
321
- # if detect_watermark_button:
322
- # with st.spinner("Detecting..."):
323
- # # result, message = detector.detect_watermark(watermarked_audio, sample_rate=default_sr, message_threshold=0.5)
324
- # # st.markdown("Probability of audio being watermarked: ")
325
- # # st.markdown(result)
326
- # # st.markdown("This is likely a watermarked audio!")
327
- # # print(f"\nThis is likely a watermarked audio: {result}")
328
-
329
- # #Run on an unwatermarked audio
330
-
331
- # if file_extension in [".wav", ".flac"]:
332
- # wav, sample_rate = torchaudio.load("test.wav")
333
- # wav= wav.unsqueeze(0)
334
-
335
- # elif file_extension == ".mp3":
336
- # # Load an MP3 file
337
- # audio = AudioSegment.from_mp3("test.mp3")
338
- # # Export it as a WAV file
339
- # audio.export("test.wav", format="wav")
340
- # wav, sample_rate = torchaudio.load("test.wav")
341
- # wav= wav.unsqueeze(0)
342
 
343
- # result2, message2 = detector.detect_watermark(wav, sample_rate=default_sr, message_threshold=0.5)
344
- # print(f"This is likely an unwatermarked audio: {result2}")
345
- # st.markdown("Probability of audio being watermarked: ")
346
- # st.markdown(result2)
347
- # st.markdown("This is likely an unwatermarked audio!")
348
 
349
 
350
  if __name__ == "__main__":
 
170
  file_name="output.mp3",
171
  mime="audio/mpeg",
172
  )
173
+ if detect_watermark_button:
174
+ with st.spinner("Detecting..."):
175
+ # result, message = detector.detect_watermark(watermarked_audio, sample_rate=default_sr, message_threshold=0.5)
176
+ # st.markdown("Probability of audio being watermarked: ")
177
+ # st.markdown(result)
178
+ # st.markdown("This is likely a watermarked audio!")
179
+ # print(f"\nThis is likely a watermarked audio: {result}")
180
+
181
+ #Run on an unwatermarked audio
182
+
183
+ if file_extension in [".wav", ".flac"]:
184
+ wav, sample_rate = torchaudio.load("test.wav")
185
+ wav= wav.unsqueeze(0)
186
+
187
+ elif file_extension == ".mp3":
188
+ # Load an MP3 file
189
+ audio = AudioSegment.from_mp3("test.mp3")
190
+ # Export it as a WAV file
191
+ audio.export("test.wav", format="wav")
192
+ wav, sample_rate = torchaudio.load("test.wav")
193
+ wav= wav.unsqueeze(0)
194
+
195
+ result2, message2 = detector.detect_watermark(wav, sample_rate=default_sr, message_threshold=0.5)
196
+ print(f"This is likely an unwatermarked audio: {result2}")
197
+ st.markdown("Probability of audio being watermarked: ")
198
+ st.markdown(result2)
199
+ st.markdown("This is likely an unwatermarked audio!")
200
+
201
  except RuntimeError:
202
  st.error("Please input audio with one channel (mono-channel)")
203
 
 
346
  # # #st.markdown(size)
347
 
348
 
349
+ if detect_watermark_button:
350
+ with st.spinner("Detecting..."):
351
+ # result, message = detector.detect_watermark(watermarked_audio, sample_rate=default_sr, message_threshold=0.5)
352
+ # st.markdown("Probability of audio being watermarked: ")
353
+ # st.markdown(result)
354
+ # st.markdown("This is likely a watermarked audio!")
355
+ # print(f"\nThis is likely a watermarked audio: {result}")
356
+
357
+ #Run on an unwatermarked audio
358
+
359
+ if file_extension in [".wav", ".flac"]:
360
+ wav, sample_rate = torchaudio.load("test.wav")
361
+ wav= wav.unsqueeze(0)
362
+
363
+ elif file_extension == ".mp3":
364
+ # Load an MP3 file
365
+ audio = AudioSegment.from_mp3("test.mp3")
366
+ # Export it as a WAV file
367
+ audio.export("test.wav", format="wav")
368
+ wav, sample_rate = torchaudio.load("test.wav")
369
+ wav= wav.unsqueeze(0)
370
 
371
+ result2, message2 = detector.detect_watermark(wav, sample_rate=default_sr, message_threshold=0.5)
372
+ print(f"This is likely an unwatermarked audio: {result2}")
373
+ st.markdown("Probability of audio being watermarked: ")
374
+ st.markdown(result2)
375
+ st.markdown("This is likely an unwatermarked audio!")
376
 
377
 
378
  if __name__ == "__main__":