Spaces:
Runtime error
Runtime error
Jeremy Hummel commited on
Commit ·
0a72300
1
Parent(s): cda6f07
Adds options for generation
Browse filesFiles changed (2)
- app.py+10-3
- visualize.py+54-17
31 unmodified lines32333435363738394041424331 unmodified lines'https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan2/versions/1/files/stylegan2-metfacesu-1024x1024.pkl']demo = gr.Interface(fn=visualize,inputs=[gr.File(label="Audio file"),gr.Dropdown(choices=network_choices, value=network_choices[0], label="Network"),gr.Slider(minimum=0.0, value=1.0, maximum=2.0, step=0.1, label="Truncation"),gr.Slider(minimum=1, value=16, maximum=64, step=48, label="Batch Size")],outputs=gr.Video())demo.launch()31 unmodified lines3233343536373839404142434445464748495031 unmodified lines'https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan2/versions/1/files/stylegan2-metfacesu-1024x1024.pkl']demo = gr.Interface(fn=visualize,inputs=[gr.Audio(label="Audio File"),# gr.File(),gr.Dropdown(choices=network_choices, value=network_choices[0], label="Network"),gr.Slider(minimum=0.0, value=1.0, maximum=2.0, label="Truncation"),gr.Slider(minimum=0.0, value=0.25, maximum=2.0, label="Tempo Sensitivity"),gr.Slider(minimum=0.0, value=0.5, maximum=2.0, label="Jitter"),gr.Slider(minimum=64, value=512, maximum=1024, step=64, label="Frame Length (samples)"),gr.Slider(minimum=1, value=300, maximum=600, step=1, label="Max Duration (seconds)"),],outputs=gr.Video())demo.launch()
2 unmodified lines34567891011121314151617181920212223242526272829303132333411 unmodified lines4647484950515290 unmodified lines1431441451461471481491501518 unmodified lines1601611621631641651661671681691701711721731742 unmodified linesimport moviepy.editor as mpyimport randomimport torchfrom tqdm import tqdmimport stylegan3def visualize(audio_file, network, truncation, batch_size, *args, **kwargs):# print(audio_file, truncation, network)# print(args)# print(kwargs)if audio_file:print('\nReading audio \n')y, sr = librosa.load(audio_file.name)else:raise ValueError("you must enter an audio file name in the --song argument")resolution = 512duration = Noneframe_length = 512tempo_sensitivity = 0.25tempo_sensitivity = tempo_sensitivity * frame_length / 512jitter = 0.5outfile = "output.mp4"# Load pre-trained model11 unmodified linesdevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')#create spectrogramspec = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=512,fmax=8000, hop_length=frame_length)#get mean power at each time pointspecm=np.mean(spec,axis=0)90 unmodified linesframes = []for i in tqdm(range(noise_vectors.shape[0] // batch_size)):#print progresspassnoise_vector=noise_vectors[i*batch_size:(i+1)*batch_size]c = None # class labels (not used in this example)8 unmodified lines#Save videoaud = mpy.AudioFileClip(audio_file.name, fps = 44100)if duration:aud.duration = durationfps = 22050/frame_lengthclip = mpy.ImageSequenceClip(frames, fps=fps)clip = clip.set_audio(aud)clip.write_videofile(outfile, audio_codec='aac', ffmpeg_params=["-vf", "scale=-1:2160:flags=lanczos", "-bf", "2", "-g", f"{fps/2}", "-crf", "18", "-movflags", "faststart"])return outfile2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646511 unmodified lines7778798081828390 unmodified lines1741751761771781798 unmodified lines1881891901911921931941951961971981992002012022032042052062072082092102112 unmodified linesimport moviepy.editor as mpyimport randomimport torchfrom moviepy.audio.AudioClip import AudioArrayClipfrom tqdm import tqdmimport stylegan3target_sr = 22050def visualize(audio_file,network,truncation,tempo_sensitivity,jitter,frame_length,duration,):# print(audio_file, truncation, network)# print(args)# print(kwargs)if audio_file:print('\nReading audio \n')# audio, sr = librosa.load(audio_file.name)sr, audio = audio_fileelse:raise ValueError("you must enter an audio file name in the --song argument")print(sr)print(audio.dtype)print(audio.shape)if audio.shape[0] < duration * sr:duration = Noneelse:frames = duration * sraudio = audio[:frames]print(audio.dtype)print(audio.shape)if audio.dtype == np.int16:audio = audio.astype(np.float32, order='C') / 32768.0audio = audio.Taudio = librosa.to_mono(audio)audio = librosa.resample(audio, orig_sr=sr, target_sr=target_sr, res_type="kaiser_best")print(audio.dtype)print(audio.shape)if audio.shape[0] / target_sr < duration:duration = Noneelse:frames = duration * sraudio = audio[:frames]# TODO:batch_size = 1resolution = 512tempo_sensitivity = tempo_sensitivity * frame_length / 512outfile = "output.mp4"# Load pre-trained model11 unmodified linesdevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')#create spectrogramspec = librosa.feature.melspectrogram(y=audio, sr=target_sr, n_mels=512,fmax=8000, hop_length=frame_length)#get mean power at each time pointspecm=np.mean(spec,axis=0)90 unmodified linesframes = []for i in tqdm(range(noise_vectors.shape[0] // batch_size)):noise_vector=noise_vectors[i*batch_size:(i+1)*batch_size]c = None # class labels (not used in this example)8 unmodified lines#Save videosr, audio = audio_fileif audio.dtype == np.int16:audio = audio.astype(np.float32, order='C') / 32768.0with AudioArrayClip(audio, sr) as aud: # from a numeric arraypass # Close is implicitly performed by context manager.if duration is not None:aud.duration = durationfps = target_sr / frame_lengthclip = mpy.ImageSequenceClip(frames, fps=fps)clip = clip.set_audio(aud)clip.write_videofile(outfile, audio_codec='aac', ffmpeg_params=[# "-vf", "scale=-1:2160:flags=lanczos","-bf", "2","-g", f"{fps/2}","-crf", "18","-movflags", "faststart"])return outfile
app.py+10-3
visualize.py+54-17