From d8fbc09867261f2fc0fd0ad928f4a30ee3a70a10 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 28 Jan 2024 05:29:57 -0500 Subject: [PATCH] fbx2gltf should work - just needs endpoint --- .../src/command_runner/command_runner.rs | 11 +- .../src/command_runner/command_runner_args.rs | 2 +- .../fbx_to_gltf/process_job.rs | 255 ++++++++---------- 3 files changed, 115 insertions(+), 153 deletions(-) diff --git a/crates/lib/subprocess_common/src/command_runner/command_runner.rs b/crates/lib/subprocess_common/src/command_runner/command_runner.rs index 996035df25..8e1d093a6d 100644 --- a/crates/lib/subprocess_common/src/command_runner/command_runner.rs +++ b/crates/lib/subprocess_common/src/command_runner/command_runner.rs @@ -45,7 +45,14 @@ pub struct CommandRunner { impl CommandRunner { /// Run the command with the `subprocess` crate utilities - pub fn run_with_subprocess(&self, args: RunAsSubprocessArgs<'_>) -> AnyhowResult { + pub fn run_with_subprocess(&self, args: RunAsSubprocessArgs<'_>) -> CommandExitStatus { + self.do_run_with_subprocess(args) + .unwrap_or_else(|err| { + CommandExitStatus::FailureWithReason { reason: format!("error: {:?}", err) } + }) + } + + fn do_run_with_subprocess(&self, args: RunAsSubprocessArgs<'_>) -> AnyhowResult { let command = self.build_command_string(&args.args); info!("Command: {:?}", command); @@ -132,7 +139,7 @@ impl CommandRunner { } } - fn build_command_string(&self, command_args: &Box) -> String { + fn build_command_string(&self, command_args: &Box<&dyn CommandArgs>) -> String { let mut command = String::new(); if let Some(execution_directory) = self.maybe_execution_directory.as_deref() { diff --git a/crates/lib/subprocess_common/src/command_runner/command_runner_args.rs b/crates/lib/subprocess_common/src/command_runner/command_runner_args.rs index 6c544020b2..7576b88498 100644 --- a/crates/lib/subprocess_common/src/command_runner/command_runner_args.rs +++ b/crates/lib/subprocess_common/src/command_runner/command_runner_args.rs @@ -17,7 +17,7 @@ pub enum FileOrCreate<'a> { pub struct RunAsSubprocessArgs<'a> { /// The args for the process we're going to call - pub args: Box, + pub args: Box<&'a dyn CommandArgs>, /// If set, write stderr to this file. pub maybe_stderr_output_file: Option>, diff --git a/crates/service/job/inference_job/src/job/job_types/format_conversion/fbx_to_gltf/process_job.rs b/crates/service/job/inference_job/src/job/job_types/format_conversion/fbx_to_gltf/process_job.rs index 7505697946..003b580354 100644 --- a/crates/service/job/inference_job/src/job/job_types/format_conversion/fbx_to_gltf/process_job.rs +++ b/crates/service/job/inference_job/src/job/job_types/format_conversion/fbx_to_gltf/process_job.rs @@ -1,14 +1,30 @@ +use std::fs::read_to_string; use std::time::Instant; use anyhow::anyhow; -use log::info; +use log::{error, info, warn}; +use buckets::public::media_files::bucket_file_path::MediaFileBucketPath; use buckets::public::media_uploads::bucket_file_path::MediaUploadOriginalFilePath; +use enums::by_table::generic_inference_jobs::inference_result_type::InferenceResultType; +use enums::by_table::generic_synthetic_ids::id_category::IdCategory; +use enums::by_table::media_files::media_file_origin_category::MediaFileOriginCategory; +use enums::by_table::media_files::media_file_origin_product_category::MediaFileOriginProductCategory; +use enums::by_table::media_files::media_file_type::MediaFileType; +use filesys::check_file_exists::check_file_exists; +use filesys::file_size::file_size; +use filesys::safe_delete_temp_directory::safe_delete_temp_directory; +use filesys::safe_delete_temp_file::safe_delete_temp_file; +use hashing::sha256::sha256_hash_file::sha256_hash_file; +use mimetypes::mimetype_for_file::get_mimetype_for_file; use mysql_queries::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob; +use mysql_queries::queries::media_files::create::insert_media_file_generic::{insert_media_file_generic, InsertArgs}; use mysql_queries::queries::media_files::get_media_file_for_inference::MediaFileForInference; +use subprocess_common::command_runner::command_runner_args::{FileOrCreate, RunAsSubprocessArgs}; -use crate::job::job_loop::job_success_result::JobSuccessResult; +use crate::job::job_loop::job_success_result::{JobSuccessResult, ResultEntity}; use crate::job::job_loop::process_single_job_error::ProcessSingleJobError; +use crate::job::job_types::format_conversion::fbx_to_gltf::command_args::FbxToGltfCommandArgs; use crate::job_dependencies::JobDependencies; use crate::util::maybe_download_file_from_bucket::{maybe_download_file_from_bucket, MaybeDownloadArgs}; @@ -30,6 +46,14 @@ pub async fn process_job(args: FbxToGltfJobArgs<'_>) -> Result) -> Result) -> Result None, - PolymorphicInferenceArgs::La(_) => None, - PolymorphicInferenceArgs::Vc { auto_predict_f0, .. } => *auto_predict_f0, - PolymorphicInferenceArgs::Rr(_) => None, - PolymorphicInferenceArgs::Ig(_) => None, - PolymorphicInferenceArgs::Mc(_) => None, - PolymorphicInferenceArgs::Cu(_) => None, - }) - .flatten() - .unwrap_or(false); - - let maybe_transpose = maybe_args - .map(|args| match args { - PolymorphicInferenceArgs::Tts { .. } => None, - PolymorphicInferenceArgs::La(_) => None, - PolymorphicInferenceArgs::Vc { transpose, .. } => *transpose, - PolymorphicInferenceArgs::Rr(_) => None, - PolymorphicInferenceArgs::Ig(_) => None, - PolymorphicInferenceArgs::Mc(_) => None, - PolymorphicInferenceArgs::Cu(_) => None, - }) - .flatten(); // ==================== RUN INFERENCE SCRIPT ==================== // - let inference_start_time = Instant::now(); + let stderr_output_file = work_temp_dir.path().join("stderr.txt"); + let output_directory = work_temp_dir.path().join("output"); + let output_directory_actual = work_temp_dir.path().join("output_out"); // NB: FBX2GLTF changes the directory name - let command_exit_status = model_dependencies - .inference_command - .execute_inference(InferenceArgs { - model_path: &so_vits_svc_fs_path, - input_path: &input_wav_path, - output_path: &output_audio_fs_path, - stderr_output_file: &stderr_output_file, - maybe_config_path: None, - device: Device::Cuda, - auto_predict_f0, - maybe_transpose, - }); + let execution_start_time = Instant::now(); - let inference_duration = Instant::now().duration_since(inference_start_time); + let command_exit_status = { + model_dependencies + .command_runner + .run_with_subprocess(RunAsSubprocessArgs { + args: Box::new(&FbxToGltfCommandArgs { + input_file: &original_media_upload_fs_path, + output_directory: &output_directory, + }), + maybe_stderr_output_file: Some(FileOrCreate::NewFileWithName(&stderr_output_file)), + maybe_stdout_output_file: None, + }) + }; - info!("Inference took duration to complete: {:?}", &inference_duration); + let execution_duration = Instant::now().duration_since(execution_start_time); + + info!("Execution took duration to complete: {:?}", &execution_duration); if !command_exit_status.is_success() { - error!("Inference failed: {:?}", command_exit_status); + error!("Execution failed: {:?}", command_exit_status); let error = ProcessSingleJobError::Other(anyhow!("CommandExitStatus: {:?}", command_exit_status)); @@ -162,8 +142,8 @@ pub async fn process_job(args: FbxToGltfJobArgs<'_>) -> Result) -> Result) -> Result, - pub mimetype: Option, - pub file_size_bytes: u64, -}