import torch
from transformers import AutoModelForQuestionAnswering
from datasets import load_dataset
from transformers import AutoTokenizer, pipeline
from tqdm.auto import tqdm
import numpy as np
import collections
import evaluate
import torch
from datasets import load_dataset
from transformers import AutoTokenizer, pipeline
from evaluate import load
from scipy.io.wavfile import write
from transformers.models.whisper.english_normalizer import BasicTextNormalizer
from tqdm import tqdm
from transformers.pipelines.pt_utils import KeyDataset
from utils import *
import wavmark
from wavmark.utils import file_reader


class NNWProof():
    Answer = None
    ##
    Proof = False

    def funcNNWProof(self, input):
        '''
        Verify the inference
        '''

        payload = [0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,1]
        model = wavmark.load_model().to(device)
        signal = file_reader.read_as_single_channel(input, aim_sr=16000)
        # 5.decode watermark
        payload_decoded, _ = wavmark.decode_watermark(model, signal, show_progress=True)
        if isinstance(payload_decoded,type(None)): return False
        BER=(payload != payload_decoded).mean() * 100
        return BER==0

    def run(self):
        self.Proof = self.funcNNWProof(self.Answer)