import time import streamlit as st from transformers import pipeline import os import torch import datetime import numpy as np import soundfile from wavmark.utils import file_reader # pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog") # st.title("Hot Dog? Or Not?") # file_name = st.file_uploader("Upload a hot dog candidate image") # if file_name is not None: # col1, col2 = st.columns(2) # image = Image.open(file_name) # col1.image(image, use_column_width=True) # predictions = pipeline(image) # col2.header("Probabilities") # for p in predictions: # col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%") def create_default_value(): if "def_value" not in st.session_state: def_val_npy = np.random.choice([0, 1], size=32 - len_start_bit) def_val_str = "".join([str(i) for i in def_val_npy]) st.session_state.def_value = def_val_str # Main web app def main(): create_default_value() # st.title("MDS07") # st.write("https://github.com/wavmark/wavmark") markdown_text = """ # MDS07 [AudioSeal](https://github.com/jcha0155/AudioSealEnhanced) is the next-generation watermarking tool driven by AI. You can upload an audio file and encode a custom 16-bit watermark or perform decoding from a watermarked audio. This page is for demonstration usage and only process **the first minute** of the audio. If you have longer files for processing, we recommend using [our python toolkit](https://github.com/jcha0155/AudioSealEnhanced). """ # 使用st.markdown渲染Markdown文本 st.markdown(markdown_text) audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3"], accept_multiple_files=False) if audio_file: # 保存文件到本地: tmp_input_audio_file = os.path.join("/tmp/", audio_file.name) with open(tmp_input_audio_file, "wb") as f: f.write(audio_file.getbuffer()) # 展示文件到页面上 # st.audio(tmp_input_audio_file, format="audio/wav") action = st.selectbox("Select Action", ["Add Watermark", "Decode Watermark"]) # if action == "Add Watermark": # watermark_text = st.text_input("The watermark (0, 1 list of length-16):", value=st.session_state.def_value) # add_watermark_button = st.button("Add Watermark", key="add_watermark_btn") # if add_watermark_button: # 点击按钮后执行的 # if audio_file and watermark_text: # with st.spinner("Adding Watermark..."): # watermarked_audio, encode_time_cost = add_watermark(tmp_input_audio_file, watermark_text) # st.write("Watermarked Audio:") # print("watermarked_audio:", watermarked_audio) # st.audio(watermarked_audio, format="audio/wav") # st.write("Time Cost: %d seconds" % encode_time_cost) # # st.button("Add Watermark", disabled=False) # elif action == "Decode Watermark": # if st.button("Decode"): # with st.spinner("Decoding..."): # decode_watermark(tmp_input_audio_file) if __name__ == "__main__": # default_sr = 16000 # max_second_encode = 60 # max_second_decode = 30 # len_start_bit = 16 # device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') # model = wavmark.load_model().to(device) main() # audio_path = "/Users/my/Library/Mobile Documents/com~apple~CloudDocs/CODE/PycharmProjects/4_语音水印/419_huggingface水印/WavMark/example.wav" # decoded_watermark, decode_cost = decode_watermark(audio_path) # print(decoded_watermark)