Adding properties to prompts

This commit is contained in:
arensc committed 2024-02-21 20:40:48 -05:00
1 parent b8270b0235
commit 29a137e4fe
4 files changed
+103 -22

No files matched your search

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use tokens::tokens::media_files::MediaFileToken;
use tokens::tokens::model_weights::ModelWeightToken;
use enums::common::visibility::Visibility;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
@@ -37,8 +38,25 @@ pub struct WorkflowArgs {
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_output_path: Option<String>,
// Upload information
// google drive link for uploads
#[serde(rename = "gd")]
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_google_drive_link: Option<String>
pub maybe_google_drive_link: Option<String>,
#[serde(rename = "ti")]
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_title: Option<String>,
#[serde(rename = "de")]
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_description: Option<String>,
#[serde(rename = "ch")]
#[serde(skip_serializing_if = "Option::is_none")]
pub maybe_commit_hash: Option<String>,
#[serde(rename = "cv")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creator_visibility: Option<Visibility>,
}
@@ -1,25 +1,29 @@
use std::time::Duration;
use anyhow::{anyhow, Result};
use log::info;
use cloud_storage::remote_file_manager::remote_cloud_file_manager::RemoteCloudFileClient;
use cloud_storage::remote_file_manager::weights_descriptor::WeightsWorkflowDescriptor;
use enums::by_table::generic_inference_jobs::inference_result_type::InferenceResultType;
use std::time::{Duration};
use cloud_storage::remote_file_manager::weights_descriptor::{WeightsSD15Descriptor, WeightsWorkflowDescriptor};
use enums::by_table::model_weights::weights_category::WeightsCategory;
use enums::by_table::model_weights::weights_types::WeightsType;
use enums::common::visibility::Visibility;
use filesys::file_exists::file_exists;
use anyhow::{anyhow, Result};
use google_drive_common::google_drive_download_command::GoogleDriveDownloadCommand;
use log::{debug, error, info, warn};
use mysql_queries::queries::model_weights::create::create_model_weight_from_voice_conversion_download_job::CreateModelWeightArgs;
use mysql_queries::queries::model_weights::create::create_weight;
use mysql_queries::queries::model_weights::create::create_weight::CreateModelWeightsArgs;
use tokens::tokens::model_weights::ModelWeightToken;
use tokens::tokens::users::UserToken;
use cloud_storage::remote_file_manager::remote_cloud_file_manager::RemoteCloudFileClient;
use enums::by_table::generic_inference_jobs::inference_result_type::InferenceResultType;
use mysql_queries::queries::media_files::create::insert_media_file_from_comfy_ui::{insert_media_file_from_comfy_ui, InsertArgs};
use mysql_queries::queries::model_weights::create::create_weight::CreateModelWeightsArgs;
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::process_job::ComfyProcessJobArgs;
use crate::job::job_types::workflow::process_single_wf_job::get_workflow_args_from_job;
use crate::job_dependencies::JobDependencies;
use crate::job::job_types::workflow::comfy_ui::process_job::ComfyProcessJobArgs;
pub async fn upload_prompt(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResult, ProcessSingleJobError>{
let job = args.job;
@@ -28,6 +32,35 @@ pub async fn upload_prompt(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessRe
let wf_args = get_workflow_args_from_job(&args).await?;
let title = match wf_args.maybe_title {
Some(val) => {
val
},
None => { "".to_string() }
};
let description = match wf_args.maybe_description {
Some(val) => {
val
},
None => { "".to_string() }
};
let commit_hash = match wf_args.maybe_commit_hash {
Some(val) => {
val
},
None => { "".to_string() }
};
let visibility = match wf_args.creator_visibility {
Some(val) => {
val
},
None => { Visibility::Public }
};
let file_name = "workflow.json";
let download_script = easyenv::get_env_string_or_default(
@@ -56,9 +89,8 @@ pub async fn upload_prompt(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessRe
return Err(ProcessSingleJobError::InvalidJob(anyhow!("Download URL Too Short")));
}
let google_drive_downloader = GoogleDriveDownloadCommand::new(
&download_script, None, None, None);
let google_drive_downloader = GoogleDriveDownloadCommand::new(&download_script,
None, None, None);
info!("Downloading {}", download_url);
let work_temp_dir = format!("workflow_upload_{}", job.id.0);
@@ -83,8 +115,10 @@ pub async fn upload_prompt(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessRe
}
info!("File Retrieved at {}", download_file_path.display());
let google_drive_downloader = GoogleDriveDownloadCommand::new(&download_script,
None, None, None);
let remote_cloud_file_client = RemoteCloudFileClient::get_remote_cloud_file_client().await?;
let remote_cloud_file_client = RemoteCloudFileClient::get_remote_cloud_file_client().await?;
let weights_sd_descriptor = Box::new(WeightsWorkflowDescriptor{});
let metadata = remote_cloud_file_client.upload_file(weights_sd_descriptor,download_file_path.to_str().unwrap_or_default()).await?;
@@ -102,19 +136,19 @@ pub async fn upload_prompt(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessRe
token: &model_weight_token,
weights_type: WeightsType::ComfyUi,
weights_category: WeightsCategory::WorkflowConfig,
title: "".parse().unwrap(),
title: title,
maybe_cover_image_media_file_token: job.maybe_cover_image_media_file_token.clone(),
maybe_description_markdown: Some("".parse().unwrap()),
maybe_description_markdown: Some(description),
maybe_description_rendered_html: None,
creator_user_token: Some(&creator_user_token),
creator_ip_address,
creator_set_visibility: Visibility::Private,
creator_set_visibility:visibility,
maybe_last_update_user_token: None,
original_download_url: Some(download_url),
original_filename: None,
// file_size_bytes: metadata.file_size_bytes, // TODO(bt,2024-02-03): We need to migrate the column to be BIGINT
file_size_bytes: 0,
file_checksum_sha2: metadata.sha256_checksum,
file_checksum_sha2: commit_hash,
public_bucket_hash: bucket_details.object_hash,
maybe_public_bucket_prefix: Some(bucket_details.prefix),
maybe_public_bucket_extension:Some(bucket_details.suffix),
@@ -211,7 +211,11 @@ pub async fn enqueue_comfy_ui_handler(
maybe_workflow_config: request.maybe_workflow_config.clone(),
maybe_input_file: request.maybe_input_file.clone(),
maybe_output_path: request.maybe_output_path.clone(),
maybe_google_drive_link: None
maybe_google_drive_link: None,
maybe_title: None,
maybe_commit_hash:None,
maybe_description:None,
creator_visibility:Some(set_visibility)
};
info!("Creating ComfyUI job record...");
@@ -56,8 +56,12 @@ const ROUTING_TAG_HEADER_NAME: &str = "routing-tag";
pub struct EnqueueWorkFlowRequest {
pub uuid_idempotency_token: String,
pub google_drive_link: String,
pub title: String,
pub description: String,
pub commit_hash: String,
// Optional cover image for workflow.
pub maybe_cover_image_media_file_token: Option<MediaFileToken>,
pub creator_set_visibility:Option<Visibility>
}
#[derive(Serialize, ToSchema)]
@@ -118,8 +122,22 @@ pub async fn enqueue_workflow_upload_request(
return Err(EnqueueWorkFlowRequestError::BadInput("Missing Google Drive Link".to_string()));
}
if request.title.is_empty() {
return Err(EnqueueWorkFlowRequestError::BadInput("Missing Title".to_string()));
}
if request.description.is_empty() {
return Err(EnqueueWorkFlowRequestError::BadInput("Missing Description".to_string()));
}
if request.commit_hash.is_empty() {
return Err(EnqueueWorkFlowRequestError::BadInput("Missing commit hash".to_string()));
}
let mut maybe_user_token: Option<UserToken> = None;
let visibility = Visibility::Private;
let visibility = request.creator_set_visibility
.unwrap_or(Visibility::Private);
let mut mysql_connection = server_state.mysql_pool.acquire().await.map_err(|err| {
warn!("MySql pool error: {:?}", err);
@@ -201,7 +219,10 @@ pub async fn enqueue_workflow_upload_request(
// ==================== INFERENCE ARGS ==================== //
let google_drive_link = request.google_drive_link.clone();
let title = request.title.clone();
let description = request.description.clone();
let commit_hash = request.commit_hash.clone();
let inference_args = WorkflowArgs {
maybe_sd_model: None,
maybe_lora_model: None,
@@ -209,7 +230,11 @@ pub async fn enqueue_workflow_upload_request(
maybe_workflow_config: None,
maybe_input_file: None,
maybe_output_path: None,
maybe_google_drive_link: Some(google_drive_link)
maybe_google_drive_link: Some(google_drive_link),
maybe_title: Some(title),
maybe_description: Some(description),
maybe_commit_hash: Some(commit_hash),
creator_visibility: Some(visibility),
};
// create the inference args here