mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-07 02:21:23 +00:00
only supply relevant args to comfy
This commit is contained in:
1 parent
6555d10353
commit
3d0f87807e
2 files changed
+79
-53
No files matched your search
+52
-35
@@ -82,28 +82,36 @@ pub struct InferenceArgs<'s> {
|
||||
pub stderr_output_file: &'s Path,
|
||||
pub stdout_output_file: &'s Path,
|
||||
|
||||
/// Location of the prompt JSON file
|
||||
pub prompt_location: &'s Path,
|
||||
|
||||
/// Positive prompt file.
|
||||
/// If set, Python will be in charge of overwriting the prompt JSON file
|
||||
/// with the correct workflow args.
|
||||
pub maybe_positive_prompt_filename: Option<&'s Path>,
|
||||
|
||||
/// Negative prompt file.
|
||||
/// If set, Python will be in charge of overwriting the prompt JSON file
|
||||
/// with the correct workflow args.
|
||||
pub maybe_negative_prompt_filename: Option<&'s Path>,
|
||||
|
||||
/// Style name
|
||||
/// If set, Python will be in charge of overwriting the prompt JSON file
|
||||
/// with the correct workflow args.
|
||||
pub maybe_style: Option<StyleTransferName>,
|
||||
pub inference_details: InferenceDetails<'s>,
|
||||
|
||||
pub face_detailer_enabled: bool,
|
||||
pub upscaler_enabled: bool,
|
||||
}
|
||||
|
||||
pub enum InferenceDetails<'s> {
|
||||
OldRustArgs {
|
||||
/// Location of the prompt JSON file
|
||||
/// Optional: This is used if the Rust side controls this prompt JSON construction.
|
||||
prompt_location: PathBuf,
|
||||
},
|
||||
NewPythonArgs {
|
||||
/// Positive prompt file.
|
||||
/// Optional: If set, Python will be in charge of overwriting the prompt JSON file
|
||||
/// with the correct workflow args.
|
||||
maybe_positive_prompt_filename: Option<&'s Path>,
|
||||
|
||||
/// Negative prompt file.
|
||||
/// Optional: If set, Python will be in charge of overwriting the prompt JSON file
|
||||
/// with the correct workflow args.
|
||||
maybe_negative_prompt_filename: Option<&'s Path>,
|
||||
|
||||
/// Style name
|
||||
/// Optional: If set, Python will be in charge of overwriting the prompt JSON file
|
||||
/// with the correct workflow args.
|
||||
maybe_style: Option<StyleTransferName>,
|
||||
},
|
||||
}
|
||||
|
||||
impl ComfyInferenceCommand {
|
||||
pub fn from_env() -> AnyhowResult<Self> {
|
||||
let comfy_root_code_directory = easyenv::get_env_pathbuf_required(
|
||||
@@ -215,26 +223,35 @@ impl ComfyInferenceCommand {
|
||||
}
|
||||
}
|
||||
|
||||
command.push_str(" --prompt ");
|
||||
command.push_str(&path_to_string(args.prompt_location));
|
||||
command.push_str(" ");
|
||||
match args.inference_details {
|
||||
InferenceDetails::OldRustArgs { ref prompt_location } => {
|
||||
command.push_str(" --prompt ");
|
||||
command.push_str(&path_to_string(prompt_location));
|
||||
command.push_str(" ");
|
||||
}
|
||||
InferenceDetails::NewPythonArgs {
|
||||
maybe_positive_prompt_filename,
|
||||
maybe_negative_prompt_filename,
|
||||
maybe_style
|
||||
} => {
|
||||
if let Some(positive_prompt_filename) = maybe_positive_prompt_filename {
|
||||
command.push_str(" --positive_prompt_filename ");
|
||||
command.push_str(&path_to_string(positive_prompt_filename));
|
||||
command.push_str(" ");
|
||||
}
|
||||
|
||||
if let Some(positive_prompt_filename) = args.maybe_positive_prompt_filename {
|
||||
command.push_str(" --positive_prompt_filename ");
|
||||
command.push_str(&path_to_string(positive_prompt_filename));
|
||||
command.push_str(" ");
|
||||
}
|
||||
if let Some(negative_prompt_filename) = maybe_negative_prompt_filename {
|
||||
command.push_str(" --negative_prompt_filename ");
|
||||
command.push_str(&path_to_string(negative_prompt_filename));
|
||||
command.push_str(" ");
|
||||
}
|
||||
|
||||
if let Some(negative_prompt_filename) = args.maybe_negative_prompt_filename {
|
||||
command.push_str(" --negative_prompt_filename ");
|
||||
command.push_str(&path_to_string(negative_prompt_filename));
|
||||
command.push_str(" ");
|
||||
}
|
||||
|
||||
if let Some(style) = args.maybe_style {
|
||||
command.push_str(" --style ");
|
||||
command.push_str(style.to_str());
|
||||
command.push_str(" ");
|
||||
if let Some(style) = maybe_style {
|
||||
command.push_str(" --style ");
|
||||
command.push_str(style.to_str());
|
||||
command.push_str(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if args.face_detailer_enabled {
|
||||
|
||||
+27
-18
@@ -39,7 +39,7 @@ use tokens::tokens::prompts::PromptToken;
|
||||
|
||||
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::workflow::comfy_ui::comfy_ui_inference_command::InferenceArgs;
|
||||
use crate::job::job_types::workflow::comfy_ui::comfy_ui_inference_command::{InferenceArgs, InferenceDetails};
|
||||
use crate::job::job_types::workflow::comfy_ui::job_outputs::JobOutputs;
|
||||
use crate::job::job_types::workflow::comfy_ui::validate_job::validate_job;
|
||||
use crate::job_dependencies::JobDependencies;
|
||||
@@ -374,29 +374,41 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
|
||||
let inference_start_time = Instant::now();
|
||||
|
||||
let prompt_path = PathBuf::from(&workflow_path);
|
||||
|
||||
let positive_prompt_file = work_temp_dir.path().join("positive_prompt.txt");
|
||||
let negative_prompt_file = work_temp_dir.path().join("negative_prompt.txt");
|
||||
|
||||
let mut maybe_style = None;
|
||||
let mut maybe_positive_prompt_filename = None;
|
||||
let mut maybe_negative_prompt_filename = None;
|
||||
let inference_details;
|
||||
|
||||
// NB: We're rolling forward to a world where the JSON modifications are performed on the Python side.
|
||||
let python_side_orchestration = comfy_args.rollout_python_workflow_args.unwrap_or(false);
|
||||
|
||||
if python_side_orchestration {
|
||||
maybe_style = comfy_args.style_name;
|
||||
let maybe_positive_prompt_filename = comfy_args.positive_prompt
|
||||
.as_deref()
|
||||
.map(|prompt| {
|
||||
std::fs::write(&positive_prompt_file, prompt)
|
||||
.map(|_| positive_prompt_file.as_path())
|
||||
.map_err(|e| ProcessSingleJobError::IoError(e))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
if let Some(positive_prompt) = comfy_args.positive_prompt.as_deref() {
|
||||
std::fs::write(&positive_prompt_file, positive_prompt).map_err(|e| ProcessSingleJobError::IoError(e))?;
|
||||
maybe_positive_prompt_filename = Some(positive_prompt_file.as_path());
|
||||
let maybe_negative_prompt_filename = comfy_args.negative_prompt
|
||||
.as_deref()
|
||||
.map(|prompt| {
|
||||
std::fs::write(&negative_prompt_file, prompt)
|
||||
.map(|_| negative_prompt_file.as_path())
|
||||
.map_err(|e| ProcessSingleJobError::IoError(e))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
inference_details = InferenceDetails::NewPythonArgs {
|
||||
maybe_style: comfy_args.style_name,
|
||||
maybe_positive_prompt_filename,
|
||||
maybe_negative_prompt_filename,
|
||||
}
|
||||
|
||||
if let Some(negative_prompt) = comfy_args.negative_prompt.as_deref() {
|
||||
std::fs::write(&negative_prompt_file, negative_prompt).map_err(|e| ProcessSingleJobError::IoError(e))?;
|
||||
maybe_negative_prompt_filename = Some(negative_prompt_file.as_path());
|
||||
} else {
|
||||
inference_details = InferenceDetails::OldRustArgs {
|
||||
prompt_location: PathBuf::from(&workflow_path),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,10 +417,7 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
.execute_inference(InferenceArgs {
|
||||
stderr_output_file: &stderr_output_file,
|
||||
stdout_output_file: &stdout_output_file,
|
||||
prompt_location: &prompt_path,
|
||||
maybe_positive_prompt_filename,
|
||||
maybe_negative_prompt_filename,
|
||||
maybe_style,
|
||||
inference_details,
|
||||
face_detailer_enabled: comfy_args.use_face_detailer.unwrap_or(false),
|
||||
upscaler_enabled: comfy_args.use_upscaler.unwrap_or(false),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user