diff --git a/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/process_so_vits_svc_model.rs b/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/process_so_vits_svc_model.rs index 765862a7ae..a5a5578e99 100644 --- a/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/process_so_vits_svc_model.rs +++ b/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/process_so_vits_svc_model.rs @@ -41,16 +41,15 @@ pub async fn process_so_vits_svc_model<'a, 'b>( let original_model_file_path = PathBuf::from(download_filename.clone()); - //let config_path = PathBuf::from("/models/voice_conversion/so-vits-svc/src/so_vits_svc_fork/configs_template/config_template.json"); // TODO: This could be variable. - let config_path = PathBuf::from("/models/voice_conversion/so-vits-svc/example_config.json"); // TODO: This could be variable. - let input_wav_path = PathBuf::from("/models/voice_conversion/so-vits-svc/example.wav"); // TODO: This could be variable. + //let config_path = PathBuf::from("/models/voice_conversion/so-vits-svc/example_config.json"); // TODO: This could be variable. + //let input_wav_path = PathBuf::from("/models/voice_conversion/so-vits-svc/example.wav"); // TODO: This could be variable. let output_wav_path = temp_dir.path().join("output.wav"); let model_check_result = job_state.sidecar_configs.so_vits_svc_model_check_command.execute_check(CheckArgs { model_path: &original_model_file_path, - input_path: &input_wav_path, + maybe_input_path: None, output_path: &output_wav_path, - config_path: &config_path, + maybe_config_path: None, device: Device::Cuda, }); diff --git a/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/so_vits_svc_model_check_command.rs b/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/so_vits_svc_model_check_command.rs index 281c188723..f6c45296c4 100644 --- a/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/so_vits_svc_model_check_command.rs +++ b/crates/service/job/download_job/src/job_types/voice_conversion/so_vits_svc/so_vits_svc_model_check_command.rs @@ -1,3 +1,4 @@ +use std::ffi::OsString; use container_common::anyhow_result::AnyhowResult; use filesys::path_to_string::path_to_string; use log::info; @@ -21,11 +22,20 @@ pub struct SoVitsSvcModelCheckCommand { /// eg. `source python/bin/activate` maybe_virtual_env_activation_command: Option, - ///// eg. `python3` - //maybe_override_python_interpreter: Option, + /// Optional default config file to use + maybe_default_config_path: Option, + + /// Optional default test wav file to use + maybe_default_test_wav_path: Option, /// If this is run under Docker (eg. in development), these are the options. maybe_docker_options: Option, + + /// Supposedly where HF caches models it downloads (have not verified this!) + maybe_huggingface_cache_dir: Option, + + /// Supposedly where NLTK caches models it downloads (have not verified this!) + maybe_nltk_cache_dir: Option, } #[derive(Clone)] @@ -47,10 +57,12 @@ pub struct CheckArgs> { pub model_path: P, /// (positional arg): input wav path - pub input_path: P, + /// This can fall back to a default value set at construction. + pub maybe_input_path: Option

, /// --config-path: path of the hparams json file - pub config_path: P, + /// This can fall back to a default value set at construction. + pub maybe_config_path: Option

, /// --output_path: output path of converting model to onnx (which we use to test validity) pub output_path: P, @@ -64,13 +76,21 @@ impl SoVitsSvcModelCheckCommand { so_vits_svc_root_code_directory: P, executable_or_command: ExecutableOrCommand, maybe_virtual_env_activation_command: Option<&str>, + maybe_default_config_path: Option

, + maybe_default_test_wav_path: Option

, maybe_docker_options: Option, + maybe_huggingface_cache_dir: Option

, + maybe_nltk_cache_dir: Option

, ) -> Self { Self { so_vits_svc_root_code_directory: so_vits_svc_root_code_directory.as_ref().to_path_buf(), executable_or_command, maybe_virtual_env_activation_command: maybe_virtual_env_activation_command.map(|s| s.to_string()), + maybe_default_config_path: maybe_default_config_path.map(|p| p.as_ref().to_path_buf()), + maybe_default_test_wav_path: maybe_default_test_wav_path.map(|p| p.as_ref().to_path_buf()), maybe_docker_options, + maybe_huggingface_cache_dir: maybe_huggingface_cache_dir.map(|s| s.as_ref().to_path_buf()), + maybe_nltk_cache_dir: maybe_nltk_cache_dir.map(|s| s.as_ref().to_path_buf()), } } @@ -98,8 +118,17 @@ impl SoVitsSvcModelCheckCommand { let maybe_virtual_env_activation_command = easyenv::get_env_string_optional( "SO_VITS_SVC_MODEL_CHECK_MAYBE_VENV_COMMAND"); - //let maybe_override_python_interpreter = easyenv::get_env_string_optional( - // "SO_VITS_SVC_MODEL_CHECK_MAYBE_PYTHON_INTERPRETER"); + let maybe_default_config_path = easyenv::get_env_pathbuf_optional( + "SO_VITS_SVC_MODEL_CHECK_MAYBE_DEFAULT_CONFIG_PATH"); + + let maybe_default_test_wav_path = easyenv::get_env_pathbuf_optional( + "SO_VITS_SVC_MODEL_CHECK_MAYBE_DEFAULT_TEST_WAV_PATH"); + + let maybe_huggingface_cache_dir = + easyenv::get_env_pathbuf_optional("HF_DATASETS_CACHE"); + + let maybe_nltk_cache_dir = + easyenv::get_env_pathbuf_optional("NLTK_DATA"); let maybe_docker_options = easyenv::get_env_string_optional( "SO_VITS_SVC_MODEL_CHECK_MAYBE_DOCKER_IMAGE") @@ -117,6 +146,10 @@ impl SoVitsSvcModelCheckCommand { executable_or_command, maybe_virtual_env_activation_command, maybe_docker_options, + maybe_default_config_path, + maybe_default_test_wav_path, + maybe_huggingface_cache_dir, + maybe_nltk_cache_dir, }) } @@ -156,8 +189,16 @@ impl SoVitsSvcModelCheckCommand { command.push_str(" --output-path "); command.push_str(&path_to_string(args.output_path)); + let config_path = match args.maybe_config_path { + Some(path) => path.as_ref().to_path_buf(), + None => match self.maybe_default_config_path.as_deref() { + Some(path) => path.to_path_buf(), + None => return Err(anyhow!("no config path supplied")), + } + }; + command.push_str(" --config-path "); - command.push_str(&path_to_string(args.config_path)); + command.push_str(&path_to_string(config_path)); let device = match args.device { Device::Cuda => "cuda", @@ -167,9 +208,17 @@ impl SoVitsSvcModelCheckCommand { command.push_str(" --device "); command.push_str(&path_to_string(device)); + let input_path = match args.maybe_input_path { + Some(path) => path.as_ref().to_path_buf(), + None => match self.maybe_default_test_wav_path.as_deref() { + Some(path) => path.to_path_buf(), + None => return Err(anyhow!("no test wav path supplied")), + } + }; + // NB: Input wav path is not a named arg command.push_str(" "); - command.push_str(&path_to_string(args.input_path)); + command.push_str(&path_to_string(input_path)); command.push_str(" "); // ===== End Python Args ===== @@ -186,9 +235,37 @@ impl SoVitsSvcModelCheckCommand { &command ]; - let mut p = Popen::create(&command_parts, PopenConfig { - ..Default::default() - })?; + let mut maybe_cache_dirs = Vec::new(); + + if let Some(cache_dir) = self.maybe_huggingface_cache_dir.as_deref() { + maybe_cache_dirs.push(( + OsString::from("HF_DATASETS_CACHE"), + OsString::from(cache_dir), + )); + maybe_cache_dirs.push(( + OsString::from("HF_HOME"), + OsString::from(cache_dir), + )); + } + + if let Some(cache_dir) = self.maybe_nltk_cache_dir.as_deref() { + maybe_cache_dirs.push(( + OsString::from("NLTK_DATA"), + OsString::from(cache_dir), + )); + maybe_cache_dirs.push(( + OsString::from("NLTK_DATA_PATH"), + OsString::from(cache_dir), + )); + } + + let mut config = PopenConfig::default(); + + if !maybe_cache_dirs.is_empty() { + config.env = Some(maybe_cache_dirs); + } + + let mut p = Popen::create(&command_parts, config)?; info!("Subprocess PID: {:?}", p.pid());