Update app.py
Browse files
app.py
CHANGED
@@ -17,4 +17,68 @@ if file_name is not None:
|
|
17 |
|
18 |
col2.header("Probabilities")
|
19 |
for p in predictions:
|
20 |
-
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
col2.header("Probabilities")
|
19 |
for p in predictions:
|
20 |
+
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
21 |
+
|
22 |
+
# Main web app
|
23 |
+
def main():
|
24 |
+
create_default_value()
|
25 |
+
|
26 |
+
# st.title("MDS07")
|
27 |
+
# st.write("https://github.com/wavmark/wavmark")
|
28 |
+
markdown_text = """
|
29 |
+
# MDS07
|
30 |
+
[AudioSeal](https://github.com/jcha0155/AudioSealEnhanced) is the next-generation watermarking tool driven by AI.
|
31 |
+
You can upload an audio file and encode a custom 16-bit watermark or perform decoding from a watermarked audio.
|
32 |
+
|
33 |
+
This page is for demonstration usage and only process **the first minute** of the audio.
|
34 |
+
If you have longer files for processing, we recommend using [our python toolkit](https://github.com/jcha0155/AudioSealEnhanced).
|
35 |
+
"""
|
36 |
+
|
37 |
+
# 使用st.markdown渲染Markdown文本
|
38 |
+
st.markdown(markdown_text)
|
39 |
+
|
40 |
+
audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3"], accept_multiple_files=False)
|
41 |
+
|
42 |
+
if audio_file:
|
43 |
+
# 保存文件到本地:
|
44 |
+
tmp_input_audio_file = os.path.join("/tmp/", audio_file.name)
|
45 |
+
with open(tmp_input_audio_file, "wb") as f:
|
46 |
+
f.write(audio_file.getbuffer())
|
47 |
+
|
48 |
+
# 展示文件到页面上
|
49 |
+
# st.audio(tmp_input_audio_file, format="audio/wav")
|
50 |
+
|
51 |
+
action = st.selectbox("Select Action", ["Add Watermark", "Decode Watermark"])
|
52 |
+
|
53 |
+
if action == "Add Watermark":
|
54 |
+
watermark_text = st.text_input("The watermark (0, 1 list of length-16):", value=st.session_state.def_value)
|
55 |
+
add_watermark_button = st.button("Add Watermark", key="add_watermark_btn")
|
56 |
+
if add_watermark_button: # 点击按钮后执行的
|
57 |
+
if audio_file and watermark_text:
|
58 |
+
with st.spinner("Adding Watermark..."):
|
59 |
+
watermarked_audio, encode_time_cost = add_watermark(tmp_input_audio_file, watermark_text)
|
60 |
+
st.write("Watermarked Audio:")
|
61 |
+
print("watermarked_audio:", watermarked_audio)
|
62 |
+
st.audio(watermarked_audio, format="audio/wav")
|
63 |
+
st.write("Time Cost: %d seconds" % encode_time_cost)
|
64 |
+
|
65 |
+
# st.button("Add Watermark", disabled=False)
|
66 |
+
elif action == "Decode Watermark":
|
67 |
+
if st.button("Decode"):
|
68 |
+
with st.spinner("Decoding..."):
|
69 |
+
decode_watermark(tmp_input_audio_file)
|
70 |
+
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
default_sr = 16000
|
74 |
+
max_second_encode = 60
|
75 |
+
max_second_decode = 30
|
76 |
+
len_start_bit = 16
|
77 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
78 |
+
model = wavmark.load_model().to(device)
|
79 |
+
main()
|
80 |
+
|
81 |
+
# audio_path = "/Users/my/Library/Mobile Documents/com~apple~CloudDocs/CODE/PycharmProjects/4_语音水印/419_huggingface水印/WavMark/example.wav"
|
82 |
+
|
83 |
+
# decoded_watermark, decode_cost = decode_watermark(audio_path)
|
84 |
+
# print(decoded_watermark)
|