Zw07 commited on
Commit
cc1bad4
1 Parent(s): 711ccaa

Create app.py

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