import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'NeuralSeq'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'text_to_audio/Make_An_Audio'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'audio_detection'))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mono2binaural'))
import gradio as gr
import matplotlib
import librosa
import torch
from langchain.agents.initialize import initialize_agent
from langchain.agents.tools import Tool
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.llms.openai import OpenAI
import re
import uuid
import soundfile
from PIL import Image
import numpy as np
from omegaconf import OmegaConf
from einops import repeat
from ldm.util import instantiate_from_config
from ldm.data.extract_mel_spectrogram import TRANSFORMS_16000
from vocoder.bigvgan.models import VocoderBigVGAN
from ldm.models.diffusion.ddim import DDIMSampler
import whisper
from utils.hparams import set_hparams
from utils.hparams import hparams as hp
import scipy.io.wavfile as wavfile
import librosa
from audio_infer.utils import config as detection_config
from audio_infer.pytorch.models import PVT
import clip
import numpy as np
AUDIO_CHATGPT_PREFIX = """AudioGPT
AudioGPT can not directly read audios, but it has a list of tools to finish different speech, audio, and singing voice tasks. Each audio will have a file name formed as "audio/xxx.wav". When talking about audios, AudioGPT is very strict to the file name and will never fabricate nonexistent files. 
AudioGPT is able to use tools in a sequence, and is loyal to the tool observation outputs rather than faking the audio content and audio file name. It will remember to provide the file name from the last tool observation, if a new audio is generated.
Human may provide new audios to AudioGPT with a description. The description helps AudioGPT to understand this audio, but AudioGPT should use tools to finish following tasks, rather than directly imagine from the description.
Overall, AudioGPT is a powerful audio dialogue assistant tool that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. 

TOOLS:
------

AudioGPT has access to the following tools:"""

AUDIO_CHATGPT_FORMAT_INSTRUCTIONS = """To use a tool, please use the following format:

```
Thought: Do I need to use a tool? Yes
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
```

When you have a response to say to the Human, or if you do not need to use a tool, you MUST use the format:

```
Thought: Do I need to use a tool? No
{ai_prefix}: [your response here]
```
"""

AUDIO_CHATGPT_SUFFIX = """You are very strict to the filename correctness and will never fake a file name if not exists.
You will remember to provide the audio file name loyally if it's provided in the last tool observation.

Begin!

Previous conversation history:
{chat_history}
New input: {input}
Thought: Do I need to use a tool? {agent_scratchpad}"""



def cut_dialogue_history(history_memory, keep_last_n_words = 500):
    tokens = history_memory.split()
    n_tokens = len(tokens)
    print(f"history_memory:{history_memory}, n_tokens: {n_tokens}")
    if n_tokens < keep_last_n_words:
        return history_memory
    else:
        paragraphs = history_memory.split('\n')
        last_n_tokens = n_tokens
        while last_n_tokens >= keep_last_n_words:
            last_n_tokens = last_n_tokens - len(paragraphs[0].split(' '))
            paragraphs = paragraphs[1:]
        return '\n' + '\n'.join(paragraphs)


def merge_audio(audio_path_1, audio_path_2):
    merged_signal = []
    sr_1, signal_1 = wavfile.read(audio_path_1)
    sr_2, signal_2 = wavfile.read(audio_path_2)
    merged_signal.append(signal_1)
    merged_signal.append(signal_2)
    merged_signal = np.hstack(merged_signal)
    merged_signal = np.asarray(merged_signal, dtype=np.int16)
    audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
    wavfile.write(audio_filename, sr_2, merged_signal)
    return audio_filename

class T2I:
    def __init__(self, device):
        from transformers import AutoModelForCausalLM, AutoTokenizer
        from diffusers import StableDiffusionPipeline
        from transformers import pipeline
        print("Initializing T2I to %s" % device)
        self.device = device
        self.pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
        self.text_refine_tokenizer = AutoTokenizer.from_pretrained("Gustavosta/MagicPrompt-Stable-Diffusion")
        self.text_refine_model = AutoModelForCausalLM.from_pretrained("Gustavosta/MagicPrompt-Stable-Diffusion")
        self.text_refine_gpt2_pipe = pipeline("text-generation", model=self.text_refine_model, tokenizer=self.text_refine_tokenizer, device=self.device)
        self.pipe.to(device)

    def inference(self, text):
        image_filename = os.path.join('image', str(uuid.uuid4())[0:8] + ".png")
        refined_text = self.text_refine_gpt2_pipe(text)[0]["generated_text"]
        print(f'{text} refined to {refined_text}')
        image = self.pipe(refined_text).images[0]
        image.save(image_filename)
        print(f"Processed T2I.run, text: {text}, image_filename: {image_filename}")
        return image_filename

class ImageCaptioning:
    def __init__(self, device):
        from transformers import BlipProcessor, BlipForConditionalGeneration
        print("Initializing ImageCaptioning to %s" % device)
        self.device = device
        self.processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
        self.model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base").to(self.device)

    def inference(self, image_path):
        inputs = self.processor(Image.open(image_path), return_tensors="pt").to(self.device)
        out = self.model.generate(**inputs)
        captions = self.processor.decode(out[0], skip_special_tokens=True)
        return captions

class T2A:
    def __init__(self, device):
        print("Initializing Make-An-Audio to %s" % device)
        self.device = device
        self.sampler = self._initialize_model('text_to_audio/Make_An_Audio/configs/text_to_audio/txt2audio_args.yaml', 'text_to_audio/Make_An_Audio/useful_ckpts/ta40multi_epoch=000085.ckpt', device=device)
        self.vocoder = VocoderBigVGAN('text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w',device=device)

    def _initialize_model(self, config, ckpt, device):
        config = OmegaConf.load(config)
        model = instantiate_from_config(config.model)
        model.load_state_dict(torch.load(ckpt, map_location='cpu')["state_dict"], strict=False)

        model = model.to(device)
        model.cond_stage_model.to(model.device)
        model.cond_stage_model.device = model.device
        sampler = DDIMSampler(model)
        return sampler

    def txt2audio(self, text, seed = 55, scale = 1.5, ddim_steps = 100, n_samples = 3, W = 624, H = 80):
        SAMPLE_RATE = 16000
        prng = np.random.RandomState(seed)
        start_code = prng.randn(n_samples, self.sampler.model.first_stage_model.embed_dim, H // 8, W // 8)
        start_code = torch.from_numpy(start_code).to(device=self.device, dtype=torch.float32)
        uc = self.sampler.model.get_learned_conditioning(n_samples * [""])
        c = self.sampler.model.get_learned_conditioning(n_samples * [text])
        shape = [self.sampler.model.first_stage_model.embed_dim, H//8, W//8]  # (z_dim, 80//2^x, 848//2^x)
        samples_ddim, _ = self.sampler.sample(S = ddim_steps,
                                            conditioning = c,
                                            batch_size = n_samples,
                                            shape = shape,
                                            verbose = False,
                                            unconditional_guidance_scale = scale,
                                            unconditional_conditioning = uc,
                                            x_T = start_code)

        x_samples_ddim = self.sampler.model.decode_first_stage(samples_ddim)
        x_samples_ddim = torch.clamp((x_samples_ddim+1.0)/2.0, min=0.0, max=1.0) # [0, 1]

        wav_list = []
        for idx,spec in enumerate(x_samples_ddim):
            wav = self.vocoder.vocode(spec)
            wav_list.append((SAMPLE_RATE,wav))
        best_wav = self.select_best_audio(text, wav_list)
        return best_wav

    def select_best_audio(self, prompt, wav_list):
        from wav_evaluation.models.CLAPWrapper import CLAPWrapper
        clap_model = CLAPWrapper('text_to_audio/Make_An_Audio/useful_ckpts/CLAP/CLAP_weights_2022.pth', 'text_to_audio/Make_An_Audio/useful_ckpts/CLAP/config.yml',
                                 use_cuda=torch.cuda.is_available())
        text_embeddings = clap_model.get_text_embeddings([prompt])
        score_list = []
        for data in wav_list:
            sr, wav = data
            audio_embeddings = clap_model.get_audio_embeddings([(torch.FloatTensor(wav), sr)], resample=True)
            score = clap_model.compute_similarity(audio_embeddings, text_embeddings,
                                                  use_logit_scale=False).squeeze().cpu().numpy()
            score_list.append(score)
        max_index = np.array(score_list).argmax()
        print(score_list, max_index)
        return wav_list[max_index]

    def inference(self, text, seed = 55, scale = 1.5, ddim_steps = 100, n_samples = 3, W = 624, H = 80):
        melbins,mel_len = 80,624
        with torch.no_grad():
            result = self.txt2audio(
                text = text,
                H = melbins,
                W = mel_len
            )
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        soundfile.write(audio_filename, result[1], samplerate = 16000)
        print(f"Processed T2I.run, text: {text}, audio_filename: {audio_filename}")
        return audio_filename

class I2A:
    def __init__(self, device):
        print("Initializing Make-An-Audio-Image to %s" % device)
        self.device = device
        self.sampler = self._initialize_model('text_to_audio/Make_An_Audio/configs/img_to_audio/img2audio_args.yaml', 'text_to_audio/Make_An_Audio/useful_ckpts/ta54_epoch=000216.ckpt', device=device)
        self.vocoder = VocoderBigVGAN('text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w',device=device)

    def _initialize_model(self, config, ckpt, device):
        config = OmegaConf.load(config)
        model = instantiate_from_config(config.model)
        model.load_state_dict(torch.load(ckpt, map_location='cpu')["state_dict"], strict=False)

        model = model.to(device)
        model.cond_stage_model.to(model.device)
        model.cond_stage_model.device = model.device
        sampler = DDIMSampler(model)
        return sampler

    def img2audio(self, image, seed = 55, scale = 3, ddim_steps = 100, W = 624, H = 80):
        SAMPLE_RATE = 16000
        n_samples = 1 # only support 1 sample
        prng = np.random.RandomState(seed)
        start_code = prng.randn(n_samples, self.sampler.model.first_stage_model.embed_dim, H // 8, W // 8)
        start_code = torch.from_numpy(start_code).to(device=self.device, dtype=torch.float32)
        uc = self.sampler.model.get_learned_conditioning(n_samples * [""])
        #image = Image.fromarray(image)
        image = Image.open(image)
        image = self.sampler.model.cond_stage_model.preprocess(image).unsqueeze(0)
        image_embedding = self.sampler.model.cond_stage_model.forward_img(image)
        c = image_embedding.repeat(n_samples, 1, 1)
        shape = [self.sampler.model.first_stage_model.embed_dim, H//8, W//8]  # (z_dim, 80//2^x, 848//2^x)
        samples_ddim, _ = self.sampler.sample(S=ddim_steps,
                                            conditioning=c,
                                            batch_size=n_samples,
                                            shape=shape,
                                            verbose=False,
                                            unconditional_guidance_scale=scale,
                                            unconditional_conditioning=uc,
                                            x_T=start_code)

        x_samples_ddim = self.sampler.model.decode_first_stage(samples_ddim)
        x_samples_ddim = torch.clamp((x_samples_ddim+1.0)/2.0, min=0.0, max=1.0) # [0, 1]
        wav_list = []
        for idx,spec in enumerate(x_samples_ddim):
            wav = self.vocoder.vocode(spec)
            wav_list.append((SAMPLE_RATE,wav))
        best_wav = wav_list[0]
        return best_wav
    def inference(self, image, seed = 55, scale = 3, ddim_steps = 100, W = 624, H = 80):
        melbins,mel_len = 80,624
        with torch.no_grad():
            result = self.img2audio(
                image=image,
                H=melbins,
                W=mel_len
            )
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        soundfile.write(audio_filename, result[1], samplerate = 16000)
        print(f"Processed I2a.run, image_filename: {image}, audio_filename: {audio_filename}")
        return audio_filename

class TTS:
    def __init__(self, device=None):
        from inference.tts.PortaSpeech import TTSInference
        if device is None:
            device = 'cuda' if torch.cuda.is_available() else 'cpu'
        print("Initializing PortaSpeech to %s" % device)
        self.device = device
        self.exp_name = 'checkpoints/ps_adv_baseline'
        self.set_model_hparams()
        self.inferencer = TTSInference(self.hp, device)

    def set_model_hparams(self):
        set_hparams(exp_name=self.exp_name, print_hparams=False)
        self.hp = hp

    def inference(self, text):
        self.set_model_hparams()
        inp = {"text": text}
        out = self.inferencer.infer_once(inp)
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        soundfile.write(audio_filename, out, samplerate=22050)
        return audio_filename

class T2S:
    def __init__(self, device= None):
        from inference.svs.ds_e2e import DiffSingerE2EInfer
        if device is None:
            device = 'cuda' if torch.cuda.is_available() else 'cpu'
        print("Initializing DiffSinger to %s" % device)
        self.device = device
        self.exp_name = 'checkpoints/0831_opencpop_ds1000'
        self.config= 'NeuralSeq/egs/egs_bases/svs/midi/e2e/opencpop/ds1000.yaml'
        self.set_model_hparams()
        self.pipe = DiffSingerE2EInfer(self.hp, device)
        self.default_inp = {
            'text': '你 说 你 不 SP 懂 为 何 在 这 时 牵 手 AP',
            'notes': 'D#4/Eb4 | D#4/Eb4 | D#4/Eb4 | D#4/Eb4 | rest | D#4/Eb4 | D4 | D4 | D4 | D#4/Eb4 | F4 | D#4/Eb4 | D4 | rest',
            'notes_duration': '0.113740 | 0.329060 | 0.287950 | 0.133480 | 0.150900 | 0.484730 | 0.242010 | 0.180820 | 0.343570 | 0.152050 | 0.266720 | 0.280310 | 0.633300 | 0.444590'
        }

    def set_model_hparams(self):
        set_hparams(config=self.config, exp_name=self.exp_name, print_hparams=False)
        self.hp = hp

    def inference(self, inputs):
        self.set_model_hparams()
        val = inputs.split(",")
        key = ['text', 'notes', 'notes_duration']
        try:
            inp = {k: v for k, v in zip(key, val)}
            wav = self.pipe.infer_once(inp)
        except:
            print('Error occurs. Generate default audio sample.\n')
            inp = self.default_inp
            wav = self.pipe.infer_once(inp)
        #if inputs == '' or len(val) < len(key):
        #    inp = self.default_inp
        #else:
        #    inp = {k:v for k,v in zip(key,val)}
        #wav = self.pipe.infer_once(inp)
        wav *= 32767
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        wavfile.write(audio_filename, self.hp['audio_sample_rate'], wav.astype(np.int16))
        print(f"Processed T2S.run, audio_filename: {audio_filename}")
        return audio_filename

class t2s_VISinger:
    def __init__(self, device=None):
        from espnet2.bin.svs_inference import SingingGenerate
        if device is None:
            device = 'cuda' if torch.cuda.is_available() else 'cpu'
        print("Initializing VISingere to %s" % device)
        tag = 'AQuarterMile/opencpop_visinger1'
        self.model = SingingGenerate.from_pretrained(
            model_tag=str_or_none(tag),
            device=device,
        )
        phn_dur = [[0.        , 0.219     ],
            [0.219     , 0.50599998],
            [0.50599998, 0.71399999],
            [0.71399999, 1.097     ],
            [1.097     , 1.28799999],
            [1.28799999, 1.98300004],
            [1.98300004, 7.10500002],
            [7.10500002, 7.60400009]]
        phn = ['sh', 'i', 'q', 'v', 'n', 'i', 'SP', 'AP']
        score = [[0, 0.50625, 'sh_i', 58, 'sh_i'], [0.50625, 1.09728, 'q_v', 56, 'q_v'], [1.09728, 1.9832100000000001, 'n_i', 53, 'n_i'], [1.9832100000000001, 7.105360000000001, 'SP', 0, 'SP'], [7.105360000000001, 7.604390000000001, 'AP', 0, 'AP']]
        tempo = 70
        tmp = {}
        tmp["label"] = phn_dur, phn
        tmp["score"] = tempo, score
        self.default_inp = tmp

    def inference(self, inputs):
        val = inputs.split(",")
        key = ['text', 'notes', 'notes_duration']
        try: # TODO: input will be update
            inp = {k: v for k, v in zip(key, val)}
            wav = self.model(text=inp)["wav"]
        except:
            print('Error occurs. Generate default audio sample.\n')
            inp = self.default_inp
            wav = self.model(text=inp)["wav"]

        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        soundfile.write(audio_filename, wav, samplerate=self.model.fs)
        return audio_filename

class TTS_OOD:
    def __init__(self, device):
        from inference.tts.GenerSpeech import GenerSpeechInfer
        if device is None:
            device = 'cuda' if torch.cuda.is_available() else 'cpu'
        print("Initializing GenerSpeech to %s" % device)
        self.device = device
        self.exp_name = 'checkpoints/GenerSpeech'
        self.config = 'NeuralSeq/modules/GenerSpeech/config/generspeech.yaml'
        self.set_model_hparams()
        self.pipe = GenerSpeechInfer(self.hp, device)

    def set_model_hparams(self):
        set_hparams(config=self.config, exp_name=self.exp_name, print_hparams=False)
        f0_stats_fn = f'{hp["binary_data_dir"]}/train_f0s_mean_std.npy'
        if os.path.exists(f0_stats_fn):
            hp['f0_mean'], hp['f0_std'] = np.load(f0_stats_fn)
            hp['f0_mean'] = float(hp['f0_mean'])
            hp['f0_std'] = float(hp['f0_std'])
        hp['emotion_encoder_path'] = 'checkpoints/Emotion_encoder.pt'
        self.hp = hp

    def inference(self, inputs):
        self.set_model_hparams()
        key = ['ref_audio', 'text']
        val = inputs.split(",")
        inp = {k: v for k, v in zip(key, val)}
        wav = self.pipe.infer_once(inp)
        wav *= 32767
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        wavfile.write(audio_filename, self.hp['audio_sample_rate'], wav.astype(np.int16))
        print(
            f"Processed GenerSpeech.run. Input text:{val[1]}. Input reference audio: {val[0]}. Output Audio_filename: {audio_filename}")
        return audio_filename

class Inpaint:
    def __init__(self, device):
        print("Initializing Make-An-Audio-inpaint to %s" % device)
        self.device = device
        self.sampler = self._initialize_model_inpaint('text_to_audio/Make_An_Audio/configs/inpaint/txt2audio_args.yaml', 'text_to_audio/Make_An_Audio/useful_ckpts/inpaint7_epoch00047.ckpt')
        self.vocoder = VocoderBigVGAN('text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w',device=device)
        self.cmap_transform = matplotlib.cm.viridis

    def _initialize_model_inpaint(self, config, ckpt):
        config = OmegaConf.load(config)
        model = instantiate_from_config(config.model)
        model.load_state_dict(torch.load(ckpt, map_location='cpu')["state_dict"], strict=False)
        device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
        model = model.to(device)
        print(model.device, device, model.cond_stage_model.device)
        sampler = DDIMSampler(model)
        return sampler

    def make_batch_sd(self, mel, mask, num_samples=1):

        mel = torch.from_numpy(mel)[None,None,...].to(dtype=torch.float32)
        mask = torch.from_numpy(mask)[None,None,...].to(dtype=torch.float32)
        masked_mel = (1 - mask) * mel

        mel = mel * 2 - 1
        mask = mask * 2 - 1
        masked_mel = masked_mel * 2 -1

        batch = {
             "mel": repeat(mel.to(device=self.device), "1 ... -> n ...", n=num_samples),
             "mask": repeat(mask.to(device=self.device), "1 ... -> n ...", n=num_samples),
             "masked_mel": repeat(masked_mel.to(device=self.device), "1 ... -> n ...", n=num_samples),
        }
        return batch
    def gen_mel(self, input_audio_path):
        SAMPLE_RATE = 16000
        sr, ori_wav = wavfile.read(input_audio_path)
        print("gen_mel")
        print(sr,ori_wav.shape,ori_wav)
        ori_wav = ori_wav.astype(np.float32, order='C') / 32768.0
        if len(ori_wav.shape)==2:# stereo
            ori_wav = librosa.to_mono(ori_wav.T)
        print(sr,ori_wav.shape,ori_wav)
        ori_wav = librosa.resample(ori_wav,orig_sr = sr,target_sr = SAMPLE_RATE)

        mel_len,hop_size = 848,256
        input_len = mel_len * hop_size
        if len(ori_wav) < input_len:
            input_wav = np.pad(ori_wav,(0,mel_len*hop_size),constant_values=0)
        else:
            input_wav = ori_wav[:input_len]

        mel = TRANSFORMS_16000(input_wav)
        return mel
    def gen_mel_audio(self, input_audio):
        SAMPLE_RATE = 16000
        sr,ori_wav = input_audio
        print("gen_mel_audio")
        print(sr,ori_wav.shape,ori_wav)

        ori_wav = ori_wav.astype(np.float32, order='C') / 32768.0
        if len(ori_wav.shape)==2:# stereo
            ori_wav = librosa.to_mono(ori_wav.T)
        print(sr,ori_wav.shape,ori_wav)
        ori_wav = librosa.resample(ori_wav,orig_sr = sr,target_sr = SAMPLE_RATE)

        mel_len,hop_size = 848,256
        input_len = mel_len * hop_size
        if len(ori_wav) < input_len:
            input_wav = np.pad(ori_wav,(0,mel_len*hop_size),constant_values=0)
        else:
            input_wav = ori_wav[:input_len]
        mel = TRANSFORMS_16000(input_wav)
        return mel
    def show_mel_fn(self, input_audio_path):
        crop_len = 500
        crop_mel = self.gen_mel(input_audio_path)[:,:crop_len]
        color_mel = self.cmap_transform(crop_mel)
        image = Image.fromarray((color_mel*255).astype(np.uint8))
        image_filename = os.path.join('image', str(uuid.uuid4())[0:8] + ".png")
        image.save(image_filename)
        return image_filename
    def inpaint(self, batch, seed, ddim_steps, num_samples=1, W=512, H=512):
        model = self.sampler.model

        prng = np.random.RandomState(seed)
        start_code = prng.randn(num_samples, model.first_stage_model.embed_dim, H // 8, W // 8)
        start_code = torch.from_numpy(start_code).to(device=self.device, dtype=torch.float32)

        c = model.get_first_stage_encoding(model.encode_first_stage(batch["masked_mel"]))
        cc = torch.nn.functional.interpolate(batch["mask"],
                                                size=c.shape[-2:])
        c = torch.cat((c, cc), dim=1) # (b,c+1,h,w) 1 is mask

        shape = (c.shape[1]-1,)+c.shape[2:]
        samples_ddim, _ = self.sampler.sample(S=ddim_steps,
                                            conditioning=c,
                                            batch_size=c.shape[0],
                                            shape=shape,
                                            verbose=False)
        x_samples_ddim = model.decode_first_stage(samples_ddim)


        mel = torch.clamp((batch["mel"]+1.0)/2.0,min=0.0, max=1.0)
        mask = torch.clamp((batch["mask"]+1.0)/2.0,min=0.0, max=1.0)
        predicted_mel = torch.clamp((x_samples_ddim+1.0)/2.0,min=0.0, max=1.0)
        inpainted = (1-mask)*mel+mask*predicted_mel
        inpainted = inpainted.cpu().numpy().squeeze()
        inapint_wav = self.vocoder.vocode(inpainted)

        return inpainted, inapint_wav
    def inference(self, input_audio, mel_and_mask, seed = 55, ddim_steps = 100):
        SAMPLE_RATE = 16000
        torch.set_grad_enabled(False)
        mel_img = Image.open(mel_and_mask['image'])
        mask_img = Image.open(mel_and_mask["mask"])
        show_mel = np.array(mel_img.convert("L"))/255
        mask = np.array(mask_img.convert("L"))/255
        mel_bins,mel_len = 80,848
        input_mel = self.gen_mel_audio(input_audio)[:,:mel_len]
        mask = np.pad(mask,((0,0),(0,mel_len-mask.shape[1])),mode='constant',constant_values=0)
        print(mask.shape,input_mel.shape)
        with torch.no_grad():
            batch = self.make_batch_sd(input_mel,mask,num_samples=1)
            inpainted,gen_wav = self.inpaint(
                batch=batch,
                seed=seed,
                ddim_steps=ddim_steps,
                num_samples=1,
                H=mel_bins, W=mel_len
            )
        inpainted = inpainted[:,:show_mel.shape[1]]
        color_mel = self.cmap_transform(inpainted)
        input_len = int(input_audio[1].shape[0] * SAMPLE_RATE / input_audio[0])
        gen_wav = (gen_wav * 32768).astype(np.int16)[:input_len]
        image = Image.fromarray((color_mel*255).astype(np.uint8))
        image_filename = os.path.join('image', str(uuid.uuid4())[0:8] + ".png")
        image.save(image_filename)
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        soundfile.write(audio_filename, gen_wav, samplerate = 16000)
        return image_filename, audio_filename
    
class ASR:
    def __init__(self, device):
        print("Initializing Whisper to %s" % device)
        self.device = device
        self.model = whisper.load_model("base", device=device)

    def inference(self, audio_path):
        audio = whisper.load_audio(audio_path)
        audio = whisper.pad_or_trim(audio)
        mel = whisper.log_mel_spectrogram(audio).to(self.device)
        _, probs = self.model.detect_language(mel)
        options = whisper.DecodingOptions()
        result = whisper.decode(self.model, mel, options)
        return result.text
    def translate_english(self, audio_path):
        audio = self.model.transcribe(audio_path, language='English')
        return audio['text']

class A2T:
    def __init__(self, device):
        from audio_to_text.inference_waveform import AudioCapModel
        print("Initializing Audio-To-Text Model to %s" % device)
        self.device = device
        self.model = AudioCapModel("audio_to_text/audiocaps_cntrstv_cnn14rnn_trm")
    def inference(self, audio_path):
        audio = whisper.load_audio(audio_path)
        caption_text = self.model(audio)
        return caption_text[0]

class GeneFace:
    def __init__(self, device=None):
        print("Initializing GeneFace model to %s" % device)
        from audio_to_face.GeneFace_binding import GeneFaceInfer
        if device is None:
            device = 'cuda' if torch.cuda.is_available() else 'cpu'
        self.device = device
        self.geneface_model = GeneFaceInfer(device)
        print("Loaded GeneFace model")

    def inference(self, audio_path):
        audio_base_name = os.path.basename(audio_path)[:-4]
        out_video_name = audio_path.replace("audio","video").replace(".wav", ".mp4")
        inp = {
            'audio_source_name': audio_path,
            'out_npy_name': f'geneface/tmp/{audio_base_name}.npy',
            'cond_name': f'geneface/tmp/{audio_base_name}.npy',
            'out_video_name': out_video_name,
            'tmp_imgs_dir': f'video/tmp_imgs',
        }
        self.geneface_model.infer_once(inp)
        return out_video_name

class SoundDetection:
    def __init__(self, device):
        self.device = device
        self.sample_rate = 32000
        self.window_size = 1024
        self.hop_size = 320
        self.mel_bins = 64
        self.fmin = 50
        self.fmax = 14000
        self.model_type = 'PVT'
        self.checkpoint_path = 'audio_detection/audio_infer/useful_ckpts/audio_detection.pth'
        self.classes_num = detection_config.classes_num
        self.labels = detection_config.labels
        self.frames_per_second = self.sample_rate // self.hop_size
        # Model = eval(self.model_type)
        self.model = PVT(sample_rate=self.sample_rate, window_size=self.window_size, 
            hop_size=self.hop_size, mel_bins=self.mel_bins, fmin=self.fmin, fmax=self.fmax, 
            classes_num=self.classes_num)
        checkpoint = torch.load(self.checkpoint_path, map_location=self.device)
        self.model.load_state_dict(checkpoint['model'])
        self.model.to(device)

    def inference(self, audio_path):
        # Forward
        (waveform, _) = librosa.core.load(audio_path, sr=self.sample_rate, mono=True)
        waveform = waveform[None, :]    # (1, audio_length)
        waveform = torch.from_numpy(waveform)
        waveform = waveform.to(self.device)
        # Forward
        with torch.no_grad():
            self.model.eval()
            batch_output_dict = self.model(waveform, None)
        framewise_output = batch_output_dict['framewise_output'].data.cpu().numpy()[0]
        """(time_steps, classes_num)"""
        # print('Sound event detection result (time_steps x classes_num): {}'.format(
        #     framewise_output.shape))
        import numpy as np
        import matplotlib.pyplot as plt
        sorted_indexes = np.argsort(np.max(framewise_output, axis=0))[::-1]
        top_k = 10  # Show top results
        top_result_mat = framewise_output[:, sorted_indexes[0 : top_k]]    
        """(time_steps, top_k)"""
        # Plot result    
        stft = librosa.core.stft(y=waveform[0].data.cpu().numpy(), n_fft=self.window_size, 
            hop_length=self.hop_size, window='hann', center=True)
        frames_num = stft.shape[-1]
        fig, axs = plt.subplots(2, 1, sharex=True, figsize=(10, 4))
        axs[0].matshow(np.log(np.abs(stft)), origin='lower', aspect='auto', cmap='jet')
        axs[0].set_ylabel('Frequency bins')
        axs[0].set_title('Log spectrogram')
        axs[1].matshow(top_result_mat.T, origin='upper', aspect='auto', cmap='jet', vmin=0, vmax=1)
        axs[1].xaxis.set_ticks(np.arange(0, frames_num, self.frames_per_second))
        axs[1].xaxis.set_ticklabels(np.arange(0, frames_num / self.frames_per_second))
        axs[1].yaxis.set_ticks(np.arange(0, top_k))
        axs[1].yaxis.set_ticklabels(np.array(self.labels)[sorted_indexes[0 : top_k]])
        axs[1].yaxis.grid(color='k', linestyle='solid', linewidth=0.3, alpha=0.3)
        axs[1].set_xlabel('Seconds')
        axs[1].xaxis.set_ticks_position('bottom')
        plt.tight_layout()
        image_filename = os.path.join('image', str(uuid.uuid4())[0:8] + ".png")
        plt.savefig(image_filename)
        return image_filename

class SoundExtraction:
    def __init__(self, device):
        from sound_extraction.model.LASSNet import LASSNet
        from sound_extraction.utils.stft import STFT
        import torch.nn as nn
        self.device = device
        self.model_file = 'sound_extraction/useful_ckpts/LASSNet.pt'
        self.stft = STFT()

        self.model = nn.DataParallel(LASSNet(device)).to(device)
        checkpoint = torch.load(self.model_file)
        self.model.load_state_dict(checkpoint['model'])
        self.model.eval()

    def inference(self, inputs):
        #key = ['ref_audio', 'text']
        from sound_extraction.utils.wav_io import load_wav, save_wav
        val = inputs.split(",")
        audio_path = val[0] # audio_path, text
        text = val[1]
        waveform = load_wav(audio_path)
        waveform = torch.tensor(waveform).transpose(1,0)
        mixed_mag, mixed_phase = self.stft.transform(waveform)
        text_query = ['[CLS] ' + text]
        mixed_mag = mixed_mag.transpose(2,1).unsqueeze(0).to(self.device)
        est_mask = self.model(mixed_mag, text_query)
        est_mag = est_mask * mixed_mag  
        est_mag = est_mag.squeeze(1)  
        est_mag = est_mag.permute(0, 2, 1) 
        est_wav = self.stft.inverse(est_mag.cpu().detach(), mixed_phase)
        est_wav = est_wav.squeeze(0).squeeze(0).numpy()  
        #est_path = f'output/est{i}.wav'
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        print('audio_filename ', audio_filename)
        save_wav(est_wav, audio_filename)
        return audio_filename


class Binaural:
    def __init__(self, device):
        from src.models import BinauralNetwork
        self.device = device
        self.model_file = 'mono2binaural/useful_ckpts/m2b/binaural_network.net'
        self.position_file = ['mono2binaural/useful_ckpts/m2b/tx_positions.txt',
                              'mono2binaural/useful_ckpts/m2b/tx_positions2.txt',
                              'mono2binaural/useful_ckpts/m2b/tx_positions3.txt',
                              'mono2binaural/useful_ckpts/m2b/tx_positions4.txt',
                              'mono2binaural/useful_ckpts/m2b/tx_positions5.txt']
        self.net = BinauralNetwork(view_dim=7,
                      warpnet_layers=4,
                      warpnet_channels=64,
                      )
        self.net.load_from_file(self.model_file)
        self.sr = 48000
    def inference(self, audio_path):
        mono, sr  = librosa.load(path=audio_path, sr=self.sr, mono=True)
        mono = torch.from_numpy(mono)
        mono = mono.unsqueeze(0)
        import numpy as np
        import random
        rand_int = random.randint(0,4)
        view = np.loadtxt(self.position_file[rand_int]).transpose().astype(np.float32)
        view = torch.from_numpy(view)
        if not view.shape[-1] * 400 == mono.shape[-1]:
            mono = mono[:,:(mono.shape[-1]//400)*400] # 
            if view.shape[1]*400 > mono.shape[1]:
                m_a = view.shape[1] - mono.shape[-1]//400 
                rand_st = random.randint(0,m_a)
                view = view[:,m_a:m_a+(mono.shape[-1]//400)] # 
        # binauralize and save output
        self.net.eval().to(self.device)
        mono, view = mono.to(self.device), view.to(self.device)
        chunk_size = 48000  # forward in chunks of 1s
        rec_field =  1000  # add 1000 samples as "safe bet" since warping has undefined rec. field
        rec_field -= rec_field % 400  # make sure rec_field is a multiple of 400 to match audio and view frequencies
        chunks = [
            {
                "mono": mono[:, max(0, i-rec_field):i+chunk_size],
                "view": view[:, max(0, i-rec_field)//400:(i+chunk_size)//400]
            }
            for i in range(0, mono.shape[-1], chunk_size)
        ]
        for i, chunk in enumerate(chunks):
            with torch.no_grad():
                mono = chunk["mono"].unsqueeze(0)
                view = chunk["view"].unsqueeze(0)
                binaural = self.net(mono, view).squeeze(0)
                if i > 0:
                    binaural = binaural[:, -(mono.shape[-1]-rec_field):]
                chunk["binaural"] = binaural
        binaural = torch.cat([chunk["binaural"] for chunk in chunks], dim=-1)
        binaural = torch.clamp(binaural, min=-1, max=1).cpu()
        #binaural = chunked_forwarding(net, mono, view)
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        import torchaudio
        torchaudio.save(audio_filename, binaural, sr)
        #soundfile.write(audio_filename, binaural, samplerate = 48000)
        print(f"Processed Binaural.run, audio_filename: {audio_filename}")
        return audio_filename

class TargetSoundDetection:
    def __init__(self, device):
        from target_sound_detection.src import models as tsd_models
        from target_sound_detection.src.models import event_labels

        self.device = device
        self.MEL_ARGS = {
            'n_mels': 64,
            'n_fft': 2048,
            'hop_length': int(22050 * 20 / 1000),
            'win_length': int(22050 * 40 / 1000)
        }
        self.EPS = np.spacing(1)
        self.clip_model, _ = clip.load("ViT-B/32", device=self.device)
        self.event_labels = event_labels
        self.id_to_event =  {i : label for i, label in enumerate(self.event_labels)}
        config = torch.load('audio_detection/target_sound_detection/useful_ckpts/tsd/run_config.pth', map_location='cpu')
        config_parameters = dict(config)
        config_parameters['tao'] = 0.6
        if 'thres' not in config_parameters.keys():
            config_parameters['thres'] = 0.5
        if 'time_resolution' not in config_parameters.keys():
            config_parameters['time_resolution'] = 125
        model_parameters = torch.load('audio_detection/target_sound_detection/useful_ckpts/tsd/run_model_7_loss=-0.0724.pt'
                                        , map_location=lambda storage, loc: storage) # load parameter 
        self.model = getattr(tsd_models, config_parameters['model'])(config_parameters,
                    inputdim=64, outputdim=2, time_resolution=config_parameters['time_resolution'], **config_parameters['model_args'])
        self.model.load_state_dict(model_parameters)
        self.model = self.model.to(self.device).eval()
        self.re_embeds = torch.load('audio_detection/target_sound_detection/useful_ckpts/tsd/text_emb.pth')
        self.ref_mel = torch.load('audio_detection/target_sound_detection/useful_ckpts/tsd/ref_mel.pth')

    def extract_feature(self, fname):
        import soundfile as sf
        y, sr = sf.read(fname, dtype='float32')
        print('y ', y.shape)
        ti = y.shape[0]/sr
        if y.ndim > 1:
            y = y.mean(1)
        y = librosa.resample(y, sr, 22050)
        lms_feature = np.log(librosa.feature.melspectrogram(y, **self.MEL_ARGS) + self.EPS).T
        return lms_feature,ti
    
    def build_clip(self, text):
        text = clip.tokenize(text).to(self.device) # ["a diagram with dog", "a dog", "a cat"]
        text_features = self.clip_model.encode_text(text)
        return text_features
    
    def cal_similarity(self, target, retrievals):
        ans = []
        #target =torch.from_numpy(target)
        for name in retrievals.keys():
            tmp = retrievals[name]
            #tmp = torch.from_numpy(tmp)
            s = torch.cosine_similarity(target.squeeze(), tmp.squeeze(), dim=0)
            ans.append(s.item())
        return ans.index(max(ans))
    
    def inference(self, text, audio_path):
        from target_sound_detection.src.utils import median_filter, decode_with_timestamps

        target_emb = self.build_clip(text) # torch type
        idx = self.cal_similarity(target_emb, self.re_embeds)
        target_event = self.id_to_event[idx]
        embedding = self.ref_mel[target_event]
        embedding = torch.from_numpy(embedding)
        embedding = embedding.unsqueeze(0).to(self.device).float()
        #print('embedding ', embedding.shape)
        inputs,ti = self.extract_feature(audio_path)
        #print('ti ', ti)
        inputs = torch.from_numpy(inputs)
        inputs = inputs.unsqueeze(0).to(self.device).float()
        #print('inputs ', inputs.shape)
        decision, decision_up, logit = self.model(inputs, embedding)
        pred = decision_up.detach().cpu().numpy()
        pred = pred[:,:,0]
        frame_num = decision_up.shape[1]
        time_ratio = ti / frame_num
        filtered_pred = median_filter(pred, window_size=1, threshold=0.5)
        #print('filtered_pred ', filtered_pred)
        time_predictions = []
        for index_k in range(filtered_pred.shape[0]):
            decoded_pred = []
            decoded_pred_ = decode_with_timestamps(target_event, filtered_pred[index_k,:])
            if len(decoded_pred_) == 0: # neg deal
                decoded_pred_.append((target_event, 0, 0))
            decoded_pred.append(decoded_pred_)
            for num_batch in range(len(decoded_pred)): # when we test our model,the batch_size is 1
                cur_pred = pred[num_batch]
                # Save each frame output, for later visualization
                label_prediction = decoded_pred[num_batch] # frame predict
                # print(label_prediction)
                for event_label, onset, offset in label_prediction:
                    time_predictions.append({
                        'onset': onset*time_ratio,
                        'offset': offset*time_ratio,})
        ans = ''
        for i,item in enumerate(time_predictions):
            ans = ans + 'segment' + str(i+1) + ' start_time: ' + str(item['onset']) + '  end_time: ' + str(item['offset']) + '\t'
        #print(ans)
        return ans

# class Speech_Enh_SS_SC:
#     """Speech Enhancement or Separation in single-channel
#     Example usage:
#         enh_model = Speech_Enh_SS("cuda")
#         enh_wav = enh_model.inference("./test_chime4_audio_M05_440C0213_PED_REAL.wav")
#     """
#     def __init__(self, device="cuda", model_name="lichenda/chime4_fasnet_dprnn_tac"):
#         self.model_name = model_name
#         self.device = device
#         print("Initializing ESPnet Enh to %s" % device)
#         self._initialize_model()

#     def _initialize_model(self):
#         from espnet_model_zoo.downloader import ModelDownloader
#         from espnet2.bin.enh_inference import SeparateSpeech

#         d = ModelDownloader()

#         cfg = d.download_and_unpack(self.model_name)
#         self.separate_speech = SeparateSpeech(
#             train_config=cfg["train_config"],
#             model_file=cfg["model_file"],
#             # for segment-wise process on long speech
#             segment_size=2.4,
#             hop_size=0.8,
#             normalize_segment_scale=False,
#             show_progressbar=True,
#             ref_channel=None,
#             normalize_output_wav=True,
#             device=self.device,
#         )

#     def inference(self, speech_path, ref_channel=0):
#         speech, sr = soundfile.read(speech_path)
#         speech = speech[:, ref_channel]
#         assert speech.dim() == 1

#         enh_speech = self.separate_speech(speech[None, ], fs=sr)
#         if len(enh_speech) == 1:
#             return enh_speech[0]
#         return enh_speech

# class Speech_Enh_SS_MC:
#     """Speech Enhancement or Separation in multi-channel"""
#     def __init__(self, device="cuda", model_name=None, ref_channel=4):
#         self.model_name = model_name
#         self.ref_channel = ref_channel
#         self.device = device
#         print("Initializing ESPnet Enh to %s" % device)
#         self._initialize_model()

#     def _initialize_model(self):
#         from espnet_model_zoo.downloader import ModelDownloader
#         from espnet2.bin.enh_inference import SeparateSpeech

#         d = ModelDownloader()

#         cfg = d.download_and_unpack(self.model_name)
#         self.separate_speech = SeparateSpeech(
#             train_config=cfg["train_config"],
#             model_file=cfg["model_file"],
#             # for segment-wise process on long speech
#             segment_size=2.4,
#             hop_size=0.8,
#             normalize_segment_scale=False,
#             show_progressbar=True,
#             ref_channel=self.ref_channel,
#             normalize_output_wav=True,
#             device=self.device,
#         )

#     def inference(self, speech_path):
#         speech, sr = soundfile.read(speech_path)
#         speech = speech.T

#         enh_speech = self.separate_speech(speech[None, ...], fs=sr)
#         if len(enh_speech) == 1:
#             return enh_speech[0]
#         return enh_speech

class Speech_Enh_SS_SC:
    """Speech Enhancement or Separation in single-channel
    Example usage:
        enh_model = Speech_Enh_SS("cuda")
        enh_wav = enh_model.inference("./test_chime4_audio_M05_440C0213_PED_REAL.wav")
    """
    def __init__(self, device="cuda", model_name="espnet/Wangyou_Zhang_chime4_enh_train_enh_conv_tasnet_raw"):
        self.model_name = model_name
        self.device = device
        print("Initializing ESPnet Enh to %s" % device)
        self._initialize_model()

    def _initialize_model(self):
        from espnet_model_zoo.downloader import ModelDownloader
        from espnet2.bin.enh_inference import SeparateSpeech

        d = ModelDownloader()

        cfg = d.download_and_unpack(self.model_name)
        self.separate_speech = SeparateSpeech(
            train_config=cfg["train_config"],
            model_file=cfg["model_file"],
            # for segment-wise process on long speech
            segment_size=2.4,
            hop_size=0.8,
            normalize_segment_scale=False,
            show_progressbar=True,
            ref_channel=None,
            normalize_output_wav=True,
            device=self.device,
        )

    def inference(self, speech_path, ref_channel=0):
        speech, sr = soundfile.read(speech_path)
        speech = speech[:, ref_channel]
        # speech = torch.from_numpy(speech)
        # assert speech.dim() == 1
        enh_speech = self.separate_speech(speech[None, ...], fs=sr)
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        # if len(enh_speech) == 1:
        soundfile.write(audio_filename, enh_speech[0].squeeze(), samplerate=sr)
            # return enh_speech[0]
        # return enh_speech
        # else: 
        #     print("############")
        #     audio_filename_1 = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        #     soundfile.write(audio_filename_1, enh_speech[0].squeeze(), samplerate=sr)
        #     audio_filename_2 = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        #     soundfile.write(audio_filename_2, enh_speech[1].squeeze(), samplerate=sr)
        #     audio_filename = merge_audio(audio_filename_1, audio_filename_2)
        return audio_filename

class Speech_SS:
    def __init__(self, device="cuda", model_name="lichenda/wsj0_2mix_skim_noncausal"):
        self.model_name = model_name
        self.device = device
        print("Initializing ESPnet SS to %s" % device)
        self._initialize_model()

    def _initialize_model(self):
        from espnet_model_zoo.downloader import ModelDownloader
        from espnet2.bin.enh_inference import SeparateSpeech

        d = ModelDownloader()

        cfg = d.download_and_unpack(self.model_name)
        self.separate_speech = SeparateSpeech(
            train_config=cfg["train_config"],
            model_file=cfg["model_file"],
            # for segment-wise process on long speech
            segment_size=2.4,
            hop_size=0.8,
            normalize_segment_scale=False,
            show_progressbar=True,
            ref_channel=None,
            normalize_output_wav=True,
            device=self.device,
        )

    def inference(self, speech_path):
        speech, sr = soundfile.read(speech_path)
        enh_speech = self.separate_speech(speech[None, ...], fs=sr)
        audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        if len(enh_speech) == 1:
            soundfile.write(audio_filename, enh_speech[0], samplerate=sr)
        else:
            # print("############")
            audio_filename_1 = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
            soundfile.write(audio_filename_1, enh_speech[0].squeeze(), samplerate=sr)
            audio_filename_2 = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
            soundfile.write(audio_filename_2, enh_speech[1].squeeze(), samplerate=sr)
            audio_filename = merge_audio(audio_filename_1, audio_filename_2)
        return audio_filename

class ConversationBot:
    def __init__(self):
        print("Initializing AudioGPT")
        self.llm = OpenAI(temperature=0)
        self.t2i = T2I(device="cuda:1")
        self.i2t = ImageCaptioning(device="cuda:0")
        self.t2a = T2A(device="cuda:0")
        self.tts = TTS(device="cpu")
        self.t2s = T2S(device="cpu")
        self.i2a = I2A(device="cuda:0")
        self.a2t = A2T(device="cpu")
        self.asr = ASR(device="cuda:0")
        self.SE_SS_SC = Speech_Enh_SS_SC(device="cuda:0")
        # self.SE_SS_MC = Speech_Enh_SS_MC(device="cuda:0")
        self.SS = Speech_SS(device="cuda:0")
        self.inpaint = Inpaint(device="cuda:0")
        self.tts_ood = TTS_OOD(device="cpu")
        self.geneface = GeneFace(device="cuda:0")
        self.detection = SoundDetection(device="cpu")
        self.binaural = Binaural(device="cuda:0")
        self.extraction = SoundExtraction(device="cuda:0")
        self.TSD = TargetSoundDetection(device="cuda:0")
        self.memory = ConversationBufferMemory(memory_key="chat_history", output_key='output')

    def init_tools(self, interaction_type):
        if interaction_type == 'text':
            self.tools = [
                Tool(name="Generate Image From User Input Text", func=self.t2i.inference,
                     description="useful for when you want to generate an image from a user input text and it saved it to a file. like: generate an image of an object or something, or generate an image that includes some objects. "
                                 "The input to this tool should be a string, representing the text used to generate image. "),
                Tool(name="Get Photo Description", func=self.i2t.inference,
                     description="useful for when you want to know what is inside the photo. receives image_path as input. "
                                 "The input to this tool should be a string, representing the image_path. "),
                Tool(name="Generate Audio From User Input Text", func=self.t2a.inference,
                     description="useful for when you want to generate an audio from a user input text and it saved it to a file."
                                 "The input to this tool should be a string, representing the text used to generate audio."),
                Tool(
                    name="Style Transfer", func= self.tts_ood.inference,
                    description="useful for when you want to generate speech samples with styles (e.g., timbre, emotion, and prosody) derived from a reference custom voice."
                                "Like: Generate a speech with style transferred from this voice. The text is xxx., or speak using the voice of this audio. The text is xxx."
                                "The input to this tool should be a comma seperated string of two, representing reference audio path and input text."),
                Tool(name="Generate Singing Voice From User Input Text, Note and Duration Sequence", func= self.t2s.inference,
                     description="useful for when you want to generate a piece of singing voice (Optional: from User Input Text, Note and Duration Sequence) and save it to a file."
                                 "If Like: Generate a piece of singing voice, the input to this tool should be \"\" since there is no User Input Text, Note and Duration Sequence ."
                                 "If Like: Generate a piece of singing voice. Text: xxx, Note: xxx, Duration: xxx. "
                                 "Or Like: Generate a piece of singing voice. Text is xxx, note is xxx, duration is xxx."
                                 "The input to this tool should be a comma seperated string of three, representing text, note and duration sequence since User Input Text, Note and Duration Sequence are all provided."),
                Tool(name="Synthesize Speech Given the User Input Text", func=self.tts.inference,
                     description="useful for when you want to convert a user input text into speech audio it saved it to a file."
                                 "The input to this tool should be a string, representing the text used to be converted to speech."),
                # Tool(name="Speech Enhancement Or Separation In Single-Channel", func=self.SE_SS_SC.inference,
                #      description="useful for when you want to enhance the quality of the speech signal by reducing background noise (single-channel), "
                #                  "or separate each speech from the speech mixture (single-channel), receives audio_path as input."
                #                  "The input to this tool should be a string, representing the audio_path."),
                Tool(name="Speech Enhancement In Single-Channel", func=self.SE_SS_SC.inference,
                     description="useful for when you want to enhance the quality of the speech signal by reducing background noise (single-channel), receives audio_path as input."
                                 "The input to this tool should be a string, representing the audio_path."),
                Tool(name="Speech Separation In Single-Channel", func=self.SS.inference,
                     description="useful for when you want to separate each speech from the speech mixture, receives audio_path as input."
                                 "The input to this tool should be a string, representing the audio_path."),
                # Tool(name="Speech Enhancement In Multi-Channel", func=self.SE_SS_MC.inference,
                #      description="useful for when you want to enhance the quality of the speech signal by reducing background noise (multi-channel), receives audio_path as input."
                #                  "The input to this tool should be a string, representing the audio_path."),                                 
                Tool(name="Generate Audio From The Image", func=self.i2a.inference,
                     description="useful for when you want to generate an audio based on an image."
                                  "The input to this tool should be a string, representing the image_path. "),
                Tool(name="Generate Text From The Audio", func=self.a2t.inference,
                     description="useful for when you want to describe an audio in text, receives audio_path as input."
                                 "The input to this tool should be a string, representing the audio_path."), 
                Tool(name="Audio Inpainting", func=self.inpaint.show_mel_fn,
                     description="useful for when you want to inpaint a mel spectrum of an audio and predict this audio, this tool will generate a mel spectrum and you can inpaint it, receives audio_path as input, "
                                 "The input to this tool should be a string, representing the audio_path."), 
                Tool(name="Transcribe Speech", func=self.asr.inference,
                     description="useful for when you want to know the text corresponding to a human speech, receives audio_path as input."
                                 "The input to this tool should be a string, representing the audio_path."),
                Tool(name="Generate a talking human portrait video given a input Audio", func=self.geneface.inference,
                     description="useful for when you want to generate a talking human portrait video given a input audio."
                                 "The input to this tool should be a string, representing the audio_path."),
                Tool(name="Detect The Sound Event From The Audio", func=self.detection.inference,
                     description="useful for when you want to know what event in the audio and the sound event start or end time, this tool will generate an image of all predict events, receives audio_path as input. "
                                 "The input to this tool should be a string, representing the audio_path. "),
                Tool(name="Sythesize Binaural Audio From A Mono Audio Input", func=self.binaural.inference,
                     description="useful for when you want to transfer your mono audio into binaural audio, receives audio_path as input. "
                                 "The input to this tool should be a string, representing the audio_path. "),
                Tool(name="Extract Sound Event From Mixture Audio Based On Language Description", func=self.extraction.inference,
                     description="useful for when you extract target sound from a mixture audio, you can describe the target sound by text, receives audio_path and text as input. "
                                 "The input to this tool should be a comma seperated string of two, representing mixture audio path and input text."),
                Tool(name="Target Sound Detection", func=self.TSD.inference,
                     description="useful for when you want to know when the target sound event in the audio happens. You can use language descriptions to instruct the model. receives text description and audio_path as input. "
                                 "The input to this tool should be a comma seperated string of two, representing audio path and the text description. ")]       

            self.agent = initialize_agent(
                self.tools,
                self.llm,
                agent="conversational-react-description",
                verbose=True,
                memory=self.memory,
                return_intermediate_steps=True,
                agent_kwargs={'prefix': AUDIO_CHATGPT_PREFIX, 'format_instructions': AUDIO_CHATGPT_FORMAT_INSTRUCTIONS, 'suffix': AUDIO_CHATGPT_SUFFIX}, )

            return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
        else:
            self.tools = [
                Tool(name="Generate Audio From User Input Text", func=self.t2a.inference,
                     description="useful for when you want to generate an audio from a user input text and it saved it to a file."
                                 "The input to this tool should be a string, representing the text used to generate audio."),
                Tool(
                    name="Style Transfer", func= self.tts_ood.inference,
                    description="useful for when you want to generate speech samples with styles (e.g., timbre, emotion, and prosody) derived from a reference custom voice."
                                "Like: Generate a speech with style transferred from this voice. The text is xxx., or speak using the voice of this audio. The text is xxx."
                                "The input to this tool should be a comma seperated string of two, representing reference audio path and input text."),
                Tool(name="Generate Singing Voice From User Input Text, Note and Duration Sequence", func= self.t2s.inference,
                     description="useful for when you want to generate a piece of singing voice (Optional: from User Input Text, Note and Duration Sequence) and save it to a file."
                                 "If Like: Generate a piece of singing voice, the input to this tool should be \"\" since there is no User Input Text, Note and Duration Sequence ."
                                 "If Like: Generate a piece of singing voice. Text: xxx, Note: xxx, Duration: xxx. "
                                 "Or Like: Generate a piece of singing voice. Text is xxx, note is xxx, duration is xxx."
                                 "The input to this tool should be a comma seperated string of three, representing text, note and duration sequence since User Input Text, Note and Duration Sequence are all provided."),
                Tool(name="Synthesize Speech Given the User Input Text", func=self.tts.inference,
                     description="useful for when you want to convert a user input text into speech audio it saved it to a file."
                                 "The input to this tool should be a string, representing the text used to be converted to speech."),
                Tool(name="Generate Text From The Audio", func=self.a2t.inference,
                     description="useful for when you want to describe an audio in text, receives audio_path as input."
                                 "The input to this tool should be a string, representing the audio_path."), 
                Tool(name="Generate a talking human portrait video given a input Audio", func=self.geneface.inference,
                     description="useful for when you want to generate a talking human portrait video given a input audio."
                                 "The input to this tool should be a string, representing the audio_path."),
                Tool(name="Generate Binaural Audio From A Mono Audio Input", func=self.binaural.inference,
                     description="useful for when you want to transfer your mono audio into binaural audio, receives audio_path as input. "
                                 "The input to this tool should be a string, representing the audio_path. "),
                Tool(name="Extract Sound Event From Mixture Audio Based On Language Description", func=self.extraction.inference,
                     description="useful for when you extract target sound from a mixture audio, you can describe the target sound by text, receives audio_path and text as input. "
                                 "The input to this tool should be a comma seperated string of two, representing mixture audio path and input text."),
                Tool(name="Target Sound Detection", func=self.TSD.inference,
                     description="useful for when you want to know when the target sound event in the audio happens. You can use language descriptions to instruct the model. receives text description and audio_path as input. "
                                 "The input to this tool should be a comma seperated string of two, representing audio path and the text description. ")]                
            self.agent = initialize_agent(
                self.tools,
                self.llm,
                agent="conversational-react-description",
                verbose=True,
                memory=self.memory,
                return_intermediate_steps=True,
                agent_kwargs={'prefix': AUDIO_CHATGPT_PREFIX, 'format_instructions': AUDIO_CHATGPT_FORMAT_INSTRUCTIONS, 'suffix': AUDIO_CHATGPT_SUFFIX}, )

            return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)

    def run_text(self, text, state):
        print("===============Running run_text =============")
        print("Inputs:", text, state)
        print("======>Previous memory:\n %s" % self.agent.memory)
        self.agent.memory.buffer = cut_dialogue_history(self.agent.memory.buffer, keep_last_n_words=500)
        res = self.agent({"input": text})
        if res['intermediate_steps'] == []:
            print("======>Current memory:\n %s" % self.agent.memory)
            response = res['output']
            state = state + [(text, response)]
            print("Outputs:", state)
            return state, state, gr.Audio.update(visible=False), gr.Video.update(visible=False), gr.Image.update(visible=False), gr.Button.update(visible=False)
        else:
            tool = res['intermediate_steps'][0][0].tool
            if tool == "Generate Image From User Input Text" or tool == "Generate Text From The Audio" or tool == "Target Sound Detection":
                print("======>Current memory:\n %s" % self.agent.memory)
                response = re.sub('(image/\S*png)', lambda m: f'![](/file={m.group(0)})*{m.group(0)}*', res['output'])
                state = state + [(text, response)]
                print("Outputs:", state)
                return state, state, gr.Audio.update(visible=False), gr.Video.update(visible=False), gr.Image.update(visible=False), gr.Button.update(visible=False)
            elif tool == "Transcribe Speech":
                response = res['output']
                state = state + [(text, response)]
                print("Outputs:", state)
                return state, state, gr.Audio.update(visible=False), gr.Video.update(visible=False), gr.Image.update(visible=False), gr.Button.update(visible=False)
            elif tool == "Detect The Sound Event From The Audio":
                image_filename = res['intermediate_steps'][0][1]
                response = res['output'] + f"![](/file={image_filename})*{image_filename}*"
                state = state + [(text, response)]
                print("Outputs:", state)
                return state, state, gr.Audio.update(visible=False), gr.Video.update(visible=False), gr.Image.update(visible=False), gr.Button.update(visible=False)       
            elif tool == "Audio Inpainting":
                audio_filename = res['intermediate_steps'][0][0].tool_input
                image_filename = res['intermediate_steps'][0][1]
                print("======>Current memory:\n %s" % self.agent.memory)
                response = res['output']
                state = state + [(text, response)]
                print("Outputs:", state)
                return state, state, gr.Audio.update(value=audio_filename,visible=True), gr.Video.update(visible=False), gr.Image.update(value=image_filename,visible=True), gr.Button.update(visible=True)
            elif tool == "Generate a talking human portrait video given a input Audio":
                video_filename = res['intermediate_steps'][0][1]
                print("======>Current memory:\n %s" % self.agent.memory)
                response = res['output'] 
                state = state + [(text, response)]
                print("Outputs:", state)
                return state, state, gr.Audio.update(visible=False), gr.Video.update(value=video_filename,visible=True), gr.Image.update(visible=False), gr.Button.update(visible=False)
            print("======>Current memory:\n %s" % self.agent.memory)
            response = re.sub('(image/\S*png)', lambda m: f'![](/file={m.group(0)})*{m.group(0)}*', res['output'])
            audio_filename = res['intermediate_steps'][0][1]
            state = state + [(text, response)]
            print("Outputs:", state)
            return state, state, gr.Audio.update(value=audio_filename,visible=True), gr.Video.update(visible=False), gr.Image.update(visible=False), gr.Button.update(visible=False)

    def run_image_or_audio(self, file, state, txt):
        file_type = file.name[-3:]
        if file_type == "wav":
            print("===============Running run_audio =============")
            print("Inputs:", file, state)
            print("======>Previous memory:\n %s" % self.agent.memory)
            audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
            # audio_load = whisper.load_audio(file.name)
            audio_load, sr = soundfile.read(file.name)
            soundfile.write(audio_filename, audio_load, samplerate = sr)
            description = self.a2t.inference(audio_filename)
            Human_prompt = "\nHuman: provide an audio named {}. The description is: {}. This information helps you to understand this audio, but you should use tools to finish following tasks, " \
                           "rather than directly imagine from my description. If you understand, say \"Received\". \n".format(audio_filename, description)
            AI_prompt = "Received.  "
            self.agent.memory.buffer = self.agent.memory.buffer + Human_prompt + 'AI: ' + AI_prompt
            print("======>Current memory:\n %s" % self.agent.memory)
            #state = state + [(f"<audio src=audio_filename controls=controls></audio>*{audio_filename}*", AI_prompt)]
            state = state + [(f"*{audio_filename}*", AI_prompt)]
            print("Outputs:", state)
            return state, state, gr.Audio.update(value=audio_filename,visible=True), gr.Video.update(visible=False)
        else:
            print("===============Running run_image =============")
            print("Inputs:", file, state)
            print("======>Previous memory:\n %s" % self.agent.memory)
            image_filename = os.path.join('image', str(uuid.uuid4())[0:8] + ".png")
            print("======>Auto Resize Image...")
            img = Image.open(file.name)
            width, height = img.size
            ratio = min(512 / width, 512 / height)
            width_new, height_new = (round(width * ratio), round(height * ratio))
            img = img.resize((width_new, height_new))
            img = img.convert('RGB')
            img.save(image_filename, "PNG")
            print(f"Resize image form {width}x{height} to {width_new}x{height_new}")
            description = self.i2t.inference(image_filename)
            Human_prompt = "\nHuman: provide a figure named {}. The description is: {}. This information helps you to understand this image, but you should use tools to finish following tasks, " \
                           "rather than directly imagine from my description. If you understand, say \"Received\". \n".format(image_filename, description)
            AI_prompt = "Received.  "
            self.agent.memory.buffer = self.agent.memory.buffer + Human_prompt + 'AI: ' + AI_prompt
            print("======>Current memory:\n %s" % self.agent.memory)
            state = state + [(f"![](/file={image_filename})*{image_filename}*", AI_prompt)]
            print("Outputs:", state)
            return state, state, gr.Audio.update(visible=False), gr.Video.update(visible=False)

    def speech(self, speech_input, state):
        input_audio_filename = os.path.join('audio', str(uuid.uuid4())[0:8] + ".wav")
        text = self.asr.translate_english(speech_input)
        print("Inputs:", text, state)
        print("======>Previous memory:\n %s" % self.agent.memory)
        self.agent.memory.buffer = cut_dialogue_history(self.agent.memory.buffer, keep_last_n_words=500)
        res = self.agent({"input": text})
        if res['intermediate_steps'] == []:
            print("======>Current memory:\n %s" % self.agent.memory)
            response = res['output']
            output_audio_filename = self.tts.inference(response)
            state = state + [(text, response)]
            print("Outputs:", state)
            return gr.Audio.update(value=None), gr.Audio.update(value=output_audio_filename,visible=True), state, gr.Video.update(visible=False)
        else:
            tool = res['intermediate_steps'][0][0].tool
            if tool == "Generate Image From User Input Text" or tool == "Generate Text From The Audio" or tool == "Target Sound Detection":
                print("======>Current memory:\n %s" % self.agent.memory)
                response = re.sub('(image/\S*png)', lambda m: f'![](/file={m.group(0)})*{m.group(0)}*', res['output'])
                output_audio_filename = self.tts.inference(res['output'])
                state = state + [(text, response)]
                print("Outputs:", state)
                return gr.Audio.update(value=None), gr.Audio.update(value=output_audio_filename,visible=True), state, gr.Video.update(visible=False)
            elif tool == "Transcribe Speech":
                print("======>Current memory:\n %s" % self.agent.memory)
                output_audio_filename = self.tts.inference(res['output'])
                response = res['output']
                state = state + [(text, response)]
                print("Outputs:", state)
                return gr.Audio.update(value=None), gr.Audio.update(value=output_audio_filename,visible=True), state, gr.Video.update(visible=False)
            elif tool == "Detect The Sound Event From The Audio":
                print("======>Current memory:\n %s" % self.agent.memory)
                image_filename = res['intermediate_steps'][0][1]
                output_audio_filename = self.tts.inference(res['output'])
                response = res['output'] + f"![](/file={image_filename})*{image_filename}*"
                state = state + [(text, response)]
                print("Outputs:", state)
                return gr.Audio.update(value=None), gr.Audio.update(value=output_audio_filename,visible=True), state, gr.Video.update(visible=False)   
            elif tool == "Generate a talking human portrait video given a input Audio":
                video_filename = res['intermediate_steps'][0][1]
                print("======>Current memory:\n %s" % self.agent.memory)
                response = res['output'] 
                output_audio_filename = self.tts.inference(res['output'])
                state = state + [(text, response)]
                print("Outputs:", state)
                return gr.Audio.update(value=None), gr.Audio.update(value=output_audio_filename,visible=True), state, gr.Video.update(value=video_filename,visible=True)
            print("======>Current memory:\n %s" % self.agent.memory)
            response = re.sub('(image/\S*png)', lambda m: f'![](/file={m.group(0)})*{m.group(0)}*', res['output'])
            audio_filename = res['intermediate_steps'][0][1]
            Res = "The audio file has been generated and the audio is "
            output_audio_filename = merge_audio(self.tts.inference(Res), audio_filename)
            print(output_audio_filename)
            state = state + [(text, response)]
            response = res['output'] 
            print("Outputs:", state)
            return gr.Audio.update(value=None), gr.Audio.update(value=output_audio_filename,visible=True), state, gr.Video.update(visible=False)

    def inpainting(self, state, audio_filename, image_filename):
        print("===============Running inpainting =============")
        print("Inputs:", state)
        print("======>Previous memory:\n %s" % self.agent.memory)
        new_image_filename, new_audio_filename = self.inpaint.inference(audio_filename, image_filename)       
        AI_prompt = "Here are the predict audio and the mel spectrum." + f"*{new_audio_filename}*" + f"![](/file={new_image_filename})*{new_image_filename}*"
        output_audio_filename = self.tts.inference(AI_prompt)
        self.agent.memory.buffer = self.agent.memory.buffer + 'AI: ' + AI_prompt
        print("======>Current memory:\n %s" % self.agent.memory)
        state = state + [(f"Audio Inpainting", AI_prompt)]
        print("Outputs:", state)
        return state, state, gr.Image.update(visible=False), gr.Audio.update(value=new_audio_filename, visible=True), gr.Video.update(visible=False), gr.Button.update(visible=False)

    def clear_audio(self):
        return gr.Audio.update(value=None, visible=False)
    def clear_input_audio(self):
        return gr.Audio.update(value=None)
    def clear_image(self):
        return gr.Image.update(value=None, visible=False)
    def clear_video(self):
        return gr.Video.update(value=None, visible=False)
    def clear_button(self):
        return gr.Button.update(visible=False)


if __name__ == '__main__':
    bot = ConversationBot()
    with gr.Blocks(css="#chatbot .overflow-y-auto{height:500px}") as demo:
        with gr.Row():
            gr.Markdown("## AudioGPT")
        chatbot = gr.Chatbot(elem_id="chatbot", label="AudioGPT", visible=False) 
        state = gr.State([])

        with gr.Row() as select_raws:
            with gr.Column(scale=0.7):
                interaction_type = gr.Radio(choices=['text', 'speech'], value='text', label='Interaction Type')
            with gr.Column(scale=0.3, min_width=0):
                select = gr.Button("Select")
        
        with gr.Row(visible=False) as text_input_raws:
            with gr.Column(scale=0.7):
                txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter, or upload an image").style(container=False)
            with gr.Column(scale=0.1, min_width=0):
                run = gr.Button("🏃‍♂️Run")
            with gr.Column(scale=0.1, min_width=0):
                clear_txt = gr.Button("🔄Clear️")
            with gr.Column(scale=0.1, min_width=0):
                btn = gr.UploadButton("🖼️Upload", file_types=["image","audio"])

        with gr.Row():
            outaudio = gr.Audio(visible=False)
        with gr.Row():
            with gr.Column(scale=0.3, min_width=0):
                outvideo = gr.Video(visible=False)
        with gr.Row():
            show_mel = gr.Image(type="filepath",tool='sketch',visible=False)
        with gr.Row():
            run_button = gr.Button("Predict Masked Place",visible=False)        

        with gr.Row(visible=False) as speech_input_raws: 
            with gr.Column(scale=0.7):
                speech_input = gr.Audio(source="microphone", type="filepath", label="Input")
            with gr.Column(scale=0.15, min_width=0):
                submit_btn = gr.Button("🏃‍♂️Submit")
            with gr.Column(scale=0.15, min_width=0):
                clear_speech = gr.Button("🔄Clear️")
            with gr.Row():
                speech_output = gr.Audio(label="Output",visible=False)

        select.click(bot.init_tools, [interaction_type], [chatbot, select_raws, text_input_raws, speech_input_raws])

        txt.submit(bot.run_text, [txt, state], [chatbot, state, outaudio, outvideo, show_mel, run_button])
        txt.submit(lambda: "", None, txt)
        run.click(bot.run_text, [txt, state], [chatbot, state, outaudio, outvideo, show_mel, run_button])
        run.click(lambda: "", None, txt)
        btn.upload(bot.run_image_or_audio, [btn, state, txt], [chatbot, state, outaudio, outvideo])
        run_button.click(bot.inpainting, [state, outaudio, show_mel], [chatbot, state, show_mel, outaudio, outvideo, run_button])
        clear_txt.click(bot.memory.clear)
        clear_txt.click(lambda: [], None, chatbot)
        clear_txt.click(lambda: [], None, state)
        clear_txt.click(lambda:None, None, txt)
        clear_txt.click(bot.clear_button, None, run_button)
        clear_txt.click(bot.clear_image, None, show_mel)
        clear_txt.click(bot.clear_audio, None, outaudio)
        clear_txt.click(bot.clear_video, None, outvideo)

        submit_btn.click(bot.speech, [speech_input, state], [speech_input, speech_output, state, outvideo])
        clear_speech.click(bot.clear_input_audio, None, speech_input)
        clear_speech.click(bot.clear_audio, None, speech_output)
        clear_speech.click(lambda: [], None, state)
        clear_speech.click(bot.clear_video, None, outvideo)

        demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
langchain.llms.openai.OpenAI langchain.agents.tools.Tool langchain.chains.conversation.memory.ConversationBufferMemory langchain.agents.initialize.initialize_agent
[((3966, 3992), 'scipy.io.wavfile.read', 'wavfile.read', (['audio_path_1'], {}), '(audio_path_1)\n', (3978, 3992), True, 'import scipy.io.wavfile as wavfile\n'), ((4014, 4040), 'scipy.io.wavfile.read', 'wavfile.read', (['audio_path_2'], {}), '(audio_path_2)\n', (4026, 4040), True, 'import scipy.io.wavfile as wavfile\n'), ((4131, 4155), 'numpy.hstack', 'np.hstack', (['merged_signal'], {}), '(merged_signal)\n', (4140, 4155), True, 'import numpy as np\n'), ((4176, 4217), 'numpy.asarray', 'np.asarray', (['merged_signal'], {'dtype': 'np.int16'}), '(merged_signal, dtype=np.int16)\n', (4186, 4217), True, 'import numpy as np\n'), ((4298, 4348), 'scipy.io.wavfile.write', 'wavfile.write', (['audio_filename', 'sr_2', 'merged_signal'], {}), '(audio_filename, sr_2, merged_signal)\n', (4311, 4348), True, 'import scipy.io.wavfile as wavfile\n'), ((53, 79), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (69, 79), False, 'import os\n'), ((4682, 4786), 'diffusers.StableDiffusionPipeline.from_pretrained', 'StableDiffusionPipeline.from_pretrained', (['"""runwayml/stable-diffusion-v1-5"""'], {'torch_dtype': 'torch.float16'}), "('runwayml/stable-diffusion-v1-5',\n    torch_dtype=torch.float16)\n", (4721, 4786), False, 'from diffusers import StableDiffusionPipeline\n'), ((4820, 4892), 'transformers.AutoTokenizer.from_pretrained', 'AutoTokenizer.from_pretrained', (['"""Gustavosta/MagicPrompt-Stable-Diffusion"""'], {}), "('Gustavosta/MagicPrompt-Stable-Diffusion')\n", (4849, 4892), False, 'from transformers import AutoModelForCausalLM, AutoTokenizer\n'), ((4926, 5005), 'transformers.AutoModelForCausalLM.from_pretrained', 'AutoModelForCausalLM.from_pretrained', (['"""Gustavosta/MagicPrompt-Stable-Diffusion"""'], {}), "('Gustavosta/MagicPrompt-Stable-Diffusion')\n", (4962, 5005), False, 'from transformers import AutoModelForCausalLM, AutoTokenizer\n'), ((5043, 5163), 'transformers.pipeline', 'pipeline', (['"""text-generation"""'], {'model': 'self.text_refine_model', 'tokenizer': 'self.text_refine_tokenizer', 'device': 'self.device'}), "('text-generation', model=self.text_refine_model, tokenizer=self.\n    text_refine_tokenizer, device=self.device)\n", (5051, 5163), False, 'from transformers import pipeline\n'), ((5875, 5945), 'transformers.BlipProcessor.from_pretrained', 'BlipProcessor.from_pretrained', (['"""Salesforce/blip-image-captioning-base"""'], {}), "('Salesforce/blip-image-captioning-base')\n", (5904, 5945), False, 'from transformers import BlipProcessor, BlipForConditionalGeneration\n'), ((6704, 6792), 'vocoder.bigvgan.models.VocoderBigVGAN', 'VocoderBigVGAN', (['"""text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w"""'], {'device': 'device'}), "('text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w',\n    device=device)\n", (6718, 6792), False, 'from vocoder.bigvgan.models import VocoderBigVGAN\n'), ((6861, 6883), 'omegaconf.OmegaConf.load', 'OmegaConf.load', (['config'], {}), '(config)\n', (6875, 6883), False, 'from omegaconf import OmegaConf\n'), ((6900, 6937), 'ldm.util.instantiate_from_config', 'instantiate_from_config', (['config.model'], {}), '(config.model)\n', (6923, 6937), False, 'from ldm.util import instantiate_from_config\n'), ((7187, 7205), 'ldm.models.diffusion.ddim.DDIMSampler', 'DDIMSampler', (['model'], {}), '(model)\n', (7198, 7205), False, 'from ldm.models.diffusion.ddim import DDIMSampler\n'), ((7378, 7405), 'numpy.random.RandomState', 'np.random.RandomState', (['seed'], {}), '(seed)\n', (7399, 7405), True, 'import numpy as np\n'), ((8501, 8560), 'torch.clamp', 'torch.clamp', (['((x_samples_ddim + 1.0) / 2.0)'], {'min': '(0.0)', 'max': '(1.0)'}), '((x_samples_ddim + 1.0) / 2.0, min=0.0, max=1.0)\n', (8512, 8560), False, 'import torch\n'), ((10157, 10217), 'soundfile.write', 'soundfile.write', (['audio_filename', 'result[1]'], {'samplerate': '(16000)'}), '(audio_filename, result[1], samplerate=16000)\n', (10172, 10217), False, 'import soundfile\n'), ((10695, 10783), 'vocoder.bigvgan.models.VocoderBigVGAN', 'VocoderBigVGAN', (['"""text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w"""'], {'device': 'device'}), "('text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w',\n    device=device)\n", (10709, 10783), False, 'from vocoder.bigvgan.models import VocoderBigVGAN\n'), ((10852, 10874), 'omegaconf.OmegaConf.load', 'OmegaConf.load', (['config'], {}), '(config)\n', (10866, 10874), False, 'from omegaconf import OmegaConf\n'), ((10891, 10928), 'ldm.util.instantiate_from_config', 'instantiate_from_config', (['config.model'], {}), '(config.model)\n', (10914, 10928), False, 'from ldm.util import instantiate_from_config\n'), ((11178, 11196), 'ldm.models.diffusion.ddim.DDIMSampler', 'DDIMSampler', (['model'], {}), '(model)\n', (11189, 11196), False, 'from ldm.models.diffusion.ddim import DDIMSampler\n'), ((11399, 11426), 'numpy.random.RandomState', 'np.random.RandomState', (['seed'], {}), '(seed)\n', (11420, 11426), True, 'import numpy as np\n'), ((11759, 11776), 'PIL.Image.open', 'Image.open', (['image'], {}), '(image)\n', (11769, 11776), False, 'from PIL import Image\n'), ((12720, 12779), 'torch.clamp', 'torch.clamp', (['((x_samples_ddim + 1.0) / 2.0)'], {'min': '(0.0)', 'max': '(1.0)'}), '((x_samples_ddim + 1.0) / 2.0, min=0.0, max=1.0)\n', (12731, 12779), False, 'import torch\n'), ((13377, 13437), 'soundfile.write', 'soundfile.write', (['audio_filename', 'result[1]'], {'samplerate': '(16000)'}), '(audio_filename, result[1], samplerate=16000)\n', (13392, 13437), False, 'import soundfile\n'), ((13967, 13996), 'inference.tts.PortaSpeech.TTSInference', 'TTSInference', (['self.hp', 'device'], {}), '(self.hp, device)\n', (13979, 13996), False, 'from inference.tts.PortaSpeech import TTSInference\n'), ((14039, 14095), 'utils.hparams.set_hparams', 'set_hparams', ([], {'exp_name': 'self.exp_name', 'print_hparams': '(False)'}), '(exp_name=self.exp_name, print_hparams=False)\n', (14050, 14095), False, 'from utils.hparams import set_hparams\n'), ((14345, 14399), 'soundfile.write', 'soundfile.write', (['audio_filename', 'out'], {'samplerate': '(22050)'}), '(audio_filename, out, samplerate=22050)\n', (14360, 14399), False, 'import soundfile\n'), ((14913, 14948), 'inference.svs.ds_e2e.DiffSingerE2EInfer', 'DiffSingerE2EInfer', (['self.hp', 'device'], {}), '(self.hp, device)\n', (14931, 14948), False, 'from inference.svs.ds_e2e import DiffSingerE2EInfer\n'), ((15398, 15474), 'utils.hparams.set_hparams', 'set_hparams', ([], {'config': 'self.config', 'exp_name': 'self.exp_name', 'print_hparams': '(False)'}), '(config=self.config, exp_name=self.exp_name, print_hparams=False)\n', (15409, 15474), False, 'from utils.hparams import set_hparams\n'), ((18112, 18174), 'soundfile.write', 'soundfile.write', (['audio_filename', 'wav'], {'samplerate': 'self.model.fs'}), '(audio_filename, wav, samplerate=self.model.fs)\n', (18127, 18174), False, 'import soundfile\n'), ((18678, 18711), 'inference.tts.GenerSpeech.GenerSpeechInfer', 'GenerSpeechInfer', (['self.hp', 'device'], {}), '(self.hp, device)\n', (18694, 18711), False, 'from inference.tts.GenerSpeech import GenerSpeechInfer\n'), ((18754, 18830), 'utils.hparams.set_hparams', 'set_hparams', ([], {'config': 'self.config', 'exp_name': 'self.exp_name', 'print_hparams': '(False)'}), '(config=self.config, exp_name=self.exp_name, print_hparams=False)\n', (18765, 18830), False, 'from utils.hparams import set_hparams\n'), ((18914, 18941), 'os.path.exists', 'os.path.exists', (['f0_stats_fn'], {}), '(f0_stats_fn)\n', (18928, 18941), False, 'import os\n'), ((20145, 20233), 'vocoder.bigvgan.models.VocoderBigVGAN', 'VocoderBigVGAN', (['"""text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w"""'], {'device': 'device'}), "('text_to_audio/Make_An_Audio/vocoder/logs/bigv16k53w',\n    device=device)\n", (20159, 20233), False, 'from vocoder.bigvgan.models import VocoderBigVGAN\n'), ((20354, 20376), 'omegaconf.OmegaConf.load', 'OmegaConf.load', (['config'], {}), '(config)\n', (20368, 20376), False, 'from omegaconf import OmegaConf\n'), ((20393, 20430), 'ldm.util.instantiate_from_config', 'instantiate_from_config', (['config.model'], {}), '(config.model)\n', (20416, 20430), False, 'from ldm.util import instantiate_from_config\n'), ((20737, 20755), 'ldm.models.diffusion.ddim.DDIMSampler', 'DDIMSampler', (['model'], {}), '(model)\n', (20748, 20755), False, 'from ldm.models.diffusion.ddim import DDIMSampler\n'), ((21544, 21574), 'scipy.io.wavfile.read', 'wavfile.read', (['input_audio_path'], {}), '(input_audio_path)\n', (21556, 21574), True, 'import scipy.io.wavfile as wavfile\n'), ((21855, 21915), 'librosa.resample', 'librosa.resample', (['ori_wav'], {'orig_sr': 'sr', 'target_sr': 'SAMPLE_RATE'}), '(ori_wav, orig_sr=sr, target_sr=SAMPLE_RATE)\n', (21871, 21915), False, 'import librosa\n'), ((22182, 22209), 'ldm.data.extract_mel_spectrogram.TRANSFORMS_16000', 'TRANSFORMS_16000', (['input_wav'], {}), '(input_wav)\n', (22198, 22209), False, 'from ldm.data.extract_mel_spectrogram import TRANSFORMS_16000\n'), ((22619, 22679), 'librosa.resample', 'librosa.resample', (['ori_wav'], {'orig_sr': 'sr', 'target_sr': 'SAMPLE_RATE'}), '(ori_wav, orig_sr=sr, target_sr=SAMPLE_RATE)\n', (22635, 22679), False, 'import librosa\n'), ((22945, 22972), 'ldm.data.extract_mel_spectrogram.TRANSFORMS_16000', 'TRANSFORMS_16000', (['input_wav'], {}), '(input_wav)\n', (22961, 22972), False, 'from ldm.data.extract_mel_spectrogram import TRANSFORMS_16000\n'), ((23512, 23539), 'numpy.random.RandomState', 'np.random.RandomState', (['seed'], {}), '(seed)\n', (23533, 23539), True, 'import numpy as np\n'), ((23834, 23899), 'torch.nn.functional.interpolate', 'torch.nn.functional.interpolate', (["batch['mask']"], {'size': 'c.shape[-2:]'}), "(batch['mask'], size=c.shape[-2:])\n", (23865, 23899), False, 'import torch\n'), ((23960, 23985), 'torch.cat', 'torch.cat', (['(c, cc)'], {'dim': '(1)'}), '((c, cc), dim=1)\n', (23969, 23985), False, 'import torch\n'), ((24438, 24495), 'torch.clamp', 'torch.clamp', (["((batch['mel'] + 1.0) / 2.0)"], {'min': '(0.0)', 'max': '(1.0)'}), "((batch['mel'] + 1.0) / 2.0, min=0.0, max=1.0)\n", (24449, 24495), False, 'import torch\n'), ((24506, 24564), 'torch.clamp', 'torch.clamp', (["((batch['mask'] + 1.0) / 2.0)"], {'min': '(0.0)', 'max': '(1.0)'}), "((batch['mask'] + 1.0) / 2.0, min=0.0, max=1.0)\n", (24517, 24564), False, 'import torch\n'), ((24584, 24643), 'torch.clamp', 'torch.clamp', (['((x_samples_ddim + 1.0) / 2.0)'], {'min': '(0.0)', 'max': '(1.0)'}), '((x_samples_ddim + 1.0) / 2.0, min=0.0, max=1.0)\n', (24595, 24643), False, 'import torch\n'), ((24954, 24983), 'torch.set_grad_enabled', 'torch.set_grad_enabled', (['(False)'], {}), '(False)\n', (24976, 24983), False, 'import torch\n'), ((25002, 25035), 'PIL.Image.open', 'Image.open', (["mel_and_mask['image']"], {}), "(mel_and_mask['image'])\n", (25012, 25035), False, 'from PIL import Image\n'), ((25055, 25087), 'PIL.Image.open', 'Image.open', (["mel_and_mask['mask']"], {}), "(mel_and_mask['mask'])\n", (25065, 25087), False, 'from PIL import Image\n'), ((25306, 25398), 'numpy.pad', 'np.pad', (['mask', '((0, 0), (0, mel_len - mask.shape[1]))'], {'mode': '"""constant"""', 'constant_values': '(0)'}), "(mask, ((0, 0), (0, mel_len - mask.shape[1])), mode='constant',\n    constant_values=0)\n", (25312, 25398), True, 'import numpy as np\n'), ((26269, 26327), 'soundfile.write', 'soundfile.write', (['audio_filename', 'gen_wav'], {'samplerate': '(16000)'}), '(audio_filename, gen_wav, samplerate=16000)\n', (26284, 26327), False, 'import soundfile\n'), ((26527, 26568), 'whisper.load_model', 'whisper.load_model', (['"""base"""'], {'device': 'device'}), "('base', device=device)\n", (26545, 26568), False, 'import whisper\n'), ((26623, 26653), 'whisper.load_audio', 'whisper.load_audio', (['audio_path'], {}), '(audio_path)\n', (26641, 26653), False, 'import whisper\n'), ((26670, 26696), 'whisper.pad_or_trim', 'whisper.pad_or_trim', (['audio'], {}), '(audio)\n', (26689, 26696), False, 'import whisper\n'), ((26831, 26856), 'whisper.DecodingOptions', 'whisper.DecodingOptions', ([], {}), '()\n', (26854, 26856), False, 'import whisper\n'), ((26874, 26914), 'whisper.decode', 'whisper.decode', (['self.model', 'mel', 'options'], {}), '(self.model, mel, options)\n', (26888, 26914), False, 'import whisper\n'), ((27312, 27373), 'audio_to_text.inference_waveform.AudioCapModel', 'AudioCapModel', (['"""audio_to_text/audiocaps_cntrstv_cnn14rnn_trm"""'], {}), "('audio_to_text/audiocaps_cntrstv_cnn14rnn_trm')\n", (27325, 27373), False, 'from audio_to_text.inference_waveform import AudioCapModel\n'), ((27427, 27457), 'whisper.load_audio', 'whisper.load_audio', (['audio_path'], {}), '(audio_path)\n', (27445, 27457), False, 'import whisper\n'), ((27863, 27884), 'audio_to_face.GeneFace_binding.GeneFaceInfer', 'GeneFaceInfer', (['device'], {}), '(device)\n', (27876, 27884), False, 'from audio_to_face.GeneFace_binding import GeneFaceInfer\n'), ((29085, 29267), 'audio_infer.pytorch.models.PVT', 'PVT', ([], {'sample_rate': 'self.sample_rate', 'window_size': 'self.window_size', 'hop_size': 'self.hop_size', 'mel_bins': 'self.mel_bins', 'fmin': 'self.fmin', 'fmax': 'self.fmax', 'classes_num': 'self.classes_num'}), '(sample_rate=self.sample_rate, window_size=self.window_size, hop_size=\n    self.hop_size, mel_bins=self.mel_bins, fmin=self.fmin, fmax=self.fmax,\n    classes_num=self.classes_num)\n', (29088, 29267), False, 'from audio_infer.pytorch.models import PVT\n'), ((29306, 29364), 'torch.load', 'torch.load', (['self.checkpoint_path'], {'map_location': 'self.device'}), '(self.checkpoint_path, map_location=self.device)\n', (29316, 29364), False, 'import torch\n'), ((29531, 29592), 'librosa.core.load', 'librosa.core.load', (['audio_path'], {'sr': 'self.sample_rate', 'mono': '(True)'}), '(audio_path, sr=self.sample_rate, mono=True)\n', (29548, 29592), False, 'import librosa\n'), ((29672, 29698), 'torch.from_numpy', 'torch.from_numpy', (['waveform'], {}), '(waveform)\n', (29688, 29698), False, 'import torch\n'), ((30663, 30711), 'matplotlib.pyplot.subplots', 'plt.subplots', (['(2)', '(1)'], {'sharex': '(True)', 'figsize': '(10, 4)'}), '(2, 1, sharex=True, figsize=(10, 4))\n', (30675, 30711), True, 'import matplotlib.pyplot as plt\n'), ((31471, 31489), 'matplotlib.pyplot.tight_layout', 'plt.tight_layout', ([], {}), '()\n', (31487, 31489), True, 'import matplotlib.pyplot as plt\n'), ((31578, 31605), 'matplotlib.pyplot.savefig', 'plt.savefig', (['image_filename'], {}), '(image_filename)\n', (31589, 31605), True, 'import matplotlib.pyplot as plt\n'), ((31952, 31958), 'sound_extraction.utils.stft.STFT', 'STFT', ([], {}), '()\n', (31956, 31958), False, 'from sound_extraction.utils.stft import STFT\n'), ((32046, 32073), 'torch.load', 'torch.load', (['self.model_file'], {}), '(self.model_file)\n', (32056, 32073), False, 'import torch\n'), ((32416, 32436), 'sound_extraction.utils.wav_io.load_wav', 'load_wav', (['audio_path'], {}), '(audio_path)\n', (32424, 32436), False, 'from sound_extraction.utils.wav_io import load_wav, save_wav\n'), ((33156, 33189), 'sound_extraction.utils.wav_io.save_wav', 'save_wav', (['est_wav', 'audio_filename'], {}), '(est_wav, audio_filename)\n', (33164, 33189), False, 'from sound_extraction.utils.wav_io import load_wav, save_wav\n'), ((33854, 33920), 'src.models.BinauralNetwork', 'BinauralNetwork', ([], {'view_dim': '(7)', 'warpnet_layers': '(4)', 'warpnet_channels': '(64)'}), '(view_dim=7, warpnet_layers=4, warpnet_channels=64)\n', (33869, 33920), False, 'from src.models import BinauralNetwork\n'), ((34119, 34171), 'librosa.load', 'librosa.load', ([], {'path': 'audio_path', 'sr': 'self.sr', 'mono': '(True)'}), '(path=audio_path, sr=self.sr, mono=True)\n', (34131, 34171), False, 'import librosa\n'), ((34187, 34209), 'torch.from_numpy', 'torch.from_numpy', (['mono'], {}), '(mono)\n', (34203, 34209), False, 'import torch\n'), ((34311, 34331), 'random.randint', 'random.randint', (['(0)', '(4)'], {}), '(0, 4)\n', (34325, 34331), False, 'import random\n'), ((34433, 34455), 'torch.from_numpy', 'torch.from_numpy', (['view'], {}), '(view)\n', (34449, 34455), False, 'import torch\n'), ((35860, 35918), 'torch.cat', 'torch.cat', (["[chunk['binaural'] for chunk in chunks]"], {'dim': '(-1)'}), "([chunk['binaural'] for chunk in chunks], dim=-1)\n", (35869, 35918), False, 'import torch\n'), ((36151, 36196), 'torchaudio.save', 'torchaudio.save', (['audio_filename', 'binaural', 'sr'], {}), '(audio_filename, binaural, sr)\n', (36166, 36196), False, 'import torchaudio\n'), ((36806, 36819), 'numpy.spacing', 'np.spacing', (['(1)'], {}), '(1)\n', (36816, 36819), True, 'import numpy as np\n'), ((36849, 36890), 'clip.load', 'clip.load', (['"""ViT-B/32"""'], {'device': 'self.device'}), "('ViT-B/32', device=self.device)\n", (36858, 36890), False, 'import clip\n'), ((37034, 37147), 'torch.load', 'torch.load', (['"""audio_detection/target_sound_detection/useful_ckpts/tsd/run_config.pth"""'], {'map_location': '"""cpu"""'}), "(\n    'audio_detection/target_sound_detection/useful_ckpts/tsd/run_config.pth',\n    map_location='cpu')\n", (37044, 37147), False, 'import torch\n'), ((37460, 37610), 'torch.load', 'torch.load', (['"""audio_detection/target_sound_detection/useful_ckpts/tsd/run_model_7_loss=-0.0724.pt"""'], {'map_location': '(lambda storage, loc: storage)'}), "(\n    'audio_detection/target_sound_detection/useful_ckpts/tsd/run_model_7_loss=-0.0724.pt'\n    , map_location=lambda storage, loc: storage)\n", (37470, 37610), False, 'import torch\n'), ((38016, 38103), 'torch.load', 'torch.load', (['"""audio_detection/target_sound_detection/useful_ckpts/tsd/text_emb.pth"""'], {}), "(\n    'audio_detection/target_sound_detection/useful_ckpts/tsd/text_emb.pth')\n", (38026, 38103), False, 'import torch\n'), ((38122, 38208), 'torch.load', 'torch.load', (['"""audio_detection/target_sound_detection/useful_ckpts/tsd/ref_mel.pth"""'], {}), "(\n    'audio_detection/target_sound_detection/useful_ckpts/tsd/ref_mel.pth')\n", (38132, 38208), False, 'import torch\n'), ((38290, 38321), 'soundfile.read', 'sf.read', (['fname'], {'dtype': '"""float32"""'}), "(fname, dtype='float32')\n", (38297, 38321), True, 'import soundfile as sf\n'), ((38439, 38469), 'librosa.resample', 'librosa.resample', (['y', 'sr', '(22050)'], {}), '(y, sr, 22050)\n', (38455, 38469), False, 'import librosa\n'), ((39559, 39586), 'torch.from_numpy', 'torch.from_numpy', (['embedding'], {}), '(embedding)\n', (39575, 39586), False, 'import torch\n'), ((39796, 39820), 'torch.from_numpy', 'torch.from_numpy', (['inputs'], {}), '(inputs)\n', (39812, 39820), False, 'import torch\n'), ((40169, 40218), 'target_sound_detection.src.utils.median_filter', 'median_filter', (['pred'], {'window_size': '(1)', 'threshold': '(0.5)'}), '(pred, window_size=1, threshold=0.5)\n', (40182, 40218), False, 'from target_sound_detection.src.utils import median_filter, decode_with_timestamps\n'), ((45032, 45049), 'espnet_model_zoo.downloader.ModelDownloader', 'ModelDownloader', ([], {}), '()\n', (45047, 45049), False, 'from espnet_model_zoo.downloader import ModelDownloader\n'), ((45135, 45379), 'espnet2.bin.enh_inference.SeparateSpeech', 'SeparateSpeech', ([], {'train_config': "cfg['train_config']", 'model_file': "cfg['model_file']", 'segment_size': '(2.4)', 'hop_size': '(0.8)', 'normalize_segment_scale': '(False)', 'show_progressbar': '(True)', 'ref_channel': 'None', 'normalize_output_wav': '(True)', 'device': 'self.device'}), "(train_config=cfg['train_config'], model_file=cfg[\n    'model_file'], segment_size=2.4, hop_size=0.8, normalize_segment_scale=\n    False, show_progressbar=True, ref_channel=None, normalize_output_wav=\n    True, device=self.device)\n", (45149, 45379), False, 'from espnet2.bin.enh_inference import SeparateSpeech\n'), ((45613, 45640), 'soundfile.read', 'soundfile.read', (['speech_path'], {}), '(speech_path)\n', (45627, 45640), False, 'import soundfile\n'), ((47031, 47048), 'espnet_model_zoo.downloader.ModelDownloader', 'ModelDownloader', ([], {}), '()\n', (47046, 47048), False, 'from espnet_model_zoo.downloader import ModelDownloader\n'), ((47134, 47378), 'espnet2.bin.enh_inference.SeparateSpeech', 'SeparateSpeech', ([], {'train_config': "cfg['train_config']", 'model_file': "cfg['model_file']", 'segment_size': '(2.4)', 'hop_size': '(0.8)', 'normalize_segment_scale': '(False)', 'show_progressbar': '(True)', 'ref_channel': 'None', 'normalize_output_wav': '(True)', 'device': 'self.device'}), "(train_config=cfg['train_config'], model_file=cfg[\n    'model_file'], segment_size=2.4, hop_size=0.8, normalize_segment_scale=\n    False, show_progressbar=True, ref_channel=None, normalize_output_wav=\n    True, device=self.device)\n", (47148, 47378), False, 'from espnet2.bin.enh_inference import SeparateSpeech\n'), ((47597, 47624), 'soundfile.read', 'soundfile.read', (['speech_path'], {}), '(speech_path)\n', (47611, 47624), False, 'import soundfile\n'), ((48487, 48508), 'langchain.llms.openai.OpenAI', 'OpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (48493, 48508), False, 'from langchain.llms.openai import OpenAI\n'), ((49380, 49452), 'langchain.chains.conversation.memory.ConversationBufferMemory', 'ConversationBufferMemory', ([], {'memory_key': '"""chat_history"""', 'output_key': '"""output"""'}), "(memory_key='chat_history', output_key='output')\n", (49404, 49452), False, 'from langchain.chains.conversation.memory import ConversationBufferMemory\n'), ((75007, 75049), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None', 'visible': '(False)'}), '(value=None, visible=False)\n', (75022, 75049), True, 'import gradio as gr\n'), ((75098, 75125), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (75113, 75125), True, 'import gradio as gr\n'), ((75168, 75210), 'gradio.Image.update', 'gr.Image.update', ([], {'value': 'None', 'visible': '(False)'}), '(value=None, visible=False)\n', (75183, 75210), True, 'import gradio as gr\n'), ((75253, 75295), 'gradio.Video.update', 'gr.Video.update', ([], {'value': 'None', 'visible': '(False)'}), '(value=None, visible=False)\n', (75268, 75295), True, 'import gradio as gr\n'), ((75339, 75370), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (75355, 75370), True, 'import gradio as gr\n'), ((75437, 75493), 'gradio.Blocks', 'gr.Blocks', ([], {'css': '"""#chatbot .overflow-y-auto{height:500px}"""'}), "(css='#chatbot .overflow-y-auto{height:500px}')\n", (75446, 75493), True, 'import gradio as gr\n'), ((75583, 75645), 'gradio.Chatbot', 'gr.Chatbot', ([], {'elem_id': '"""chatbot"""', 'label': '"""AudioGPT"""', 'visible': '(False)'}), "(elem_id='chatbot', label='AudioGPT', visible=False)\n", (75593, 75645), True, 'import gradio as gr\n'), ((75663, 75675), 'gradio.State', 'gr.State', (['[]'], {}), '([])\n', (75671, 75675), True, 'import gradio as gr\n'), ((130, 156), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (146, 156), False, 'import os\n'), ((205, 231), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (221, 231), False, 'import os\n'), ((293, 319), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (309, 319), False, 'import os\n'), ((399, 425), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (415, 425), False, 'import os\n'), ((493, 519), 'os.path.realpath', 'os.path.realpath', (['__file__'], {}), '(__file__)\n', (509, 519), False, 'import os\n'), ((9915, 9930), 'torch.no_grad', 'torch.no_grad', ([], {}), '()\n', (9928, 9930), False, 'import torch\n'), ((13139, 13154), 'torch.no_grad', 'torch.no_grad', ([], {}), '()\n', (13152, 13154), False, 'import torch\n'), ((18985, 19005), 'numpy.load', 'np.load', (['f0_stats_fn'], {}), '(f0_stats_fn)\n', (18992, 19005), True, 'import numpy as np\n'), ((20568, 20593), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (20591, 20593), False, 'import torch\n'), ((20544, 20564), 'torch.device', 'torch.device', (['"""cuda"""'], {}), "('cuda')\n", (20556, 20564), False, 'import torch\n'), ((20599, 20618), 'torch.device', 'torch.device', (['"""cpu"""'], {}), "('cpu')\n", (20611, 20618), False, 'import torch\n'), ((21770, 21796), 'librosa.to_mono', 'librosa.to_mono', (['ori_wav.T'], {}), '(ori_wav.T)\n', (21785, 21796), False, 'import librosa\n'), ((22054, 22113), 'numpy.pad', 'np.pad', (['ori_wav', '(0, mel_len * hop_size)'], {'constant_values': '(0)'}), '(ori_wav, (0, mel_len * hop_size), constant_values=0)\n', (22060, 22113), True, 'import numpy as np\n'), ((22534, 22560), 'librosa.to_mono', 'librosa.to_mono', (['ori_wav.T'], {}), '(ori_wav.T)\n', (22549, 22560), False, 'import librosa\n'), ((22818, 22877), 'numpy.pad', 'np.pad', (['ori_wav', '(0, mel_len * hop_size)'], {'constant_values': '(0)'}), '(ori_wav, (0, mel_len * hop_size), constant_values=0)\n', (22824, 22877), True, 'import numpy as np\n'), ((25442, 25457), 'torch.no_grad', 'torch.no_grad', ([], {}), '()\n', (25455, 25457), False, 'import torch\n'), ((27988, 28016), 'os.path.basename', 'os.path.basename', (['audio_path'], {}), '(audio_path)\n', (28004, 28016), False, 'import os\n'), ((29774, 29789), 'torch.no_grad', 'torch.no_grad', ([], {}), '()\n', (29787, 29789), False, 'import torch\n'), ((31019, 31067), 'numpy.arange', 'np.arange', (['(0)', 'frames_num', 'self.frames_per_second'], {}), '(0, frames_num, self.frames_per_second)\n', (31028, 31067), True, 'import numpy as np\n'), ((31105, 31154), 'numpy.arange', 'np.arange', (['(0)', '(frames_num / self.frames_per_second)'], {}), '(0, frames_num / self.frames_per_second)\n', (31114, 31154), True, 'import numpy as np\n'), ((31187, 31206), 'numpy.arange', 'np.arange', (['(0)', 'top_k'], {}), '(0, top_k)\n', (31196, 31206), True, 'import numpy as np\n'), ((40409, 40472), 'target_sound_detection.src.utils.decode_with_timestamps', 'decode_with_timestamps', (['target_event', 'filtered_pred[index_k, :]'], {}), '(target_event, filtered_pred[index_k, :])\n', (40431, 40472), False, 'from target_sound_detection.src.utils import median_filter, decode_with_timestamps\n'), ((47818, 47879), 'soundfile.write', 'soundfile.write', (['audio_filename', 'enh_speech[0]'], {'samplerate': 'sr'}), '(audio_filename, enh_speech[0], samplerate=sr)\n', (47833, 47879), False, 'import soundfile\n'), ((57651, 57951), 'langchain.agents.initialize.initialize_agent', 'initialize_agent', (['self.tools', 'self.llm'], {'agent': '"""conversational-react-description"""', 'verbose': '(True)', 'memory': 'self.memory', 'return_intermediate_steps': '(True)', 'agent_kwargs': "{'prefix': AUDIO_CHATGPT_PREFIX, 'format_instructions':\n    AUDIO_CHATGPT_FORMAT_INSTRUCTIONS, 'suffix': AUDIO_CHATGPT_SUFFIX}"}), "(self.tools, self.llm, agent=\n    'conversational-react-description', verbose=True, memory=self.memory,\n    return_intermediate_steps=True, agent_kwargs={'prefix':\n    AUDIO_CHATGPT_PREFIX, 'format_instructions':\n    AUDIO_CHATGPT_FORMAT_INSTRUCTIONS, 'suffix': AUDIO_CHATGPT_SUFFIX})\n", (57667, 57951), False, 'from langchain.agents.initialize import initialize_agent\n'), ((62445, 62745), 'langchain.agents.initialize.initialize_agent', 'initialize_agent', (['self.tools', 'self.llm'], {'agent': '"""conversational-react-description"""', 'verbose': '(True)', 'memory': 'self.memory', 'return_intermediate_steps': '(True)', 'agent_kwargs': "{'prefix': AUDIO_CHATGPT_PREFIX, 'format_instructions':\n    AUDIO_CHATGPT_FORMAT_INSTRUCTIONS, 'suffix': AUDIO_CHATGPT_SUFFIX}"}), "(self.tools, self.llm, agent=\n    'conversational-react-description', verbose=True, memory=self.memory,\n    return_intermediate_steps=True, agent_kwargs={'prefix':\n    AUDIO_CHATGPT_PREFIX, 'format_instructions':\n    AUDIO_CHATGPT_FORMAT_INSTRUCTIONS, 'suffix': AUDIO_CHATGPT_SUFFIX})\n", (62461, 62745), False, 'from langchain.agents.initialize import initialize_agent\n'), ((67323, 67348), 'soundfile.read', 'soundfile.read', (['file.name'], {}), '(file.name)\n', (67337, 67348), False, 'import soundfile\n'), ((67361, 67419), 'soundfile.write', 'soundfile.write', (['audio_filename', 'audio_load'], {'samplerate': 'sr'}), '(audio_filename, audio_load, samplerate=sr)\n', (67376, 67419), False, 'import soundfile\n'), ((68723, 68744), 'PIL.Image.open', 'Image.open', (['file.name'], {}), '(file.name)\n', (68733, 68744), False, 'from PIL import Image\n'), ((74811, 74841), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (74826, 74841), True, 'import gradio as gr\n'), ((74843, 74898), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'new_audio_filename', 'visible': '(True)'}), '(value=new_audio_filename, visible=True)\n', (74858, 74898), True, 'import gradio as gr\n'), ((74900, 74930), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (74915, 74930), True, 'import gradio as gr\n'), ((74932, 74963), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (74948, 74963), True, 'import gradio as gr\n'), ((75516, 75524), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (75522, 75524), True, 'import gradio as gr\n'), ((75538, 75564), 'gradio.Markdown', 'gr.Markdown', (['"""## AudioGPT"""'], {}), "('## AudioGPT')\n", (75549, 75564), True, 'import gradio as gr\n'), ((75690, 75698), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (75696, 75698), True, 'import gradio as gr\n'), ((75985, 76006), 'gradio.Row', 'gr.Row', ([], {'visible': '(False)'}), '(visible=False)\n', (75991, 76006), True, 'import gradio as gr\n'), ((76544, 76552), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (76550, 76552), True, 'import gradio as gr\n'), ((76577, 76600), 'gradio.Audio', 'gr.Audio', ([], {'visible': '(False)'}), '(visible=False)\n', (76585, 76600), True, 'import gradio as gr\n'), ((76614, 76622), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (76620, 76622), True, 'import gradio as gr\n'), ((76740, 76748), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (76746, 76748), True, 'import gradio as gr\n'), ((76773, 76828), 'gradio.Image', 'gr.Image', ([], {'type': '"""filepath"""', 'tool': '"""sketch"""', 'visible': '(False)'}), "(type='filepath', tool='sketch', visible=False)\n", (76781, 76828), True, 'import gradio as gr\n'), ((76840, 76848), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (76846, 76848), True, 'import gradio as gr\n'), ((76875, 76923), 'gradio.Button', 'gr.Button', (['"""Predict Masked Place"""'], {'visible': '(False)'}), "('Predict Masked Place', visible=False)\n", (76884, 76923), True, 'import gradio as gr\n'), ((76945, 76966), 'gradio.Row', 'gr.Row', ([], {'visible': '(False)'}), '(visible=False)\n', (76951, 76966), True, 'import gradio as gr\n'), ((5967, 6057), 'transformers.BlipForConditionalGeneration.from_pretrained', 'BlipForConditionalGeneration.from_pretrained', (['"""Salesforce/blip-image-captioning-base"""'], {}), "(\n    'Salesforce/blip-image-captioning-base')\n", (6011, 6057), False, 'from transformers import BlipProcessor, BlipForConditionalGeneration\n'), ((6968, 7004), 'torch.load', 'torch.load', (['ckpt'], {'map_location': '"""cpu"""'}), "(ckpt, map_location='cpu')\n", (6978, 7004), False, 'import torch\n'), ((7534, 7562), 'torch.from_numpy', 'torch.from_numpy', (['start_code'], {}), '(start_code)\n', (7550, 7562), False, 'import torch\n'), ((9137, 9162), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (9160, 9162), False, 'import torch\n'), ((9661, 9681), 'numpy.array', 'np.array', (['score_list'], {}), '(score_list)\n', (9669, 9681), True, 'import numpy as np\n'), ((10959, 10995), 'torch.load', 'torch.load', (['ckpt'], {'map_location': '"""cpu"""'}), "(ckpt, map_location='cpu')\n", (10969, 10995), False, 'import torch\n'), ((11555, 11583), 'torch.from_numpy', 'torch.from_numpy', (['start_code'], {}), '(start_code)\n', (11571, 11583), False, 'import torch\n'), ((13731, 13756), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (13754, 13756), False, 'import torch\n'), ((14598, 14623), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (14621, 14623), False, 'import torch\n'), ((16575, 16600), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (16598, 16600), False, 'import torch\n'), ((18374, 18399), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (18397, 18399), False, 'import torch\n'), ((20461, 20497), 'torch.load', 'torch.load', (['ckpt'], {'map_location': '"""cpu"""'}), "(ckpt, map_location='cpu')\n", (20471, 20497), False, 'import torch\n'), ((23657, 23685), 'torch.from_numpy', 'torch.from_numpy', (['start_code'], {}), '(start_code)\n', (23673, 23685), False, 'import torch\n'), ((26711, 26745), 'whisper.log_mel_spectrogram', 'whisper.log_mel_spectrogram', (['audio'], {}), '(audio)\n', (26738, 26745), False, 'import whisper\n'), ((27767, 27792), 'torch.cuda.is_available', 'torch.cuda.is_available', ([], {}), '()\n', (27790, 27792), False, 'import torch\n'), ((30235, 30267), 'numpy.max', 'np.max', (['framewise_output'], {'axis': '(0)'}), '(framewise_output, axis=0)\n', (30241, 30267), True, 'import numpy as np\n'), ((30742, 30754), 'numpy.abs', 'np.abs', (['stft'], {}), '(stft)\n', (30748, 30754), True, 'import numpy as np\n'), ((31244, 31265), 'numpy.array', 'np.array', (['self.labels'], {}), '(self.labels)\n', (31252, 31265), True, 'import numpy as np\n'), ((32456, 32478), 'torch.tensor', 'torch.tensor', (['waveform'], {}), '(waveform)\n', (32468, 32478), False, 'import torch\n'), ((34703, 34725), 'random.randint', 'random.randint', (['(0)', 'm_a'], {}), '(0, m_a)\n', (34717, 34725), False, 'import random\n'), ((35521, 35536), 'torch.no_grad', 'torch.no_grad', ([], {}), '()\n', (35534, 35536), False, 'import torch\n'), ((35938, 35974), 'torch.clamp', 'torch.clamp', (['binaural'], {'min': '(-1)', 'max': '(1)'}), '(binaural, min=-1, max=1)\n', (35949, 35974), False, 'import torch\n'), ((38646, 38665), 'clip.tokenize', 'clip.tokenize', (['text'], {}), '(text)\n', (38659, 38665), False, 'import clip\n'), ((49580, 49968), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Image From User Input Text"""', 'func': 'self.t2i.inference', 'description': '"""useful for when you want to generate an image from a user input text and it saved it to a file. like: generate an image of an object or something, or generate an image that includes some objects. The input to this tool should be a string, representing the text used to generate image. """'}), "(name='Generate Image From User Input Text', func=self.t2i.inference,\n    description=\n    'useful for when you want to generate an image from a user input text and it saved it to a file. like: generate an image of an object or something, or generate an image that includes some objects. The input to this tool should be a string, representing the text used to generate image. '\n    )\n", (49584, 49968), False, 'from langchain.agents.tools import Tool\n'), ((50029, 50275), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Get Photo Description"""', 'func': 'self.i2t.inference', 'description': '"""useful for when you want to know what is inside the photo. receives image_path as input. The input to this tool should be a string, representing the image_path. """'}), "(name='Get Photo Description', func=self.i2t.inference, description=\n    'useful for when you want to know what is inside the photo. receives image_path as input. The input to this tool should be a string, representing the image_path. '\n    )\n", (50033, 50275), False, 'from langchain.agents.tools import Tool\n'), ((50340, 50626), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Audio From User Input Text"""', 'func': 'self.t2a.inference', 'description': '"""useful for when you want to generate an audio from a user input text and it saved it to a file.The input to this tool should be a string, representing the text used to generate audio."""'}), "(name='Generate Audio From User Input Text', func=self.t2a.inference,\n    description=\n    'useful for when you want to generate an audio from a user input text and it saved it to a file.The input to this tool should be a string, representing the text used to generate audio.'\n    )\n", (50344, 50626), False, 'from langchain.agents.tools import Tool\n'), ((50687, 51161), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Style Transfer"""', 'func': 'self.tts_ood.inference', 'description': '"""useful for when you want to generate speech samples with styles (e.g., timbre, emotion, and prosody) derived from a reference custom voice.Like: Generate a speech with style transferred from this voice. The text is xxx., or speak using the voice of this audio. The text is xxx.The input to this tool should be a comma seperated string of two, representing reference audio path and input text."""'}), "(name='Style Transfer', func=self.tts_ood.inference, description=\n    'useful for when you want to generate speech samples with styles (e.g., timbre, emotion, and prosody) derived from a reference custom voice.Like: Generate a speech with style transferred from this voice. The text is xxx., or speak using the voice of this audio. The text is xxx.The input to this tool should be a comma seperated string of two, representing reference audio path and input text.'\n    )\n", (50691, 51161), False, 'from langchain.agents.tools import Tool\n'), ((51281, 52061), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Singing Voice From User Input Text, Note and Duration Sequence"""', 'func': 'self.t2s.inference', 'description': '"""useful for when you want to generate a piece of singing voice (Optional: from User Input Text, Note and Duration Sequence) and save it to a file.If Like: Generate a piece of singing voice, the input to this tool should be "" since there is no User Input Text, Note and Duration Sequence .If Like: Generate a piece of singing voice. Text: xxx, Note: xxx, Duration: xxx. Or Like: Generate a piece of singing voice. Text is xxx, note is xxx, duration is xxx.The input to this tool should be a comma seperated string of three, representing text, note and duration sequence since User Input Text, Note and Duration Sequence are all provided."""'}), '(name=\n    \'Generate Singing Voice From User Input Text, Note and Duration Sequence\',\n    func=self.t2s.inference, description=\n    \'useful for when you want to generate a piece of singing voice (Optional: from User Input Text, Note and Duration Sequence) and save it to a file.If Like: Generate a piece of singing voice, the input to this tool should be "" since there is no User Input Text, Note and Duration Sequence .If Like: Generate a piece of singing voice. Text: xxx, Note: xxx, Duration: xxx. Or Like: Generate a piece of singing voice. Text is xxx, note is xxx, duration is xxx.The input to this tool should be a comma seperated string of three, representing text, note and duration sequence since User Input Text, Note and Duration Sequence are all provided.\'\n    )\n', (51285, 52061), False, 'from langchain.agents.tools import Tool\n'), ((52228, 52530), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Synthesize Speech Given the User Input Text"""', 'func': 'self.tts.inference', 'description': '"""useful for when you want to convert a user input text into speech audio it saved it to a file.The input to this tool should be a string, representing the text used to be converted to speech."""'}), "(name='Synthesize Speech Given the User Input Text', func=self.tts.\n    inference, description=\n    'useful for when you want to convert a user input text into speech audio it saved it to a file.The input to this tool should be a string, representing the text used to be converted to speech.'\n    )\n", (52232, 52530), False, 'from langchain.agents.tools import Tool\n'), ((53100, 53426), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Speech Enhancement In Single-Channel"""', 'func': 'self.SE_SS_SC.inference', 'description': '"""useful for when you want to enhance the quality of the speech signal by reducing background noise (single-channel), receives audio_path as input.The input to this tool should be a string, representing the audio_path."""'}), "(name='Speech Enhancement In Single-Channel', func=self.SE_SS_SC.\n    inference, description=\n    'useful for when you want to enhance the quality of the speech signal by reducing background noise (single-channel), receives audio_path as input.The input to this tool should be a string, representing the audio_path.'\n    )\n", (53104, 53426), False, 'from langchain.agents.tools import Tool\n'), ((53486, 53762), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Speech Separation In Single-Channel"""', 'func': 'self.SS.inference', 'description': '"""useful for when you want to separate each speech from the speech mixture, receives audio_path as input.The input to this tool should be a string, representing the audio_path."""'}), "(name='Speech Separation In Single-Channel', func=self.SS.inference,\n    description=\n    'useful for when you want to separate each speech from the speech mixture, receives audio_path as input.The input to this tool should be a string, representing the audio_path.'\n    )\n", (53490, 53762), False, 'from langchain.agents.tools import Tool\n'), ((54246, 54479), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Audio From The Image"""', 'func': 'self.i2a.inference', 'description': '"""useful for when you want to generate an audio based on an image.The input to this tool should be a string, representing the image_path. """'}), "(name='Generate Audio From The Image', func=self.i2a.inference,\n    description=\n    'useful for when you want to generate an audio based on an image.The input to this tool should be a string, representing the image_path. '\n    )\n", (54250, 54479), False, 'from langchain.agents.tools import Tool\n'), ((54541, 54792), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Text From The Audio"""', 'func': 'self.a2t.inference', 'description': '"""useful for when you want to describe an audio in text, receives audio_path as input.The input to this tool should be a string, representing the audio_path."""'}), "(name='Generate Text From The Audio', func=self.a2t.inference,\n    description=\n    'useful for when you want to describe an audio in text, receives audio_path as input.The input to this tool should be a string, representing the audio_path.'\n    )\n", (54545, 54792), False, 'from langchain.agents.tools import Tool\n'), ((54854, 55191), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Audio Inpainting"""', 'func': 'self.inpaint.show_mel_fn', 'description': '"""useful for when you want to inpaint a mel spectrum of an audio and predict this audio, this tool will generate a mel spectrum and you can inpaint it, receives audio_path as input, The input to this tool should be a string, representing the audio_path."""'}), "(name='Audio Inpainting', func=self.inpaint.show_mel_fn, description=\n    'useful for when you want to inpaint a mel spectrum of an audio and predict this audio, this tool will generate a mel spectrum and you can inpaint it, receives audio_path as input, The input to this tool should be a string, representing the audio_path.'\n    )\n", (54858, 55191), False, 'from langchain.agents.tools import Tool\n'), ((55257, 55513), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Transcribe Speech"""', 'func': 'self.asr.inference', 'description': '"""useful for when you want to know the text corresponding to a human speech, receives audio_path as input.The input to this tool should be a string, representing the audio_path."""'}), "(name='Transcribe Speech', func=self.asr.inference, description=\n    'useful for when you want to know the text corresponding to a human speech, receives audio_path as input.The input to this tool should be a string, representing the audio_path.'\n    )\n", (55261, 55513), False, 'from langchain.agents.tools import Tool\n'), ((55578, 55869), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate a talking human portrait video given a input Audio"""', 'func': 'self.geneface.inference', 'description': '"""useful for when you want to generate a talking human portrait video given a input audio.The input to this tool should be a string, representing the audio_path."""'}), "(name='Generate a talking human portrait video given a input Audio',\n    func=self.geneface.inference, description=\n    'useful for when you want to generate a talking human portrait video given a input audio.The input to this tool should be a string, representing the audio_path.'\n    )\n", (55582, 55869), False, 'from langchain.agents.tools import Tool\n'), ((55930, 56296), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Detect The Sound Event From The Audio"""', 'func': 'self.detection.inference', 'description': '"""useful for when you want to know what event in the audio and the sound event start or end time, this tool will generate an image of all predict events, receives audio_path as input. The input to this tool should be a string, representing the audio_path. """'}), "(name='Detect The Sound Event From The Audio', func=self.detection.\n    inference, description=\n    'useful for when you want to know what event in the audio and the sound event start or end time, this tool will generate an image of all predict events, receives audio_path as input. The input to this tool should be a string, representing the audio_path. '\n    )\n", (55934, 56296), False, 'from langchain.agents.tools import Tool\n'), ((56356, 56654), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Sythesize Binaural Audio From A Mono Audio Input"""', 'func': 'self.binaural.inference', 'description': '"""useful for when you want to transfer your mono audio into binaural audio, receives audio_path as input. The input to this tool should be a string, representing the audio_path. """'}), "(name='Sythesize Binaural Audio From A Mono Audio Input', func=self.\n    binaural.inference, description=\n    'useful for when you want to transfer your mono audio into binaural audio, receives audio_path as input. The input to this tool should be a string, representing the audio_path. '\n    )\n", (56360, 56654), False, 'from langchain.agents.tools import Tool\n'), ((56714, 57120), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Extract Sound Event From Mixture Audio Based On Language Description"""', 'func': 'self.extraction.inference', 'description': '"""useful for when you extract target sound from a mixture audio, you can describe the target sound by text, receives audio_path and text as input. The input to this tool should be a comma seperated string of two, representing mixture audio path and input text."""'}), "(name=\n    'Extract Sound Event From Mixture Audio Based On Language Description',\n    func=self.extraction.inference, description=\n    'useful for when you extract target sound from a mixture audio, you can describe the target sound by text, receives audio_path and text as input. The input to this tool should be a comma seperated string of two, representing mixture audio path and input text.'\n    )\n", (56718, 57120), False, 'from langchain.agents.tools import Tool\n'), ((57176, 57569), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Target Sound Detection"""', 'func': 'self.TSD.inference', 'description': '"""useful for when you want to know when the target sound event in the audio happens. You can use language descriptions to instruct the model. receives text description and audio_path as input. The input to this tool should be a comma seperated string of two, representing audio path and the text description. """'}), "(name='Target Sound Detection', func=self.TSD.inference, description=\n    'useful for when you want to know when the target sound event in the audio happens. You can use language descriptions to instruct the model. receives text description and audio_path as input. The input to this tool should be a comma seperated string of two, representing audio path and the text description. '\n    )\n", (57180, 57569), False, 'from langchain.agents.tools import Tool\n'), ((58070, 58093), 'gradio.update', 'gr.update', ([], {'visible': '(True)'}), '(visible=True)\n', (58079, 58093), True, 'import gradio as gr\n'), ((58095, 58119), 'gradio.update', 'gr.update', ([], {'visible': '(False)'}), '(visible=False)\n', (58104, 58119), True, 'import gradio as gr\n'), ((58121, 58144), 'gradio.update', 'gr.update', ([], {'visible': '(True)'}), '(visible=True)\n', (58130, 58144), True, 'import gradio as gr\n'), ((58146, 58170), 'gradio.update', 'gr.update', ([], {'visible': '(False)'}), '(visible=False)\n', (58155, 58170), True, 'import gradio as gr\n'), ((58228, 58514), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Audio From User Input Text"""', 'func': 'self.t2a.inference', 'description': '"""useful for when you want to generate an audio from a user input text and it saved it to a file.The input to this tool should be a string, representing the text used to generate audio."""'}), "(name='Generate Audio From User Input Text', func=self.t2a.inference,\n    description=\n    'useful for when you want to generate an audio from a user input text and it saved it to a file.The input to this tool should be a string, representing the text used to generate audio.'\n    )\n", (58232, 58514), False, 'from langchain.agents.tools import Tool\n'), ((58575, 59049), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Style Transfer"""', 'func': 'self.tts_ood.inference', 'description': '"""useful for when you want to generate speech samples with styles (e.g., timbre, emotion, and prosody) derived from a reference custom voice.Like: Generate a speech with style transferred from this voice. The text is xxx., or speak using the voice of this audio. The text is xxx.The input to this tool should be a comma seperated string of two, representing reference audio path and input text."""'}), "(name='Style Transfer', func=self.tts_ood.inference, description=\n    'useful for when you want to generate speech samples with styles (e.g., timbre, emotion, and prosody) derived from a reference custom voice.Like: Generate a speech with style transferred from this voice. The text is xxx., or speak using the voice of this audio. The text is xxx.The input to this tool should be a comma seperated string of two, representing reference audio path and input text.'\n    )\n", (58579, 59049), False, 'from langchain.agents.tools import Tool\n'), ((59169, 59949), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Singing Voice From User Input Text, Note and Duration Sequence"""', 'func': 'self.t2s.inference', 'description': '"""useful for when you want to generate a piece of singing voice (Optional: from User Input Text, Note and Duration Sequence) and save it to a file.If Like: Generate a piece of singing voice, the input to this tool should be "" since there is no User Input Text, Note and Duration Sequence .If Like: Generate a piece of singing voice. Text: xxx, Note: xxx, Duration: xxx. Or Like: Generate a piece of singing voice. Text is xxx, note is xxx, duration is xxx.The input to this tool should be a comma seperated string of three, representing text, note and duration sequence since User Input Text, Note and Duration Sequence are all provided."""'}), '(name=\n    \'Generate Singing Voice From User Input Text, Note and Duration Sequence\',\n    func=self.t2s.inference, description=\n    \'useful for when you want to generate a piece of singing voice (Optional: from User Input Text, Note and Duration Sequence) and save it to a file.If Like: Generate a piece of singing voice, the input to this tool should be "" since there is no User Input Text, Note and Duration Sequence .If Like: Generate a piece of singing voice. Text: xxx, Note: xxx, Duration: xxx. Or Like: Generate a piece of singing voice. Text is xxx, note is xxx, duration is xxx.The input to this tool should be a comma seperated string of three, representing text, note and duration sequence since User Input Text, Note and Duration Sequence are all provided.\'\n    )\n', (59173, 59949), False, 'from langchain.agents.tools import Tool\n'), ((60116, 60418), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Synthesize Speech Given the User Input Text"""', 'func': 'self.tts.inference', 'description': '"""useful for when you want to convert a user input text into speech audio it saved it to a file.The input to this tool should be a string, representing the text used to be converted to speech."""'}), "(name='Synthesize Speech Given the User Input Text', func=self.tts.\n    inference, description=\n    'useful for when you want to convert a user input text into speech audio it saved it to a file.The input to this tool should be a string, representing the text used to be converted to speech.'\n    )\n", (60120, 60418), False, 'from langchain.agents.tools import Tool\n'), ((60478, 60729), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Text From The Audio"""', 'func': 'self.a2t.inference', 'description': '"""useful for when you want to describe an audio in text, receives audio_path as input.The input to this tool should be a string, representing the audio_path."""'}), "(name='Generate Text From The Audio', func=self.a2t.inference,\n    description=\n    'useful for when you want to describe an audio in text, receives audio_path as input.The input to this tool should be a string, representing the audio_path.'\n    )\n", (60482, 60729), False, 'from langchain.agents.tools import Tool\n'), ((60791, 61082), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate a talking human portrait video given a input Audio"""', 'func': 'self.geneface.inference', 'description': '"""useful for when you want to generate a talking human portrait video given a input audio.The input to this tool should be a string, representing the audio_path."""'}), "(name='Generate a talking human portrait video given a input Audio',\n    func=self.geneface.inference, description=\n    'useful for when you want to generate a talking human portrait video given a input audio.The input to this tool should be a string, representing the audio_path.'\n    )\n", (60795, 61082), False, 'from langchain.agents.tools import Tool\n'), ((61143, 61440), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Generate Binaural Audio From A Mono Audio Input"""', 'func': 'self.binaural.inference', 'description': '"""useful for when you want to transfer your mono audio into binaural audio, receives audio_path as input. The input to this tool should be a string, representing the audio_path. """'}), "(name='Generate Binaural Audio From A Mono Audio Input', func=self.\n    binaural.inference, description=\n    'useful for when you want to transfer your mono audio into binaural audio, receives audio_path as input. The input to this tool should be a string, representing the audio_path. '\n    )\n", (61147, 61440), False, 'from langchain.agents.tools import Tool\n'), ((61500, 61906), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Extract Sound Event From Mixture Audio Based On Language Description"""', 'func': 'self.extraction.inference', 'description': '"""useful for when you extract target sound from a mixture audio, you can describe the target sound by text, receives audio_path and text as input. The input to this tool should be a comma seperated string of two, representing mixture audio path and input text."""'}), "(name=\n    'Extract Sound Event From Mixture Audio Based On Language Description',\n    func=self.extraction.inference, description=\n    'useful for when you extract target sound from a mixture audio, you can describe the target sound by text, receives audio_path and text as input. The input to this tool should be a comma seperated string of two, representing mixture audio path and input text.'\n    )\n", (61504, 61906), False, 'from langchain.agents.tools import Tool\n'), ((61962, 62355), 'langchain.agents.tools.Tool', 'Tool', ([], {'name': '"""Target Sound Detection"""', 'func': 'self.TSD.inference', 'description': '"""useful for when you want to know when the target sound event in the audio happens. You can use language descriptions to instruct the model. receives text description and audio_path as input. The input to this tool should be a comma seperated string of two, representing audio path and the text description. """'}), "(name='Target Sound Detection', func=self.TSD.inference, description=\n    'useful for when you want to know when the target sound event in the audio happens. You can use language descriptions to instruct the model. receives text description and audio_path as input. The input to this tool should be a comma seperated string of two, representing audio path and the text description. '\n    )\n", (61966, 62355), False, 'from langchain.agents.tools import Tool\n'), ((62864, 62888), 'gradio.update', 'gr.update', ([], {'visible': '(False)'}), '(visible=False)\n', (62873, 62888), True, 'import gradio as gr\n'), ((62890, 62914), 'gradio.update', 'gr.update', ([], {'visible': '(False)'}), '(visible=False)\n', (62899, 62914), True, 'import gradio as gr\n'), ((62916, 62940), 'gradio.update', 'gr.update', ([], {'visible': '(False)'}), '(visible=False)\n', (62925, 62940), True, 'import gradio as gr\n'), ((62942, 62965), 'gradio.update', 'gr.update', ([], {'visible': '(True)'}), '(visible=True)\n', (62951, 62965), True, 'import gradio as gr\n'), ((63585, 63615), 'gradio.Audio.update', 'gr.Audio.update', ([], {'visible': '(False)'}), '(visible=False)\n', (63600, 63615), True, 'import gradio as gr\n'), ((63617, 63647), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (63632, 63647), True, 'import gradio as gr\n'), ((63649, 63679), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (63664, 63679), True, 'import gradio as gr\n'), ((63681, 63712), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (63697, 63712), True, 'import gradio as gr\n'), ((66706, 66757), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'audio_filename', 'visible': '(True)'}), '(value=audio_filename, visible=True)\n', (66721, 66757), True, 'import gradio as gr\n'), ((66758, 66788), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (66773, 66788), True, 'import gradio as gr\n'), ((66790, 66820), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (66805, 66820), True, 'import gradio as gr\n'), ((66822, 66853), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (66838, 66853), True, 'import gradio as gr\n'), ((68295, 68346), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'audio_filename', 'visible': '(True)'}), '(value=audio_filename, visible=True)\n', (68310, 68346), True, 'import gradio as gr\n'), ((68347, 68377), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (68362, 68377), True, 'import gradio as gr\n'), ((69917, 69947), 'gradio.Audio.update', 'gr.Audio.update', ([], {'visible': '(False)'}), '(visible=False)\n', (69932, 69947), True, 'import gradio as gr\n'), ((69949, 69979), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (69964, 69979), True, 'import gradio as gr\n'), ((70735, 70762), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (70750, 70762), True, 'import gradio as gr\n'), ((70764, 70822), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'output_audio_filename', 'visible': '(True)'}), '(value=output_audio_filename, visible=True)\n', (70779, 70822), True, 'import gradio as gr\n'), ((70830, 70860), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (70845, 70860), True, 'import gradio as gr\n'), ((73858, 73885), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (73873, 73885), True, 'import gradio as gr\n'), ((73887, 73945), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'output_audio_filename', 'visible': '(True)'}), '(value=output_audio_filename, visible=True)\n', (73902, 73945), True, 'import gradio as gr\n'), ((73953, 73983), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (73968, 73983), True, 'import gradio as gr\n'), ((75732, 75752), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.7)'}), '(scale=0.7)\n', (75741, 75752), True, 'import gradio as gr\n'), ((75789, 75865), 'gradio.Radio', 'gr.Radio', ([], {'choices': "['text', 'speech']", 'value': '"""text"""', 'label': '"""Interaction Type"""'}), "(choices=['text', 'speech'], value='text', label='Interaction Type')\n", (75797, 75865), True, 'import gradio as gr\n'), ((75883, 75916), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.3)', 'min_width': '(0)'}), '(scale=0.3, min_width=0)\n', (75892, 75916), True, 'import gradio as gr\n'), ((75943, 75962), 'gradio.Button', 'gr.Button', (['"""Select"""'], {}), "('Select')\n", (75952, 75962), True, 'import gradio as gr\n'), ((76044, 76064), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.7)'}), '(scale=0.7)\n', (76053, 76064), True, 'import gradio as gr\n'), ((76219, 76252), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.1)', 'min_width': '(0)'}), '(scale=0.1, min_width=0)\n', (76228, 76252), True, 'import gradio as gr\n'), ((76276, 76301), 'gradio.Button', 'gr.Button', (['"""🏃\u200d♂️Run"""'], {}), "('🏃\\u200d♂️Run')\n", (76285, 76301), True, 'import gradio as gr\n'), ((76314, 76347), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.1)', 'min_width': '(0)'}), '(scale=0.1, min_width=0)\n', (76323, 76347), True, 'import gradio as gr\n'), ((76377, 76397), 'gradio.Button', 'gr.Button', (['"""🔄Clear️"""'], {}), "('🔄Clear️')\n", (76386, 76397), True, 'import gradio as gr\n'), ((76415, 76448), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.1)', 'min_width': '(0)'}), '(scale=0.1, min_width=0)\n', (76424, 76448), True, 'import gradio as gr\n'), ((76472, 76530), 'gradio.UploadButton', 'gr.UploadButton', (['"""🖼️Upload"""'], {'file_types': "['image', 'audio']"}), "('🖼️Upload', file_types=['image', 'audio'])\n", (76487, 76530), True, 'import gradio as gr\n'), ((76641, 76674), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.3)', 'min_width': '(0)'}), '(scale=0.3, min_width=0)\n', (76650, 76674), True, 'import gradio as gr\n'), ((76703, 76726), 'gradio.Video', 'gr.Video', ([], {'visible': '(False)'}), '(visible=False)\n', (76711, 76726), True, 'import gradio as gr\n'), ((77007, 77027), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.7)'}), '(scale=0.7)\n', (77016, 77027), True, 'import gradio as gr\n'), ((77060, 77121), 'gradio.Audio', 'gr.Audio', ([], {'source': '"""microphone"""', 'type': '"""filepath"""', 'label': '"""Input"""'}), "(source='microphone', type='filepath', label='Input')\n", (77068, 77121), True, 'import gradio as gr\n'), ((77139, 77173), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.15)', 'min_width': '(0)'}), '(scale=0.15, min_width=0)\n', (77148, 77173), True, 'import gradio as gr\n'), ((77204, 77232), 'gradio.Button', 'gr.Button', (['"""🏃\u200d♂️Submit"""'], {}), "('🏃\\u200d♂️Submit')\n", (77213, 77232), True, 'import gradio as gr\n'), ((77245, 77279), 'gradio.Column', 'gr.Column', ([], {'scale': '(0.15)', 'min_width': '(0)'}), '(scale=0.15, min_width=0)\n', (77254, 77279), True, 'import gradio as gr\n'), ((77312, 77332), 'gradio.Button', 'gr.Button', (['"""🔄Clear️"""'], {}), "('🔄Clear️')\n", (77321, 77332), True, 'import gradio as gr\n'), ((77350, 77358), 'gradio.Row', 'gr.Row', ([], {}), '()\n', (77356, 77358), True, 'import gradio as gr\n'), ((77392, 77431), 'gradio.Audio', 'gr.Audio', ([], {'label': '"""Output"""', 'visible': '(False)'}), "(label='Output', visible=False)\n", (77400, 77431), True, 'import gradio as gr\n'), ((4265, 4277), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (4275, 4277), False, 'import uuid\n'), ((6139, 6161), 'PIL.Image.open', 'Image.open', (['image_path'], {}), '(image_path)\n', (6149, 6161), False, 'from PIL import Image\n'), ((20850, 20871), 'torch.from_numpy', 'torch.from_numpy', (['mel'], {}), '(mel)\n', (20866, 20871), False, 'import torch\n'), ((20926, 20948), 'torch.from_numpy', 'torch.from_numpy', (['mask'], {}), '(mask)\n', (20942, 20948), False, 'import torch\n'), ((31997, 32012), 'sound_extraction.model.LASSNet.LASSNet', 'LASSNet', (['device'], {}), '(device)\n', (32004, 32012), False, 'from sound_extraction.model.LASSNet import LASSNet\n'), ((38499, 38549), 'librosa.feature.melspectrogram', 'librosa.feature.melspectrogram', (['y'], {}), '(y, **self.MEL_ARGS)\n', (38529, 38549), False, 'import librosa\n'), ((64244, 64274), 'gradio.Audio.update', 'gr.Audio.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64259, 64274), True, 'import gradio as gr\n'), ((64276, 64306), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64291, 64306), True, 'import gradio as gr\n'), ((64308, 64338), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64323, 64338), True, 'import gradio as gr\n'), ((64340, 64371), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64356, 64371), True, 'import gradio as gr\n'), ((71452, 71479), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (71467, 71479), True, 'import gradio as gr\n'), ((71481, 71539), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'output_audio_filename', 'visible': '(True)'}), '(value=output_audio_filename, visible=True)\n', (71496, 71539), True, 'import gradio as gr\n'), ((71547, 71577), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (71562, 71577), True, 'import gradio as gr\n'), ((5271, 5283), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (5281, 5283), False, 'import uuid\n'), ((9377, 9399), 'torch.FloatTensor', 'torch.FloatTensor', (['wav'], {}), '(wav)\n', (9394, 9399), False, 'import torch\n'), ((10120, 10132), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (10130, 10132), False, 'import uuid\n'), ((13340, 13352), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (13350, 13352), False, 'import uuid\n'), ((14308, 14320), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (14318, 14320), False, 'import uuid\n'), ((16178, 16190), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (16188, 16190), False, 'import uuid\n'), ((18075, 18087), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (18085, 18087), False, 'import uuid\n'), ((19487, 19499), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (19497, 19499), False, 'import uuid\n'), ((23290, 23302), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (23300, 23302), False, 'import uuid\n'), ((26117, 26129), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (26127, 26129), False, 'import uuid\n'), ((26232, 26244), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (26242, 26244), False, 'import uuid\n'), ((31541, 31553), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (31551, 31553), False, 'import uuid\n'), ((33070, 33082), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (33080, 33082), False, 'import uuid\n'), ((34346, 34386), 'numpy.loadtxt', 'np.loadtxt', (['self.position_file[rand_int]'], {}), '(self.position_file[rand_int])\n', (34356, 34386), True, 'import numpy as np\n'), ((36088, 36100), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (36098, 36100), False, 'import uuid\n'), ((45879, 45891), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (45889, 45891), False, 'import uuid\n'), ((47744, 47756), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (47754, 47756), False, 'import uuid\n'), ((64588, 64618), 'gradio.Audio.update', 'gr.Audio.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64603, 64618), True, 'import gradio as gr\n'), ((64620, 64650), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64635, 64650), True, 'import gradio as gr\n'), ((64652, 64682), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64667, 64682), True, 'import gradio as gr\n'), ((64684, 64715), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (64700, 64715), True, 'import gradio as gr\n'), ((70081, 70093), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (70091, 70093), False, 'import uuid\n'), ((71927, 71954), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (71942, 71954), True, 'import gradio as gr\n'), ((71956, 72014), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'output_audio_filename', 'visible': '(True)'}), '(value=output_audio_filename, visible=True)\n', (71971, 72014), True, 'import gradio as gr\n'), ((72022, 72052), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (72037, 72052), True, 'import gradio as gr\n'), ((76088, 76183), 'gradio.Textbox', 'gr.Textbox', ([], {'show_label': '(False)', 'placeholder': '"""Enter text and press enter, or upload an image"""'}), "(show_label=False, placeholder=\n    'Enter text and press enter, or upload an image')\n", (76098, 76183), True, 'import gradio as gr\n'), ((47987, 47999), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (47997, 47999), False, 'import uuid\n'), ((48159, 48171), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (48169, 48171), False, 'import uuid\n'), ((65068, 65098), 'gradio.Audio.update', 'gr.Audio.update', ([], {'visible': '(False)'}), '(visible=False)\n', (65083, 65098), True, 'import gradio as gr\n'), ((65100, 65130), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (65115, 65130), True, 'import gradio as gr\n'), ((65132, 65162), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (65147, 65162), True, 'import gradio as gr\n'), ((65164, 65195), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (65180, 65195), True, 'import gradio as gr\n'), ((67208, 67220), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (67218, 67220), False, 'import uuid\n'), ((68627, 68639), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (68637, 68639), False, 'import uuid\n'), ((72538, 72565), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (72553, 72565), True, 'import gradio as gr\n'), ((72567, 72625), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'output_audio_filename', 'visible': '(True)'}), '(value=output_audio_filename, visible=True)\n', (72582, 72625), True, 'import gradio as gr\n'), ((72633, 72663), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (72648, 72663), True, 'import gradio as gr\n'), ((65632, 65683), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'audio_filename', 'visible': '(True)'}), '(value=audio_filename, visible=True)\n', (65647, 65683), True, 'import gradio as gr\n'), ((65684, 65714), 'gradio.Video.update', 'gr.Video.update', ([], {'visible': '(False)'}), '(visible=False)\n', (65699, 65714), True, 'import gradio as gr\n'), ((65716, 65767), 'gradio.Image.update', 'gr.Image.update', ([], {'value': 'image_filename', 'visible': '(True)'}), '(value=image_filename, visible=True)\n', (65731, 65767), True, 'import gradio as gr\n'), ((65768, 65798), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(True)'}), '(visible=True)\n', (65784, 65798), True, 'import gradio as gr\n'), ((73124, 73151), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'None'}), '(value=None)\n', (73139, 73151), True, 'import gradio as gr\n'), ((73153, 73211), 'gradio.Audio.update', 'gr.Audio.update', ([], {'value': 'output_audio_filename', 'visible': '(True)'}), '(value=output_audio_filename, visible=True)\n', (73168, 73211), True, 'import gradio as gr\n'), ((73219, 73270), 'gradio.Video.update', 'gr.Video.update', ([], {'value': 'video_filename', 'visible': '(True)'}), '(value=video_filename, visible=True)\n', (73234, 73270), True, 'import gradio as gr\n'), ((66196, 66226), 'gradio.Audio.update', 'gr.Audio.update', ([], {'visible': '(False)'}), '(visible=False)\n', (66211, 66226), True, 'import gradio as gr\n'), ((66228, 66279), 'gradio.Video.update', 'gr.Video.update', ([], {'value': 'video_filename', 'visible': '(True)'}), '(value=video_filename, visible=True)\n', (66243, 66279), True, 'import gradio as gr\n'), ((66280, 66310), 'gradio.Image.update', 'gr.Image.update', ([], {'visible': '(False)'}), '(visible=False)\n', (66295, 66310), True, 'import gradio as gr\n'), ((66312, 66343), 'gradio.Button.update', 'gr.Button.update', ([], {'visible': '(False)'}), '(visible=False)\n', (66328, 66343), True, 'import gradio as gr\n')]