diff --git a/node.py b/node.py index 1c38cbd..baefd86 100644 --- a/node.py +++ b/node.py @@ -30,47 +30,35 @@ def generate_random_audio_name(): def get_image_url(image): - try: - image = image.squeeze(0) - image = image.permute(2, 0, 1) - image = transforms.ToPILImage()(image) + image = image.squeeze(0) + image = image.permute(2, 0, 1) + image = transforms.ToPILImage()(image) - image_name = generate_random_image_name() - save_path = os.path.join(folder_paths.get_output_directory, image_name) - torchvision.utils.save_image(image, save_path) + image_name = generate_random_image_name() + save_path = os.path.join(folder_paths.get_output_directory, image_name) + torchvision.utils.save_image(image, save_path) - if os.path.exists(image_name): - os.remove(image_name) - - return image_name + if os.path.exists(image_name): + os.remove(image_name) - except Exception as e: - if os.path.exists(image_name): - os.remove(image_name) - raise RuntimeError(f"处理图片失败: {str(e)}") + return image_name def get_audio_url(audio): - try: - waveform = audio["waveform"] - sample_rate = audio["sample_rate"] + waveform = audio["waveform"] + sample_rate = audio["sample_rate"] - if waveform.dim() == 3: - waveform = waveform.squeeze(0) + if waveform.dim() == 3: + waveform = waveform.squeeze(0) - audio_name = generate_random_audio_name() - save_path = os.path.join(folder_paths.get_output_directory, audio_name) - torchaudio.save(save_path, waveform, sample_rate, format="wav") + audio_name = generate_random_audio_name() + save_path = os.path.join(folder_paths.get_output_directory, audio_name) + torchaudio.save(save_path, waveform, sample_rate, format="wav") - if os.path.exists(audio_name): - os.remove(audio_name) + if os.path.exists(audio_name): + os.remove(audio_name) - return audio_name - - except Exception as e: - if os.path.exists(audio_name): - os.remove(audio_name) - raise RuntimeError(f"处理音频失败: {str(e)}") + return audio_name def get_model_versions(model_type: str) -> list[str]: