Spaces:
Runtime error
Runtime error
dropdown>radio, t-start percentage, intro text change
Browse files19 unmodified lines2021222324252619 unmodified lines4647484950515218 unmodified lines71727374757677787980818283844 unmodified lines899091929394958 unmodified lines1041051061071081091101111121139 unmodified lines1231241251261271281291301311321331341351361371381391401411421431441451461471 unmodified line1491501511521531541551 unmodified line1571581591601611621631641651661671681691702 unmodified lines17317417517617717817918018118218318418518618740 unmodified lines22822923023123223323423523623723823924024124224324424524624724824919 unmodified linesdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")ldm2 = load_model(model_id=LDM2, device=device)ldm2_large = load_model(model_id=LDM2_LARGE, device=device)ldm2_music = load_model(model_id= MUSIC, device=device)def randomize_seed_fn(seed, randomize_seed):19 unmodified linesreturn zs, wtsdef sample(ldm_stable, zs, wts, steps, prompt_tar, tstart, cfg_scale_tar): # , ldm_stable):# reverse process (via Zs and wT)tstart = torch.tensor(tstart, dtype=torch.int)18 unmodified linesreturn f.namedef change_tstart_range(t_start, steps):maximum = int(0.8 * steps)minimum = int(0.15 * steps)if t_start > maximum:t_start = maximumelif t_start < minimum:t_start = minimumreturn t_startdef edit(input_audio,model_id: str,4 unmodified linessteps=200,cfg_scale_src=3.5,cfg_scale_tar=12,t_start=90,randomize_seed=True):# global ldm_stable, current_loaded_model8 unmodified linesldm_stable = ldm2elif model_id == LDM2_LARGE:ldm_stable = ldm2_largeelse: # MUSICldm_stable = ldm2_music# If the inversion was done for a different model, we need to re-run the inversionif not do_inversion and (saved_inv_model is None or saved_inv_model != model_id):9 unmodified lineszs = gr.State(value=zs_tensor)saved_inv_model = model_iddo_inversion = False# make sure t_start is in the right limitt_start = change_tstart_range(t_start, steps)output = sample(ldm_stable, zs.value, wts.value, steps, prompt_tar=target_prompt, tstart=t_start,cfg_scale_tar=cfg_scale_tar)return output, wts, zs, saved_inv_model, do_inversiondef get_example():case = [['Examples/Beethoven.wav','','A recording of an arcade game soundtrack.',90,'cvssp/audioldm2-music','27s','Examples/Beethoven_arcade.wav',1 unmodified line['Examples/Beethoven.wav','A high quality recording of wind instruments and strings playing.','A high quality recording of a piano playing.',90,'cvssp/audioldm2-music','27s','Examples/Beethoven_piano.wav',1 unmodified line['Examples/ModalJazz.wav','Trumpets playing alongside a piano, bass and drums in an upbeat old-timey cool jazz song.','A banjo playing alongside a piano, bass and drums in an upbeat old-timey cool country song.',90,'cvssp/audioldm2-music','106s','Examples/ModalJazz_banjo.wav',],['Examples/Cat.wav','','A dog barking.',150,'cvssp/audioldm2-large','10s','Examples/Cat_dog.wav',]2 unmodified linesintro = """<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;"> AUDI 🎧 </h1><h2 style="font-weight: 1400; text-align: center; margin-bottom: 7px;"> Audio editing Using DDPM Inversion 🎛️ </h2><h3 style="margin-bottom: 10px; text-align: center;"><a href="https://arxiv.org/abs/2402.10009">[Paper]</a> | <a href="https://hilamanor.github.io/AudioEditing/">[Project page]</a> | <a href="https://github.com/HilaManor/AudioEditingCode">[Code]</a></h3><p style="font-size:large">Demo for the method introduced in:<b <a href="https://arxiv.org/abs/2402.10009" style="text-decoration: underline;" target="_blank"> Zero-Shot Unsupervised and Text-Based Audio Editing Using DDPM Inversion </a> </b></p><p style="font-size:larger">40 unmodified linesoutput_audio = gr.Audio(label="Edited Audio", interactive=False, scale=1)with gr.Row():tar_prompt = gr.Textbox(label="Prompt", info="Describe your desired edited output", placeholder="a recording of a happy upbeat arcade game soundtrack",lines=2, interactive=True)with gr.Row():with gr.Column():submit = gr.Button("Edit")with gr.Row():t_start = gr.Slider(minimum=10, maximum=240, value=30, step=1, label="T-start", interactive=True, scale=3,info="Higher T-start -> stronger edit. Lower T-start -> closer to original audio")model_id = gr.Dropdown(label="AudioLDM2 Version", choices=["cvssp/audioldm2","cvssp/audioldm2-large","cvssp/audioldm2-music"],info="Choose a checkpoint suitable for your intended audio and edit",value="cvssp/audioldm2-music", interactive=True, type="value", scale=2)with gr.Accordion("More Options", open=False):with gr.Row():src_prompt = gr.Textbox(label="Source Prompt", lines=2, interactive=True, info= "Optional: Describe the original audio input",19 unmodified lines2021222324252619 unmodified lines46474849505118 unmodified lines707172737475767778798081828384854 unmodified lines909192939495968 unmodified lines1051061071081091101111129 unmodified lines1221231241251261271281291301311321331341351361371381391401411421431 unmodified line1451461471481491501511 unmodified line1531541551561571581591601611621631641651662 unmodified lines16917017117217317417517617717817918018118218340 unmodified lines22422522622722822923023123223323423523623723823924024124224324424524624719 unmodified linesdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")ldm2 = load_model(model_id=LDM2, device=device)ldm2_large = load_model(model_id=LDM2_LARGE, device=device)ldm2_music = load_model(model_id=MUSIC, device=device)def randomize_seed_fn(seed, randomize_seed):19 unmodified linesreturn zs, wtsdef sample(ldm_stable, zs, wts, steps, prompt_tar, tstart, cfg_scale_tar): # , ldm_stable):# reverse process (via Zs and wT)tstart = torch.tensor(tstart, dtype=torch.int)18 unmodified linesreturn f.name# def change_tstart_range(t_start, steps):# maximum = int(0.8 * steps)# minimum = int(0.15 * steps)# if t_start > maximum:# t_start = maximum# elif t_start < minimum:# t_start = minimum# return t_startdef edit(input_audio,model_id: str,4 unmodified linessteps=200,cfg_scale_src=3.5,cfg_scale_tar=12,t_start=45,randomize_seed=True):# global ldm_stable, current_loaded_model8 unmodified linesldm_stable = ldm2elif model_id == LDM2_LARGE:ldm_stable = ldm2_largeelse: # MUSICldm_stable = ldm2_music# If the inversion was done for a different model, we need to re-run the inversionif not do_inversion and (saved_inv_model is None or saved_inv_model != model_id):9 unmodified lineszs = gr.State(value=zs_tensor)saved_inv_model = model_iddo_inversion = False# make sure t_start is in the right limit# t_start = change_tstart_range(t_start, steps)output = sample(ldm_stable, zs.value, wts.value, steps, prompt_tar=target_prompt,tstart=int(t_start / 100 * steps), cfg_scale_tar=cfg_scale_tar)return output, wts, zs, saved_inv_model, do_inversiondef get_example():case = [['Examples/Beethoven.wav','','A recording of an arcade game soundtrack.',45,'cvssp/audioldm2-music','27s','Examples/Beethoven_arcade.wav',1 unmodified line['Examples/Beethoven.wav','A high quality recording of wind instruments and strings playing.','A high quality recording of a piano playing.',45,'cvssp/audioldm2-music','27s','Examples/Beethoven_piano.wav',1 unmodified line['Examples/ModalJazz.wav','Trumpets playing alongside a piano, bass and drums in an upbeat old-timey cool jazz song.','A banjo playing alongside a piano, bass and drums in an upbeat old-timey cool country song.',45,'cvssp/audioldm2-music','106s','Examples/ModalJazz_banjo.wav',],['Examples/Cat.wav','','A dog barking.',75,'cvssp/audioldm2-large','10s','Examples/Cat_dog.wav',]2 unmodified linesintro = """<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;"> ZETA Editing 🎧 </h1><h2 style="font-weight: 1400; text-align: center; margin-bottom: 7px;"> Zero-Shot Text-Based Audio Editing Using DDPM Inversion 🎛️ </h2><h3 style="margin-bottom: 10px; text-align: center;"><a href="https://arxiv.org/abs/2402.10009">[Paper]</a> | <a href="https://hilamanor.github.io/AudioEditing/">[Project page]</a> | <a href="https://github.com/HilaManor/AudioEditingCode">[Code]</a></h3><p style="font-size:large">Demo for the text-based editing method introduced in:<b <a href="https://arxiv.org/abs/2402.10009" style="text-decoration: underline;" target="_blank"> Zero-Shot Unsupervised and Text-Based Audio Editing Using DDPM Inversion </a> </b></p><p style="font-size:larger">40 unmodified linesoutput_audio = gr.Audio(label="Edited Audio", interactive=False, scale=1)with gr.Row():tar_prompt = gr.Textbox(label="Prompt", info="Describe your desired edited output", placeholder="a recording of a happy upbeat arcade game soundtrack",lines=2, interactive=True)with gr.Row():t_start = gr.Slider(minimum=15, maximum=85, value=45, step=1, label="T-start (%)", interactive=True, scale=3,info="Higher T-start -> stronger edit. Lower T-start -> closer to original audio.")# model_id = gr.Dropdown(label="AudioLDM2 Version",model_id = gr.Radio(label="AudioLDM2 Version",choices=["cvssp/audioldm2","cvssp/audioldm2-large","cvssp/audioldm2-music"],info="Choose a checkpoint suitable for your intended audio and edit",value="cvssp/audioldm2-music", interactive=True, type="value", scale=2)with gr.Row():with gr.Column():submit = gr.Button("Edit")with gr.Accordion("More Options", open=False):with gr.Row():src_prompt = gr.Textbox(label="Source Prompt", lines=2, interactive=True, info= "Optional: Describe the original audio input",
app.py+37-39