mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 08:57:54 +00:00
download IPAdapter image
This commit is contained in:
1 parent
6f69a2715a
commit
80aff2bfff
4 files changed
+123
-1
No files matched your search
@@ -38,7 +38,9 @@ pub struct MediaFile {
|
||||
|
||||
pub maybe_media_subtype: Option<MediaFileSubtype>,
|
||||
|
||||
// TODO: Other media details (file size, mime type, dimensions, duration, etc.)
|
||||
pub maybe_mime_type: Option<String>,
|
||||
|
||||
// TODO: Other media details (file size, dimensions, duration, etc.)
|
||||
// TODO: Provenance data (product, upload vs inference, model details and foreign keys)
|
||||
|
||||
pub maybe_batch_token: Option<BatchGenerationToken>,
|
||||
@@ -124,6 +126,8 @@ pub struct MediaFileRaw {
|
||||
|
||||
pub maybe_media_subtype: Option<MediaFileSubtype>,
|
||||
|
||||
pub maybe_mime_type: Option<String>,
|
||||
|
||||
pub maybe_batch_token: Option<BatchGenerationToken>,
|
||||
|
||||
pub maybe_style_transfer_source_media_file_token: Option<MediaFileToken>,
|
||||
@@ -220,6 +224,7 @@ pub async fn get_media_file(
|
||||
maybe_animation_type: record.maybe_animation_type,
|
||||
media_class: record.media_class,
|
||||
maybe_media_subtype: record.maybe_media_subtype,
|
||||
maybe_mime_type: record.maybe_mime_type,
|
||||
maybe_batch_token: record.maybe_batch_token,
|
||||
maybe_style_transfer_source_media_file_token: record.maybe_style_transfer_source_media_file_token,
|
||||
maybe_scene_source_media_file_token: record.maybe_scene_source_media_file_token,
|
||||
@@ -279,6 +284,8 @@ SELECT
|
||||
|
||||
m.maybe_media_subtype as `maybe_media_subtype: enums::by_table::media_files::media_file_subtype::MediaFileSubtype`,
|
||||
|
||||
m.maybe_mime_type,
|
||||
|
||||
users.token as `maybe_creator_user_token: tokens::tokens::users::UserToken`,
|
||||
users.username as maybe_creator_username,
|
||||
users.display_name as maybe_creator_display_name,
|
||||
@@ -381,6 +388,8 @@ SELECT
|
||||
|
||||
m.maybe_media_subtype as `maybe_media_subtype: enums::by_table::media_files::media_file_subtype::MediaFileSubtype`,
|
||||
|
||||
m.maybe_mime_type,
|
||||
|
||||
users.token as `maybe_creator_user_token: tokens::tokens::users::UserToken`,
|
||||
users.username as maybe_creator_username,
|
||||
users.display_name as maybe_creator_display_name,
|
||||
|
||||
+18
@@ -46,6 +46,7 @@ use crate::job::job_loop::process_single_job_error::ProcessSingleJobError;
|
||||
use crate::job::job_types::workflow::comfy_ui::comfy_process_job_args::ComfyProcessJobArgs;
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::comfy_ui_inference_command::{InferenceArgs, InferenceDetails};
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::steps::check_and_validate_job::check_and_validate_job;
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::steps::download_global_ipa_image::{download_global_ipa_image, DownloadGlobalIpaImageArgs};
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::steps::download_input_video::{download_input_video, DownloadInputVideoArgs};
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::steps::validate_and_save_results::{SaveResultsArgs, validate_and_save_results};
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::video_paths::VideoPaths;
|
||||
@@ -214,6 +215,23 @@ pub async fn process_job(args: ComfyProcessJobArgs<'_>) -> Result<JobSuccessResu
|
||||
|
||||
// TODO(bt,2024-04-20): Clean up this mess.
|
||||
|
||||
// ==================== DOWNLOAD GLOBAL IPA IMAGE (IF SET) ==================== //
|
||||
|
||||
let mut global_ipa_image = None;
|
||||
|
||||
if let Some(ipa_media_token) = comfy_args.global_ip_adapter_token.as_ref() {
|
||||
let results = download_global_ipa_image(DownloadGlobalIpaImageArgs {
|
||||
ipa_media_token,
|
||||
comfy_input_directory: &input_dir,
|
||||
mysql_pool: &deps.db.mysql_pool,
|
||||
remote_cloud_file_client: &remote_cloud_file_client,
|
||||
}).await?;
|
||||
|
||||
info!("Downloaded global IPA image to {:?}", results.ipa_image_path);
|
||||
|
||||
global_ipa_image = Some(results);
|
||||
}
|
||||
|
||||
// ==================== DOWNLOAD VIDEO ==================== //
|
||||
|
||||
let download_video = download_input_video(DownloadInputVideoArgs {
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use log::{error, info};
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use buckets::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use cloud_storage::remote_file_manager::remote_cloud_file_manager::RemoteCloudFileClient;
|
||||
use filesys::path_to_string::path_to_string;
|
||||
use mysql_queries::queries::media_files::get::get_media_file::{get_media_file, MediaFile};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use videos::ffprobe_get_dimensions::ffprobe_get_dimensions;
|
||||
|
||||
use crate::job::job_loop::process_single_job_error::ProcessSingleJobError;
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::steps::check_and_validate_job::JobArgs;
|
||||
use crate::job::job_types::workflow::comfy_ui::video_style_transfer::video_paths::VideoPaths;
|
||||
|
||||
const DEFAULT_SUFFIX : &str = ".jpg";
|
||||
|
||||
pub struct IpaImageDownloadDetails {
|
||||
pub input_video_media_file: MediaFile,
|
||||
pub ipa_image_path: PathBuf,
|
||||
}
|
||||
|
||||
pub struct DownloadGlobalIpaImageArgs<'a> {
|
||||
pub ipa_media_token: &'a MediaFileToken,
|
||||
pub comfy_input_directory: &'a Path,
|
||||
pub mysql_pool: &'a MySqlPool,
|
||||
pub remote_cloud_file_client: &'a RemoteCloudFileClient,
|
||||
}
|
||||
|
||||
pub async fn download_global_ipa_image(
|
||||
args: DownloadGlobalIpaImageArgs<'_>
|
||||
) -> Result<IpaImageDownloadDetails, ProcessSingleJobError> {
|
||||
|
||||
info!("Querying global IPA input media file by token: {:?} ...", &args.ipa_media_token);
|
||||
|
||||
let input_media_file = get_media_file(
|
||||
&args.ipa_media_token,
|
||||
true,
|
||||
args.mysql_pool
|
||||
).await?.ok_or_else(|| {
|
||||
error!("input global IPA media_file not found: {:?}", &args.ipa_media_token);
|
||||
ProcessSingleJobError::Other(anyhow!("input global IPA media_file not found: {:?}", &args.ipa_media_token))
|
||||
})?;
|
||||
|
||||
let media_file_bucket_path = MediaFileBucketPath::from_object_hash(
|
||||
&input_media_file.public_bucket_directory_hash,
|
||||
input_media_file.maybe_public_bucket_prefix.as_deref(),
|
||||
input_media_file.maybe_public_bucket_extension.as_deref());
|
||||
|
||||
info!("Input global IPA media file cloud bucket path: {:?}", media_file_bucket_path.get_full_object_path_str());
|
||||
|
||||
let suffix = get_suffix(&input_media_file);
|
||||
|
||||
let ipa_image_path = args.comfy_input_directory
|
||||
.join(format!("global_ipa_image{}", suffix));
|
||||
|
||||
info!("Downloading global IPA input file to {:?}", &ipa_image_path);
|
||||
|
||||
args.remote_cloud_file_client.download_media_file(
|
||||
&media_file_bucket_path,
|
||||
path_to_string(&ipa_image_path)
|
||||
).await?;
|
||||
|
||||
info!("Downloaded image!");
|
||||
|
||||
Ok(IpaImageDownloadDetails {
|
||||
input_video_media_file: input_media_file,
|
||||
ipa_image_path,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_suffix(input_media_file: &MediaFile) -> String {
|
||||
let mut suffix;
|
||||
|
||||
if let Some(extension) = input_media_file.maybe_public_bucket_extension.as_deref() {
|
||||
suffix = extension.to_string();
|
||||
} else if let Some(mime_type) = input_media_file.maybe_mime_type.as_deref() {
|
||||
suffix = match mime_type {
|
||||
"image/jpeg" => ".jpg".to_string(),
|
||||
"image/png" => ".png".to_string(),
|
||||
_ => DEFAULT_SUFFIX.to_string(),
|
||||
}
|
||||
} else {
|
||||
suffix = DEFAULT_SUFFIX.to_string();
|
||||
}
|
||||
|
||||
if !suffix.starts_with(".") {
|
||||
suffix = format!(".{}", suffix);
|
||||
}
|
||||
|
||||
suffix
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
pub mod check_and_validate_job;
|
||||
pub mod download_global_ipa_image;
|
||||
pub mod download_input_video;
|
||||
pub mod validate_and_save_results;
|
||||
Reference in new issue
Block a user