mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-29 04:52:51 -04:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2feefcb75b | ||
|
|
b54953bc04 | ||
|
|
29ade5fbbc | ||
|
|
d6ddf0f693 | ||
|
|
e7e816b3c2 | ||
|
|
6199f1f5a7 | ||
|
|
27ae474797 | ||
|
|
9d3d3aa98c |
@@ -1,14 +1,23 @@
|
||||
use crate::error::fal_error_plus::FalErrorPlus;
|
||||
|
||||
const BILLING_ERROR : &str = "{\"detail\": \"User is locked. Reason: Exhausted balance. Top up your balance at fal.ai/dashboard/billing.\"}";
|
||||
|
||||
/// Better classify the `fal::FalError` into a more user-friendly `FalErrorPlus`.
|
||||
pub fn classify_fal_error(err: fal::FalError) -> FalErrorPlus {
|
||||
// Other("{\"detail\": \"User is locked. Reason: Exhausted balance. Top up your balance at fal.ai/dashboard/billing.\"}")
|
||||
match err {
|
||||
fal::FalError::RequestError(_) => FalErrorPlus::FalError(err),
|
||||
fal::FalError::ImageError(_) => FalErrorPlus::FalError(err),
|
||||
fal::FalError::SerializeError(_) => FalErrorPlus::FalError(err),
|
||||
fal::FalError::StreamError(_) => FalErrorPlus::FalError(err),
|
||||
fal::FalError::Other(ref inner) => {
|
||||
if inner.contains("Invalid Key Authorization header format") {
|
||||
if inner == BILLING_ERROR {
|
||||
FalErrorPlus::FalBillingError(inner.to_string())
|
||||
} else if inner.contains("billing") {
|
||||
FalErrorPlus::FalBillingError(inner.to_string())
|
||||
} else if inner.contains("balance") {
|
||||
FalErrorPlus::FalBillingError(inner.to_string())
|
||||
} else if inner.contains("Invalid Key Authorization header format") {
|
||||
FalErrorPlus::FalApiKeyError(inner.to_string())
|
||||
} else if inner.contains("No user found for Key ID and Secret") {
|
||||
FalErrorPlus::FalApiKeyError(inner.to_string())
|
||||
|
||||
@@ -9,6 +9,8 @@ pub enum FalErrorPlus {
|
||||
FalError(fal::FalError),
|
||||
/// The fal API key is invalid.
|
||||
FalApiKeyError(String),
|
||||
/// The fal account has a billing issue
|
||||
FalBillingError(String),
|
||||
/// Another error we didn't handle.
|
||||
AnyhowError(anyhow::Error),
|
||||
/// URL parse errors.
|
||||
@@ -24,6 +26,7 @@ impl Display for FalErrorPlus {
|
||||
match self {
|
||||
Self::FalError(err) => write!(f, "FalErrorPlus::FalError: {:?}", err),
|
||||
Self::FalApiKeyError(reason) => write!(f, "FalErrorPlus::FalApiKeyError: {}", reason),
|
||||
Self::FalBillingError(reason) => write!(f, "FalErrorPlus::FalBillingError: {}", reason),
|
||||
Self::AnyhowError(err) => write!(f, "FalErrorPlus::AnyhowError: {:?}", err),
|
||||
Self::UrlParseError(err) => write!(f, "FalErrorPlus::UrlParseError: {:?}", err),
|
||||
Self::UnhandledEndpoint(endpoint) => write!(f, "FalErrorPlus::UnhandledEndpoint: {:?}", endpoint),
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::error::classify_fal_error::classify_fal_error;
|
||||
use crate::error::fal_error_plus::FalErrorPlus;
|
||||
use fal::endpoints::fal_ai::qwen_image_edit::{qwen_image_edit, QwenImageEditInput};
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct QwenImageEditArgs<'a, U: IntoUrl, R: IntoUrl> {
|
||||
// Request required
|
||||
pub prompt: &'a str,
|
||||
pub image_url: U,
|
||||
|
||||
// Request optional
|
||||
pub num_images: Option<QwenImageEditNumImages>,
|
||||
pub image_size: Option<QwenImageEditSize>,
|
||||
|
||||
// Fulfillment
|
||||
pub webhook_url: R,
|
||||
pub api_key: &'a FalApiKey,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum QwenImageEditNumImages {
|
||||
One, // Default
|
||||
Two,
|
||||
Three,
|
||||
Four,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum QwenImageEditSize {
|
||||
Square, // 1:1
|
||||
SquareHd, // 1:1
|
||||
LandscapeFourByThree, // 4:3
|
||||
LandscapeSixteenByNine, // 16:9
|
||||
PortraitThreeByFour, // 3:4
|
||||
PortraitNineBySixteen, // 9:16
|
||||
//Custom { width: u32, height: u32 }, // TODO
|
||||
}
|
||||
|
||||
pub async fn enqueue_qwen_image_edit_webhook<U: IntoUrl, R: IntoUrl>(
|
||||
args: QwenImageEditArgs<'_, U, R>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
|
||||
let num_images = args.num_images
|
||||
.map(|num| match num {
|
||||
QwenImageEditNumImages::One => 1,
|
||||
QwenImageEditNumImages::Two => 2,
|
||||
QwenImageEditNumImages::Three => 3,
|
||||
QwenImageEditNumImages::Four => 4,
|
||||
});
|
||||
|
||||
let image_size = args.image_size
|
||||
.map(|size| match size {
|
||||
QwenImageEditSize::Square => "square",
|
||||
QwenImageEditSize::SquareHd => "square_hd",
|
||||
QwenImageEditSize::LandscapeFourByThree => "landscape_4_3",
|
||||
QwenImageEditSize::LandscapeSixteenByNine => "landscape_16_9",
|
||||
QwenImageEditSize::PortraitThreeByFour => "portrait_4_3", // NB: I think they made a mistake
|
||||
QwenImageEditSize::PortraitNineBySixteen => "portrait_16_9", // NB: I think they made a mistake
|
||||
})
|
||||
.map(|size| size.to_string());
|
||||
|
||||
let request = QwenImageEditInput {
|
||||
prompt: args.prompt.to_string(),
|
||||
image_url: args.image_url.as_str().to_string(),
|
||||
image_size,
|
||||
num_images,
|
||||
|
||||
// Maybe expose
|
||||
output_format: Some("png".to_string()), // png or jpeg
|
||||
negative_prompt: None,
|
||||
seed: None,
|
||||
|
||||
// Constants
|
||||
//sync_mode: None, // Synchronous / slow
|
||||
num_inference_steps: None,
|
||||
guidance_scale: None,
|
||||
enable_safety_checker: None,
|
||||
acceleration: None,
|
||||
};
|
||||
|
||||
let result = qwen_image_edit(request)
|
||||
.with_api_key(&args.api_key.0)
|
||||
.queue_webhook(args.webhook_url)
|
||||
.await;
|
||||
|
||||
result.map_err(|err| classify_fal_error(err))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::requests::webhook::image::edit::enqueue_qwen_image_edit_webhook::{enqueue_qwen_image_edit_webhook, QwenImageEditArgs, QwenImageEditNumImages};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use test_data::web::image_urls::MOUNTAIN_TREE_IMAGE_URL;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = QwenImageEditArgs {
|
||||
image_url: MOUNTAIN_TREE_IMAGE_URL,
|
||||
prompt: "put christmas lights on the tree, add snow to the mountains",
|
||||
num_images: Some(QwenImageEditNumImages::One),
|
||||
image_size: None,
|
||||
api_key: &api_key,
|
||||
webhook_url: "https://example.com/webhook",
|
||||
};
|
||||
|
||||
let result = enqueue_qwen_image_edit_webhook(args).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::error::classify_fal_error::classify_fal_error;
|
||||
use crate::error::fal_error_plus::FalErrorPlus;
|
||||
use fal::endpoints::fal_ai::bytedance::seededit::edit_image_v3::seededit_v3_edit;
|
||||
use fal::endpoints::fal_ai::bytedance::seededit::edit_image_v3::SeedEditV3Input;
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct SeedEditV3EditArgs<'a, U: IntoUrl, R: IntoUrl> {
|
||||
// Request required
|
||||
pub prompt: &'a str,
|
||||
pub image_url: U,
|
||||
|
||||
// Fulfillment
|
||||
pub webhook_url: R,
|
||||
pub api_key: &'a FalApiKey,
|
||||
}
|
||||
|
||||
pub async fn enqueue_seededit_v3_edit_webhook<U: IntoUrl, R: IntoUrl>(
|
||||
args: SeedEditV3EditArgs<'_, U, R>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
|
||||
let request = SeedEditV3Input {
|
||||
prompt: args.prompt.to_string(),
|
||||
image_url: args.image_url.as_str().to_string(),
|
||||
|
||||
// Constants
|
||||
guidance_scale: None,
|
||||
enable_safety_checker: None,
|
||||
};
|
||||
|
||||
let result = seededit_v3_edit(request)
|
||||
.with_api_key(&args.api_key.0)
|
||||
.queue_webhook(args.webhook_url)
|
||||
.await;
|
||||
|
||||
result.map_err(|err| classify_fal_error(err))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::requests::webhook::image::edit::enqueue_seededit_v3_edit_webhook::{enqueue_seededit_v3_edit_webhook, SeedEditV3EditArgs};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use test_data::web::image_urls::MOUNTAIN_TREE_IMAGE_URL;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = SeedEditV3EditArgs {
|
||||
image_url: MOUNTAIN_TREE_IMAGE_URL,
|
||||
prompt: "put christmas lights on the tree, add snow to the mountains",
|
||||
api_key: &api_key,
|
||||
webhook_url: "https://example.com/webhook",
|
||||
};
|
||||
|
||||
let result = enqueue_seededit_v3_edit_webhook(args).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
pub mod enqueue_flux_pro_kontext_max_edit_webhook;
|
||||
pub mod enqueue_flux_pro_kontext_max_edit_webhook;
|
||||
pub mod enqueue_qwen_image_edit_webhook;
|
||||
pub mod enqueue_seededit_v3_edit_webhook;
|
||||
+1
-1
@@ -85,7 +85,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_flux_1_dev() -> AnyhowResult<()> {
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_flux_1_schnell() -> AnyhowResult<()> {
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_flux_11_pro() -> AnyhowResult<()> {
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_gpt_image_1_edit_image() -> AnyhowResult<()> {
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
let image_url = "https://cdn-2.fakeyou.com/media/3/4/h/f/s/34hfsmt8e38rvne6mwa4pwbxr6292sgy/image_34hfsmt8e38rvne6mwa4pwbxr6292sgy.png";
|
||||
|
||||
// XXX: Don't commit secrets!
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_gpt_image_1_edit_image() -> AnyhowResult<()> {
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore] // NB: Manually test, don't run in CI!
|
||||
async fn test_rembg_request() -> anyhow::Result<()> {
|
||||
async fn test() -> anyhow::Result<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let api_key = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
let api_key = FalApiKey::from_str(&api_key);
|
||||
|
||||
+18
-15
@@ -5,8 +5,9 @@ use fal::endpoints::fal_ai::kling_video::v1_6::pro::image_to_video::{image_to_vi
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct Kling16ProArgs<'a, U: IntoUrl, V: IntoUrl> {
|
||||
pub struct Kling16ProArgs<'a, U: IntoUrl, T: IntoUrl, V: IntoUrl> {
|
||||
pub image_url: U,
|
||||
pub end_frame_image_url: Option<T>,
|
||||
pub webhook_url: V,
|
||||
pub prompt: &'a str,
|
||||
pub api_key: &'a FalApiKey,
|
||||
@@ -28,8 +29,8 @@ pub enum Kling16ProAspectRatio {
|
||||
TallNineSixteen, // 9:16
|
||||
}
|
||||
|
||||
pub async fn enqueue_kling_16_pro_image_to_video_webhook<U: IntoUrl, V: IntoUrl>(
|
||||
args: Kling16ProArgs<'_, U, V>
|
||||
pub async fn enqueue_kling_16_pro_image_to_video_webhook<U: IntoUrl, T: IntoUrl, V: IntoUrl>(
|
||||
args: Kling16ProArgs<'_, U, T, V>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
let duration = match args.duration {
|
||||
Kling16Duration::Default => None,
|
||||
@@ -45,15 +46,18 @@ pub async fn enqueue_kling_16_pro_image_to_video_webhook<U: IntoUrl, V: IntoUrl>
|
||||
|
||||
let image_url = args.image_url.as_str().to_string();
|
||||
|
||||
let tail_image_url = args.end_frame_image_url
|
||||
.map(|url| url.as_str().to_string());
|
||||
|
||||
let request = ProImageToVideoRequest {
|
||||
image_url,
|
||||
tail_image_url,
|
||||
prompt: args.prompt.to_string(),
|
||||
aspect_ratio,
|
||||
duration,
|
||||
// Maybe expose these later
|
||||
cfg_scale: None,
|
||||
negative_prompt: None,
|
||||
tail_image_url: None,
|
||||
};
|
||||
|
||||
let result = image_to_video(request)
|
||||
@@ -64,35 +68,34 @@ pub async fn enqueue_kling_16_pro_image_to_video_webhook<U: IntoUrl, V: IntoUrl>
|
||||
result.map_err(|err| classify_fal_error(err))
|
||||
}
|
||||
|
||||
/*
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::requests::webhook::video::enqueue_kling_16_image_to_video_webhook::{enqueue_kling_16_image_to_video_webhook, Kling16Args, Kling16Duration};
|
||||
use crate::requests::webhook::video::enqueue_kling_16_pro_image_to_video_webhook::{enqueue_kling_16_pro_image_to_video_webhook, Kling16Duration, Kling16ProArgs, Kling16ProAspectRatio};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use testing::test_file_path::test_file_path;
|
||||
use test_data::web::image_urls::{JUNO_AT_LAKE_IMAGE_URL, TALL_MOCHI_WITH_GLASSES_IMAGE_URL};
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_kling16_video() -> AnyhowResult<()> {
|
||||
let image = test_file_path("test_data/image/juno.jpg")?;
|
||||
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = Kling16Args {
|
||||
image_path: image,
|
||||
prompt: "a corgi looks out over the water",
|
||||
let args = Kling16ProArgs {
|
||||
image_url: TALL_MOCHI_WITH_GLASSES_IMAGE_URL,
|
||||
end_frame_image_url: Some(JUNO_AT_LAKE_IMAGE_URL.to_string()),
|
||||
prompt: "shiba in glasses runs to the lake and stands by the shore",
|
||||
api_key: &api_key,
|
||||
duration: Kling16Duration::Default,
|
||||
aspect_ratio: Kling16ProAspectRatio::WideSixteenNine,
|
||||
webhook_url: "https://example.com/webhook",
|
||||
};
|
||||
|
||||
let result = enqueue_kling_16_image_to_video_webhook(args).await?;
|
||||
let result = enqueue_kling_16_pro_image_to_video_webhook(args).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
*/
|
||||
+13
-10
@@ -5,8 +5,9 @@ use fal::endpoints::fal_ai::kling_video::v2_1::pro::image_to_video::{image_to_vi
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct Kling21ProArgs<'a, U: IntoUrl, V: IntoUrl> {
|
||||
pub struct Kling21ProArgs<'a, U: IntoUrl, T: IntoUrl, V: IntoUrl> {
|
||||
pub image_url: U,
|
||||
pub end_frame_image_url: Option<T>,
|
||||
pub webhook_url: V,
|
||||
pub prompt: &'a str,
|
||||
pub api_key: &'a FalApiKey,
|
||||
@@ -28,8 +29,8 @@ pub enum Kling21ProAspectRatio {
|
||||
TallNineSixteen, // 9:16
|
||||
}
|
||||
|
||||
pub async fn enqueue_kling_21_pro_image_to_video_webhook<U: IntoUrl, V: IntoUrl>(
|
||||
args: Kling21ProArgs<'_, U, V>
|
||||
pub async fn enqueue_kling_21_pro_image_to_video_webhook<U: IntoUrl, T: IntoUrl, V: IntoUrl>(
|
||||
args: Kling21ProArgs<'_, U, T, V>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
let duration = match args.duration {
|
||||
Kling21ProDuration::Default => None,
|
||||
@@ -45,15 +46,18 @@ pub async fn enqueue_kling_21_pro_image_to_video_webhook<U: IntoUrl, V: IntoUrl>
|
||||
|
||||
let image_url = args.image_url.as_str().to_string();
|
||||
|
||||
let tail_image_url = args.end_frame_image_url
|
||||
.map(|url| url.as_str().to_string());
|
||||
|
||||
let request = ProImageToVideoRequest {
|
||||
image_url,
|
||||
prompt: args.prompt.to_string(),
|
||||
tail_image_url,
|
||||
aspect_ratio,
|
||||
duration,
|
||||
// Maybe expose these later
|
||||
cfg_scale: None,
|
||||
negative_prompt: None,
|
||||
tail_image_url: None,
|
||||
};
|
||||
|
||||
let result = image_to_video(request)
|
||||
@@ -64,27 +68,26 @@ pub async fn enqueue_kling_21_pro_image_to_video_webhook<U: IntoUrl, V: IntoUrl>
|
||||
result.map_err(|err| classify_fal_error(err))
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::requests::webhook::video::enqueue_kling_21_pro_image_to_video_webhook::{enqueue_kling_21_pro_image_to_video_webhook, Kling21ProArgs, Kling21ProAspectRatio, Kling21ProDuration};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use test_data::web::image_urls::{JUNO_AT_LAKE_IMAGE_URL, SUPER_WIDE_FALL_MOUNTAINS_IMAGE_URL};
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_kling21_pro_video() -> AnyhowResult<()> {
|
||||
let image_url = "https://cdn-2.fakeyou.com/media/3/4/h/f/s/34hfsmt8e38rvne6mwa4pwbxr6292sgy/image_34hfsmt8e38rvne6mwa4pwbxr6292sgy.png";
|
||||
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = Kling21ProArgs {
|
||||
image_url: image_url,
|
||||
prompt: "a shot of the mountains, the camera rotates around to show the mountain range",
|
||||
image_url: SUPER_WIDE_FALL_MOUNTAINS_IMAGE_URL,
|
||||
end_frame_image_url: Some(JUNO_AT_LAKE_IMAGE_URL.to_string()),
|
||||
prompt: "a shot of the mountains, the camera pulls back to show a corgi waiting to jump into the lake",
|
||||
api_key: &api_key,
|
||||
duration: Kling21ProDuration::Default,
|
||||
aspect_ratio: Kling21ProAspectRatio::WideSixteenNine,
|
||||
|
||||
+13
-8
@@ -6,8 +6,9 @@ use fal::endpoints::fal_ai::bytedance::seedance::v1::lite::image_to_video::Image
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct Seedance1LiteArgs<'a, U: IntoUrl, V: IntoUrl> {
|
||||
pub struct Seedance1LiteArgs<'a, U: IntoUrl, T: IntoUrl, V: IntoUrl> {
|
||||
pub image_url: U,
|
||||
pub end_frame_image_url: Option<T>,
|
||||
pub webhook_url: V,
|
||||
pub prompt: &'a str,
|
||||
pub api_key: &'a FalApiKey,
|
||||
@@ -29,8 +30,8 @@ pub enum Seedance1LiteResolution {
|
||||
SevenTwentyP, // 720p
|
||||
}
|
||||
|
||||
pub async fn enqueue_seedance_1_lite_image_to_video_webhook<U: IntoUrl, V: IntoUrl>(
|
||||
args: Seedance1LiteArgs<'_, U, V>
|
||||
pub async fn enqueue_seedance_1_lite_image_to_video_webhook<U: IntoUrl, T: IntoUrl, V: IntoUrl>(
|
||||
args: Seedance1LiteArgs<'_, U, T, V>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
let duration = match args.duration {
|
||||
Seedance1LiteDuration::FiveSeconds => Some("5".to_string()),
|
||||
@@ -44,8 +45,12 @@ pub async fn enqueue_seedance_1_lite_image_to_video_webhook<U: IntoUrl, V: IntoU
|
||||
|
||||
let image_url = args.image_url.as_str().to_string();
|
||||
|
||||
let end_image_url = args.end_frame_image_url
|
||||
.map(|url| url.as_str().to_string());
|
||||
|
||||
let request = ImageToVideoRequest {
|
||||
image_url,
|
||||
end_image_url,
|
||||
prompt: args.prompt.to_string(),
|
||||
duration,
|
||||
resolution,
|
||||
@@ -69,20 +74,20 @@ mod tests {
|
||||
use crate::requests::webhook::video::enqueue_seedance_1_lite_image_to_video_webhook::{enqueue_seedance_1_lite_image_to_video_webhook, Seedance1LiteArgs, Seedance1LiteDuration, Seedance1LiteResolution};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use test_data::web::image_urls::{JUNO_AT_LAKE_IMAGE_URL, TALL_MOCHI_WITH_GLASSES_IMAGE_URL};
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test_kling21_pro_video() -> AnyhowResult<()> {
|
||||
let image_url = "https://cdn-2.fakeyou.com/media/3/4/h/f/s/34hfsmt8e38rvne6mwa4pwbxr6292sgy/image_34hfsmt8e38rvne6mwa4pwbxr6292sgy.png";
|
||||
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = Seedance1LiteArgs {
|
||||
image_url: image_url,
|
||||
prompt: "a shot of the mountains as the sun sets and reveals the moon and stars",
|
||||
image_url: TALL_MOCHI_WITH_GLASSES_IMAGE_URL,
|
||||
end_frame_image_url: Some(JUNO_AT_LAKE_IMAGE_URL.to_string()),
|
||||
prompt: "shiba in glasses runs to the lake and stands by the shore",
|
||||
api_key: &api_key,
|
||||
camera_fixed: false,
|
||||
duration: Seedance1LiteDuration::FiveSeconds,
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::error::classify_fal_error::classify_fal_error;
|
||||
use crate::error::fal_error_plus::FalErrorPlus;
|
||||
use fal::endpoints::fal_ai::veo3::image_to_video_fast::{image_to_video_fast, ImageToVideoFastInput};
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct Veo3FastArgs<'a, U: IntoUrl, V: IntoUrl> {
|
||||
pub prompt: &'a str,
|
||||
pub image_url: U,
|
||||
pub duration: Veo3FastDuration,
|
||||
pub api_key: &'a FalApiKey,
|
||||
pub resolution: Veo3FastResolution,
|
||||
pub generate_audio: bool,
|
||||
pub webhook_url: V,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Veo3FastDuration {
|
||||
Default,
|
||||
EightSeconds,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Veo3FastResolution {
|
||||
Default,
|
||||
SevenTwentyP,
|
||||
TenEightyP,
|
||||
}
|
||||
|
||||
pub async fn enqueue_veo_3_fast_image_to_video_webhook<U: IntoUrl, V: IntoUrl>(
|
||||
args: Veo3FastArgs<'_, U, V>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
let duration = match args.duration {
|
||||
Veo3FastDuration::Default => None,
|
||||
Veo3FastDuration::EightSeconds => Some("8s".to_string()),
|
||||
};
|
||||
|
||||
let resolution= match args.resolution {
|
||||
Veo3FastResolution::Default => None,
|
||||
Veo3FastResolution::SevenTwentyP => Some("720p".to_string()),
|
||||
Veo3FastResolution::TenEightyP => Some("1080p".to_string()),
|
||||
};
|
||||
|
||||
let image_url = args.image_url.as_str().to_string();
|
||||
|
||||
let request = ImageToVideoFastInput {
|
||||
image_url,
|
||||
prompt: args.prompt.to_string(),
|
||||
resolution,
|
||||
duration,
|
||||
generate_audio: Some(args.generate_audio),
|
||||
};
|
||||
|
||||
let result = image_to_video_fast(request)
|
||||
.with_api_key(&args.api_key.0)
|
||||
.queue_webhook(args.webhook_url)
|
||||
.await;
|
||||
|
||||
result.map_err(|err| classify_fal_error(err))
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::requests::webhook::video::enqueue_veo_3_fast_image_to_video_webhook::{enqueue_veo_3_fast_image_to_video_webhook, Veo3FastArgs, Veo3FastDuration, Veo3FastResolution};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use test_data::web::image_urls::ERNEST_GHOST_TREX_IMAGE_URL;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
let image_url = ERNEST_GHOST_TREX_IMAGE_URL;
|
||||
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = Veo3FastArgs {
|
||||
image_url: image_url,
|
||||
prompt: "man is standing next to a ghost and t-rex, they begin to chase him as the camera pulls back to show the wider scene",
|
||||
api_key: &api_key,
|
||||
duration: Veo3FastDuration::EightSeconds,
|
||||
generate_audio: true,
|
||||
resolution: Veo3FastResolution::TenEightyP,
|
||||
webhook_url: "https://example.com/webhook",
|
||||
};
|
||||
|
||||
let result = enqueue_veo_3_fast_image_to_video_webhook(args).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::error::classify_fal_error::classify_fal_error;
|
||||
use crate::error::fal_error_plus::FalErrorPlus;
|
||||
use fal::endpoints::fal_ai::veo3::image_to_video::{image_to_video, ImageToVideoInput};
|
||||
use fal::webhook::WebhookResponse;
|
||||
use reqwest::IntoUrl;
|
||||
|
||||
pub struct Veo3Args<'a, U: IntoUrl, V: IntoUrl> {
|
||||
pub prompt: &'a str,
|
||||
pub image_url: U,
|
||||
pub duration: Veo3Duration,
|
||||
pub api_key: &'a FalApiKey,
|
||||
pub resolution: Veo3Resolution,
|
||||
pub generate_audio: bool,
|
||||
pub webhook_url: V,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Veo3Duration {
|
||||
Default,
|
||||
EightSeconds,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum Veo3Resolution {
|
||||
Default,
|
||||
SevenTwentyP,
|
||||
TenEightyP,
|
||||
}
|
||||
|
||||
pub async fn enqueue_veo_3_image_to_video_webhook<U: IntoUrl, V: IntoUrl>(
|
||||
args: Veo3Args<'_, U, V>
|
||||
) -> Result<WebhookResponse, FalErrorPlus> {
|
||||
let duration = match args.duration {
|
||||
Veo3Duration::Default => None,
|
||||
Veo3Duration::EightSeconds => Some("8s".to_string()),
|
||||
};
|
||||
|
||||
let resolution= match args.resolution {
|
||||
Veo3Resolution::Default => None,
|
||||
Veo3Resolution::SevenTwentyP => Some("720p".to_string()),
|
||||
Veo3Resolution::TenEightyP => Some("1080p".to_string()),
|
||||
};
|
||||
|
||||
let image_url = args.image_url.as_str().to_string();
|
||||
|
||||
let request = ImageToVideoInput {
|
||||
image_url,
|
||||
prompt: args.prompt.to_string(),
|
||||
resolution,
|
||||
duration,
|
||||
generate_audio: Some(args.generate_audio),
|
||||
};
|
||||
|
||||
let result = image_to_video(request)
|
||||
.with_api_key(&args.api_key.0)
|
||||
.queue_webhook(args.webhook_url)
|
||||
.await;
|
||||
|
||||
result.map_err(|err| classify_fal_error(err))
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::creds::fal_api_key::FalApiKey;
|
||||
use crate::requests::webhook::video::enqueue_veo_3_image_to_video_webhook::{enqueue_veo_3_image_to_video_webhook, Veo3Args, Veo3Duration, Veo3Resolution};
|
||||
use errors::AnyhowResult;
|
||||
use std::fs::read_to_string;
|
||||
use test_data::web::image_urls::JUNO_AT_LAKE_IMAGE_URL;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore]
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
let image_url = JUNO_AT_LAKE_IMAGE_URL;
|
||||
|
||||
// XXX: Don't commit secrets!
|
||||
let secret = read_to_string("/Users/bt/Artcraft/credentials/fal_api_key.txt")?;
|
||||
|
||||
let api_key = FalApiKey::from_str(&secret);
|
||||
|
||||
let args = Veo3Args {
|
||||
image_url: image_url,
|
||||
prompt: "corgi at the lake. the corgi barks. camera pulls back to show a wider shot of the lake as the corgi jumps into the water. there are sounds of barking and splashing. cinematic, 8k, ultra wide shot",
|
||||
api_key: &api_key,
|
||||
duration: Veo3Duration::EightSeconds,
|
||||
generate_audio: true,
|
||||
resolution: Veo3Resolution::TenEightyP,
|
||||
webhook_url: "https://example.com/webhook",
|
||||
};
|
||||
|
||||
let result = enqueue_veo_3_image_to_video_webhook(args).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,6 @@ pub mod enqueue_kling_16_pro_image_to_video_webhook;
|
||||
pub mod enqueue_kling_21_master_image_to_video_webhook;
|
||||
pub mod enqueue_kling_21_pro_image_to_video_webhook;
|
||||
pub mod enqueue_seedance_1_lite_image_to_video_webhook;
|
||||
pub mod enqueue_veo_2_image_to_video_webhook;
|
||||
pub mod enqueue_veo_2_image_to_video_webhook;
|
||||
pub mod enqueue_veo_3_fast_image_to_video_webhook;
|
||||
pub mod enqueue_veo_3_image_to_video_webhook;
|
||||
+14
-6
@@ -23,14 +23,22 @@ use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct EnqueueImageToVideoRequest {
|
||||
/// Image media file; the image to remove the background from.
|
||||
/// TODO: In the future we may support base64 images, URLs, or file paths here.
|
||||
pub image_media_token: Option<MediaFileToken>,
|
||||
|
||||
/// REQUIRED.
|
||||
/// The model to use.
|
||||
pub model: Option<VideoModel>,
|
||||
|
||||
/// Optional text prompt.
|
||||
|
||||
/// Currently REQUIRED.
|
||||
/// Image media file; the starting frame of the video.
|
||||
/// TODO: In the future we may support base64 images, URLs, or file paths here.
|
||||
pub image_media_token: Option<MediaFileToken>,
|
||||
|
||||
/// Optional.
|
||||
/// Image media file; the image to remove the background from.
|
||||
/// TODO: In the future we may support base64 images, URLs, or file paths here.
|
||||
pub end_frame_image_media_token: Option<MediaFileToken>,
|
||||
|
||||
/// Optional.
|
||||
/// Text prompt used to direct the video.
|
||||
pub prompt: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -76,6 +76,7 @@ pub async fn handle_video_artcraft(
|
||||
let request = GenerateKling16ProImageToVideoRequest {
|
||||
uuid_idempotency_token,
|
||||
media_file_token: request.image_media_token,
|
||||
end_frame_image_media_token: request.end_frame_image_media_token,
|
||||
aspect_ratio: Some(GenerateKling16ProAspectRatio::WideSixteenNine),
|
||||
prompt: request.prompt,
|
||||
duration: None,
|
||||
@@ -128,6 +129,7 @@ pub async fn handle_video_artcraft(
|
||||
let request = GenerateKling21ProImageToVideoRequest {
|
||||
uuid_idempotency_token,
|
||||
media_file_token: request.image_media_token,
|
||||
end_frame_image_media_token: request.end_frame_image_media_token,
|
||||
aspect_ratio: Some(GenerateKling21ProAspectRatio::WideSixteenNine),
|
||||
prompt: request.prompt,
|
||||
duration: None,
|
||||
@@ -154,6 +156,7 @@ pub async fn handle_video_artcraft(
|
||||
let request = GenerateSeedance10LiteImageToVideoRequest {
|
||||
uuid_idempotency_token,
|
||||
media_file_token: request.image_media_token,
|
||||
end_frame_image_media_token: request.end_frame_image_media_token,
|
||||
prompt: request.prompt,
|
||||
resolution: None,
|
||||
duration: None,
|
||||
|
||||
@@ -22,7 +22,7 @@ pub const MOUNTAIN_TREE_IMAGE_URL :&str = "https://cdn-2.fakeyou.com/media/3/4/h
|
||||
pub const WHITE_HOUSE_SUNSET_IMAGE_URL : &str = "https://cdn-2.fakeyou.com/media/q/t/z/w/k/qtzwka8dd0g2nfyk94k1qh3zzfwqtfhn/asset_qtzwka8dd0g2nfyk94k1qh3zzfwqtfhn.jpg";
|
||||
|
||||
// media token: m_z61yg5w7dnnvhb1f9sqt8jf02y61bv
|
||||
pub const WIDE_FALL_MOUNTAINS_IMAGE_URL : &str = "https://cdn-2.fakeyou.com/media/w/6/m/j/p/w6mjpcqkky7f2f3xkyvkcv3qeedkmejs/asset_w6mjpcqkky7f2f3xkyvkcv3qeedkmejs.jpg";
|
||||
pub const SUPER_WIDE_FALL_MOUNTAINS_IMAGE_URL: &str = "https://cdn-2.fakeyou.com/media/w/6/m/j/p/w6mjpcqkky7f2f3xkyvkcv3qeedkmejs/asset_w6mjpcqkky7f2f3xkyvkcv3qeedkmejs.jpg";
|
||||
|
||||
// media token: m_m1bz02z1kkzanxy6rb4vk1kvq9de9g
|
||||
pub const JUNO_AT_LAKE_IMAGE_URL : &str = "https://cdn-2.fakeyou.com/media/s/v/c/p/p/svcpp441gyb6mjtt8413kf5zxw1ehy4t/upload_svcpp441gyb6mjtt8413kf5zxw1ehy4t.jpg";
|
||||
|
||||
+5
-1
@@ -13,7 +13,11 @@ pub struct GenerateKling16ProImageToVideoRequest {
|
||||
/// Source of the image file to convert to video.
|
||||
/// It must be an image.
|
||||
pub media_file_token: Option<MediaFileToken>,
|
||||
|
||||
|
||||
/// Optional.
|
||||
/// Image media file; the image to remove the background from.
|
||||
pub end_frame_image_media_token: Option<MediaFileToken>,
|
||||
|
||||
/// Optional text prompt.
|
||||
pub prompt: Option<String>,
|
||||
|
||||
|
||||
+4
@@ -13,6 +13,10 @@ pub struct GenerateKling21ProImageToVideoRequest {
|
||||
/// Source of the image file to convert to video.
|
||||
/// It must be an image.
|
||||
pub media_file_token: Option<MediaFileToken>,
|
||||
|
||||
/// Optional.
|
||||
/// Image media file; the image to remove the background from.
|
||||
pub end_frame_image_media_token: Option<MediaFileToken>,
|
||||
|
||||
/// Optional text prompt.
|
||||
pub prompt: Option<String>,
|
||||
|
||||
+5
-1
@@ -13,7 +13,11 @@ pub struct GenerateSeedance10LiteImageToVideoRequest {
|
||||
/// Source of the image file to convert to video.
|
||||
/// It must be an image.
|
||||
pub media_file_token: Option<MediaFileToken>,
|
||||
|
||||
|
||||
/// Optional.
|
||||
/// Image media file; the image to remove the background from.
|
||||
pub end_frame_image_media_token: Option<MediaFileToken>,
|
||||
|
||||
/// Optional text prompt.
|
||||
pub prompt: Option<String>,
|
||||
|
||||
|
||||
+53
-38
@@ -5,6 +5,8 @@ use crate::http_server::common_responses::media::media_links_builder::MediaLinks
|
||||
use crate::http_server::endpoints::media_files::helpers::get_media_domain::get_media_domain;
|
||||
use crate::http_server::validations::validate_idempotency_token_format::validate_idempotency_token_format;
|
||||
use crate::state::server_state::ServerState;
|
||||
use crate::util::lookup::fetch_all_required_media_files::fetch_all_required_media_files;
|
||||
use crate::util::traits::into_media_links_trait::IntoMediaLinks;
|
||||
use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest};
|
||||
use artcraft_api_defs::generate::video::generate_kling_1_6_pro_image_to_video::{GenerateKling16ProAspectRatio, GenerateKling16ProImageToVideoRequest};
|
||||
@@ -24,6 +26,7 @@ use mysql_queries::queries::generic_inference::fal::insert_generic_inference_job
|
||||
use mysql_queries::queries::generic_inference::fal::insert_generic_inference_job_for_fal_queue::FalCategory;
|
||||
use mysql_queries::queries::generic_inference::fal::insert_generic_inference_job_for_fal_queue::InsertGenericInferenceForFalArgs;
|
||||
use mysql_queries::queries::idepotency_tokens::insert_idempotency_token::insert_idempotency_token;
|
||||
use mysql_queries::queries::media_files::get::batch_get_media_files_by_tokens::batch_get_media_files_by_tokens_with_connection;
|
||||
use mysql_queries::queries::media_files::get::get_media_file::get_media_file_with_connection;
|
||||
use mysql_queries::queries::prompts::insert_prompt::{insert_prompt, InsertPromptArgs};
|
||||
use sqlx::Acquire;
|
||||
@@ -73,14 +76,35 @@ pub async fn generate_kling_1_6_pro_video_handler(
|
||||
// }
|
||||
//};
|
||||
|
||||
let media_file_token = match &request.media_file_token {
|
||||
let start_frame_media_file_token = match &request.media_file_token {
|
||||
Some(token) => token,
|
||||
None => {
|
||||
warn!("No media file token provided");
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("No media file token provided".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mut tokens = vec![
|
||||
start_frame_media_file_token.clone(),
|
||||
];
|
||||
|
||||
let maybe_end_frame_image_media_token = request.end_frame_image_media_token.as_ref();
|
||||
|
||||
if let Some(end_frame_token) = maybe_end_frame_image_media_token {
|
||||
tokens.push(end_frame_token.clone());
|
||||
}
|
||||
|
||||
let media_files = fetch_all_required_media_files(
|
||||
&mut mysql_connection,
|
||||
&tokens,
|
||||
).await?;
|
||||
|
||||
for media_file in media_files.iter() {
|
||||
if !media_file.media_type.is_jpg_or_png_or_legacy_image() {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("Media file must be a JPG or PNG image".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(reason) = validate_idempotency_token_format(&request.uuid_idempotency_token) {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage(reason));
|
||||
}
|
||||
@@ -91,42 +115,30 @@ pub async fn generate_kling_1_6_pro_video_handler(
|
||||
error!("Error inserting idempotency token: {:?}", err);
|
||||
CommonWebError::BadInputWithSimpleMessage("invalid idempotency token".to_string())
|
||||
})?;
|
||||
const IS_MOD : bool = false;
|
||||
|
||||
let media_file_lookup_result = get_media_file_with_connection(
|
||||
media_file_token,
|
||||
IS_MOD,
|
||||
&mut mysql_connection,
|
||||
).await;
|
||||
|
||||
let media_file = match media_file_lookup_result {
|
||||
Ok(Some(media_file)) => media_file,
|
||||
Ok(None) => {
|
||||
warn!("MediaFile not found: {:?}", media_file_token);
|
||||
return Err(CommonWebError::NotFound);
|
||||
},
|
||||
Err(err) => {
|
||||
warn!("Error looking up media_file: {:?}", err);
|
||||
return Err(CommonWebError::ServerError);
|
||||
}
|
||||
let media_domain = get_media_domain(&http_request);
|
||||
|
||||
let start_frame_url = media_files.iter()
|
||||
.find(|file| &file.token == start_frame_media_file_token)
|
||||
.map(|file| file.to_media_links(media_domain, server_state.server_environment))
|
||||
.map(|file| file.cdn_url)
|
||||
.ok_or_else(|| {
|
||||
warn!("Start frame media file not found after fetch");
|
||||
CommonWebError::NotFound
|
||||
})?;
|
||||
|
||||
let maybe_end_frame_url = match maybe_end_frame_image_media_token {
|
||||
None => None,
|
||||
Some(end_frame_token) => Some(media_files.iter()
|
||||
.find(|file| &file.token == end_frame_token)
|
||||
.map(|file| file.to_media_links(media_domain, server_state.server_environment))
|
||||
.map(|file| file.cdn_url)
|
||||
.ok_or_else(|| {
|
||||
warn!("End frame media file not found after fetch");
|
||||
CommonWebError::NotFound
|
||||
})?),
|
||||
};
|
||||
|
||||
if !media_file.media_type.is_jpg_or_png_or_legacy_image() {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("Media file must be a JPG or PNG image".to_string()));
|
||||
}
|
||||
|
||||
let media_domain = get_media_domain(&http_request);
|
||||
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash(
|
||||
&media_file.public_bucket_directory_hash,
|
||||
media_file.maybe_public_bucket_prefix.as_deref(),
|
||||
media_file.maybe_public_bucket_extension.as_deref());
|
||||
|
||||
let media_links = MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&bucket_path);
|
||||
|
||||
info!("Fal webhook URL: {}", server_state.fal.webhook_url);
|
||||
|
||||
let prompt = request.prompt
|
||||
@@ -146,9 +158,10 @@ pub async fn generate_kling_1_6_pro_video_handler(
|
||||
Some(GenerateKling16ProDuration::TenSeconds) => Kling16Duration::TenSeconds,
|
||||
None => Kling16Duration::FiveSeconds,
|
||||
};
|
||||
|
||||
|
||||
let args = Kling16ProArgs {
|
||||
image_url: media_links.cdn_url,
|
||||
image_url: start_frame_url,
|
||||
end_frame_image_url: maybe_end_frame_url,
|
||||
webhook_url: &server_state.fal.webhook_url,
|
||||
duration,
|
||||
prompt,
|
||||
@@ -159,7 +172,7 @@ pub async fn generate_kling_1_6_pro_video_handler(
|
||||
let fal_result = enqueue_kling_16_pro_image_to_video_webhook(args)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("Error calling remove_background_rembg_webhook: {:?}", err);
|
||||
warn!("Error calling enqueue_kling_16_pro_image_to_video_webhook: {:?}", err);
|
||||
CommonWebError::ServerError
|
||||
})?;
|
||||
|
||||
@@ -206,6 +219,8 @@ pub async fn generate_kling_1_6_pro_video_handler(
|
||||
}
|
||||
};
|
||||
|
||||
// TODO(bt,2025-08-26): Save reference images.
|
||||
|
||||
let db_result = insert_generic_inference_job_for_fal_queue(InsertGenericInferenceForFalArgs {
|
||||
uuid_idempotency_token: &request.uuid_idempotency_token,
|
||||
maybe_external_third_party_id: &external_job_id,
|
||||
|
||||
+48
-36
@@ -28,6 +28,8 @@ use mysql_queries::queries::media_files::get::get_media_file::{get_media_file, g
|
||||
use mysql_queries::queries::prompts::insert_prompt::{insert_prompt, InsertPromptArgs};
|
||||
use sqlx::Acquire;
|
||||
use utoipa::ToSchema;
|
||||
use crate::util::lookup::fetch_all_required_media_files::fetch_all_required_media_files;
|
||||
use crate::util::traits::into_media_links_trait::IntoMediaLinks;
|
||||
|
||||
/// Kling 2.1 Pro Image to Video
|
||||
#[utoipa::path(
|
||||
@@ -73,14 +75,35 @@ pub async fn generate_kling_2_1_pro_video_handler(
|
||||
// }
|
||||
//};
|
||||
|
||||
let media_file_token = match &request.media_file_token {
|
||||
let start_frame_media_file_token = match &request.media_file_token {
|
||||
Some(token) => token,
|
||||
None => {
|
||||
warn!("No media file token provided");
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("No media file token provided".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mut tokens = vec![
|
||||
start_frame_media_file_token.clone(),
|
||||
];
|
||||
|
||||
let maybe_end_frame_image_media_token = request.end_frame_image_media_token.as_ref();
|
||||
|
||||
if let Some(end_frame_token) = maybe_end_frame_image_media_token {
|
||||
tokens.push(end_frame_token.clone());
|
||||
}
|
||||
|
||||
let media_files = fetch_all_required_media_files(
|
||||
&mut mysql_connection,
|
||||
&tokens,
|
||||
).await?;
|
||||
|
||||
for media_file in media_files.iter() {
|
||||
if !media_file.media_type.is_jpg_or_png_or_legacy_image() {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("Media file must be a JPG or PNG image".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(reason) = validate_idempotency_token_format(&request.uuid_idempotency_token) {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage(reason));
|
||||
}
|
||||
@@ -91,42 +114,30 @@ pub async fn generate_kling_2_1_pro_video_handler(
|
||||
error!("Error inserting idempotency token: {:?}", err);
|
||||
CommonWebError::BadInputWithSimpleMessage("invalid idempotency token".to_string())
|
||||
})?;
|
||||
const IS_MOD : bool = false;
|
||||
|
||||
let media_file_lookup_result = get_media_file_with_connection(
|
||||
media_file_token,
|
||||
IS_MOD,
|
||||
&mut mysql_connection,
|
||||
).await;
|
||||
|
||||
let media_file = match media_file_lookup_result {
|
||||
Ok(Some(media_file)) => media_file,
|
||||
Ok(None) => {
|
||||
warn!("MediaFile not found: {:?}", media_file_token);
|
||||
return Err(CommonWebError::NotFound);
|
||||
},
|
||||
Err(err) => {
|
||||
warn!("Error looking up media_file: {:?}", err);
|
||||
return Err(CommonWebError::ServerError);
|
||||
}
|
||||
let media_domain = get_media_domain(&http_request);
|
||||
|
||||
let start_frame_url = media_files.iter()
|
||||
.find(|file| &file.token == start_frame_media_file_token)
|
||||
.map(|file| file.to_media_links(media_domain, server_state.server_environment))
|
||||
.map(|file| file.cdn_url)
|
||||
.ok_or_else(|| {
|
||||
warn!("Start frame media file not found after fetch");
|
||||
CommonWebError::NotFound
|
||||
})?;
|
||||
|
||||
let maybe_end_frame_url = match maybe_end_frame_image_media_token {
|
||||
None => None,
|
||||
Some(end_frame_token) => Some(media_files.iter()
|
||||
.find(|file| &file.token == end_frame_token)
|
||||
.map(|file| file.to_media_links(media_domain, server_state.server_environment))
|
||||
.map(|file| file.cdn_url)
|
||||
.ok_or_else(|| {
|
||||
warn!("End frame media file not found after fetch");
|
||||
CommonWebError::NotFound
|
||||
})?),
|
||||
};
|
||||
|
||||
if !media_file.media_type.is_jpg_or_png_or_legacy_image() {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("Media file must be a JPG or PNG image".to_string()));
|
||||
}
|
||||
|
||||
let media_domain = get_media_domain(&http_request);
|
||||
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash(
|
||||
&media_file.public_bucket_directory_hash,
|
||||
media_file.maybe_public_bucket_prefix.as_deref(),
|
||||
media_file.maybe_public_bucket_extension.as_deref());
|
||||
|
||||
let media_links = MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&bucket_path);
|
||||
|
||||
info!("Fal webhook URL: {}", server_state.fal.webhook_url);
|
||||
|
||||
let prompt = request.prompt
|
||||
@@ -148,7 +159,8 @@ pub async fn generate_kling_2_1_pro_video_handler(
|
||||
};
|
||||
|
||||
let args = Kling21ProArgs {
|
||||
image_url: media_links.cdn_url,
|
||||
image_url: start_frame_url,
|
||||
end_frame_image_url: maybe_end_frame_url,
|
||||
webhook_url: &server_state.fal.webhook_url,
|
||||
duration,
|
||||
prompt,
|
||||
|
||||
+48
-36
@@ -5,6 +5,8 @@ use crate::http_server::common_responses::media::media_links_builder::MediaLinks
|
||||
use crate::http_server::endpoints::media_files::helpers::get_media_domain::get_media_domain;
|
||||
use crate::http_server::validations::validate_idempotency_token_format::validate_idempotency_token_format;
|
||||
use crate::state::server_state::ServerState;
|
||||
use crate::util::lookup::fetch_all_required_media_files::fetch_all_required_media_files;
|
||||
use crate::util::traits::into_media_links_trait::IntoMediaLinks;
|
||||
use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest};
|
||||
use artcraft_api_defs::generate::video::generate_seedance_1_0_lite_image_to_video::GenerateSeedance10LiteDuration;
|
||||
@@ -74,14 +76,35 @@ pub async fn generate_seedance_1_0_lite_image_to_video_handler(
|
||||
// }
|
||||
//};
|
||||
|
||||
let media_file_token = match &request.media_file_token {
|
||||
let start_frame_media_file_token = match &request.media_file_token {
|
||||
Some(token) => token,
|
||||
None => {
|
||||
warn!("No media file token provided");
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("No media file token provided".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mut tokens = vec![
|
||||
start_frame_media_file_token.clone(),
|
||||
];
|
||||
|
||||
let maybe_end_frame_image_media_token = request.end_frame_image_media_token.as_ref();
|
||||
|
||||
if let Some(end_frame_token) = maybe_end_frame_image_media_token {
|
||||
tokens.push(end_frame_token.clone());
|
||||
}
|
||||
|
||||
let media_files = fetch_all_required_media_files(
|
||||
&mut mysql_connection,
|
||||
&tokens,
|
||||
).await?;
|
||||
|
||||
for media_file in media_files.iter() {
|
||||
if !media_file.media_type.is_jpg_or_png_or_legacy_image() {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("Media file must be a JPG or PNG image".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(reason) = validate_idempotency_token_format(&request.uuid_idempotency_token) {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage(reason));
|
||||
}
|
||||
@@ -92,42 +115,30 @@ pub async fn generate_seedance_1_0_lite_image_to_video_handler(
|
||||
error!("Error inserting idempotency token: {:?}", err);
|
||||
CommonWebError::BadInputWithSimpleMessage("invalid idempotency token".to_string())
|
||||
})?;
|
||||
const IS_MOD : bool = false;
|
||||
|
||||
let media_file_lookup_result = get_media_file_with_connection(
|
||||
media_file_token,
|
||||
IS_MOD,
|
||||
&mut mysql_connection,
|
||||
).await;
|
||||
|
||||
let media_file = match media_file_lookup_result {
|
||||
Ok(Some(media_file)) => media_file,
|
||||
Ok(None) => {
|
||||
warn!("MediaFile not found: {:?}", media_file_token);
|
||||
return Err(CommonWebError::NotFound);
|
||||
},
|
||||
Err(err) => {
|
||||
warn!("Error looking up media_file: {:?}", err);
|
||||
return Err(CommonWebError::ServerError);
|
||||
}
|
||||
let media_domain = get_media_domain(&http_request);
|
||||
|
||||
let start_frame_url = media_files.iter()
|
||||
.find(|file| &file.token == start_frame_media_file_token)
|
||||
.map(|file| file.to_media_links(media_domain, server_state.server_environment))
|
||||
.map(|file| file.cdn_url)
|
||||
.ok_or_else(|| {
|
||||
warn!("Start frame media file not found after fetch");
|
||||
CommonWebError::NotFound
|
||||
})?;
|
||||
|
||||
let maybe_end_frame_url = match maybe_end_frame_image_media_token {
|
||||
None => None,
|
||||
Some(end_frame_token) => Some(media_files.iter()
|
||||
.find(|file| &file.token == end_frame_token)
|
||||
.map(|file| file.to_media_links(media_domain, server_state.server_environment))
|
||||
.map(|file| file.cdn_url)
|
||||
.ok_or_else(|| {
|
||||
warn!("End frame media file not found after fetch");
|
||||
CommonWebError::NotFound
|
||||
})?),
|
||||
};
|
||||
|
||||
if !media_file.media_type.is_jpg_or_png_or_legacy_image() {
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage("Media file must be a JPG or PNG image".to_string()));
|
||||
}
|
||||
|
||||
let media_domain = get_media_domain(&http_request);
|
||||
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash(
|
||||
&media_file.public_bucket_directory_hash,
|
||||
media_file.maybe_public_bucket_prefix.as_deref(),
|
||||
media_file.maybe_public_bucket_extension.as_deref());
|
||||
|
||||
let media_links = MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain,
|
||||
server_state.server_environment,
|
||||
&bucket_path);
|
||||
|
||||
info!("Fal webhook URL: {}", server_state.fal.webhook_url);
|
||||
|
||||
let prompt = request.prompt
|
||||
@@ -148,7 +159,8 @@ pub async fn generate_seedance_1_0_lite_image_to_video_handler(
|
||||
};
|
||||
|
||||
let args = Seedance1LiteArgs {
|
||||
image_url: media_links.cdn_url,
|
||||
image_url: start_frame_url,
|
||||
end_frame_image_url: maybe_end_frame_url,
|
||||
webhook_url: &server_state.fal.webhook_url,
|
||||
api_key: &server_state.fal.api_key,
|
||||
duration,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
use crate::http_server::common_responses::common_web_error::CommonWebError;
|
||||
use log::{error, warn};
|
||||
use mysql_queries::queries::media_files::get::batch_get_media_files_by_tokens::{batch_get_media_files_by_tokens_with_connection, MediaFilesByTokensRecord};
|
||||
use sqlx::pool::PoolConnection;
|
||||
use sqlx::MySql;
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
|
||||
const CAN_SEE_DELETED: bool = false;
|
||||
|
||||
/// Look up all the media tokens. If any are missing, return an error.
|
||||
pub async fn fetch_all_required_media_files(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
media_file_tokens: &[MediaFileToken],
|
||||
) -> Result<Vec<MediaFilesByTokensRecord>, CommonWebError> {
|
||||
let result = batch_get_media_files_by_tokens_with_connection(
|
||||
mysql_connection,
|
||||
&media_file_tokens,
|
||||
CAN_SEE_DELETED,
|
||||
).await;
|
||||
|
||||
let media_files = match result {
|
||||
Ok(files) => files,
|
||||
Err(err) => {
|
||||
error!("Error getting media files by tokens: {:?}", err);
|
||||
return Err(CommonWebError::ServerError);
|
||||
}
|
||||
};
|
||||
|
||||
if media_files.len() != media_file_tokens.len() {
|
||||
warn!("Wrong number of media files returned for tokens: {} found for {} tokens", media_files.len(), media_file_tokens.len());
|
||||
return Err(CommonWebError::BadInputWithSimpleMessage(
|
||||
format!("Not all media files could be found. Media files found: {}, tokens provided: {}",
|
||||
media_files.len(), media_file_tokens.len())));
|
||||
}
|
||||
|
||||
Ok(media_files)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod fetch_all_required_media_files;
|
||||
@@ -11,7 +11,9 @@ pub mod enroll_in_studio;
|
||||
pub mod generate_random_username;
|
||||
pub mod http_download_url_to_bytes;
|
||||
pub mod http_download_url_to_tempfile;
|
||||
pub mod lookup;
|
||||
pub mod placeholder_images;
|
||||
pub mod read_toml_file_to_struct;
|
||||
pub mod title_to_url_slug;
|
||||
pub mod traits;
|
||||
pub mod troll_user_bans;
|
||||
@@ -0,0 +1,28 @@
|
||||
use crate::http_server::common_responses::media::media_domain::MediaDomain;
|
||||
use crate::http_server::common_responses::media::media_links_builder::MediaLinksBuilder;
|
||||
use artcraft_api_defs::common::responses::media_links::MediaLinks;
|
||||
use bucket_paths::legacy::typified_paths::public::media_files::bucket_file_path::MediaFileBucketPath;
|
||||
use mysql_queries::queries::media_files::get::batch_get_media_files_by_tokens::MediaFilesByTokensRecord;
|
||||
use server_environment::ServerEnvironment;
|
||||
|
||||
pub trait IntoMediaLinks {
|
||||
fn to_media_links(
|
||||
&self,
|
||||
media_domain: MediaDomain,
|
||||
server_environment: ServerEnvironment,
|
||||
) -> MediaLinks;
|
||||
}
|
||||
|
||||
impl IntoMediaLinks for MediaFilesByTokensRecord {
|
||||
fn to_media_links(&self, media_domain: MediaDomain, server_environment: ServerEnvironment) -> MediaLinks {
|
||||
let bucket_path = MediaFileBucketPath::from_object_hash(
|
||||
&self.public_bucket_directory_hash,
|
||||
self.maybe_public_bucket_prefix.as_deref(),
|
||||
self.maybe_public_bucket_extension.as_deref());
|
||||
MediaLinksBuilder::from_media_path_and_env(
|
||||
media_domain,
|
||||
server_environment,
|
||||
&bucket_path
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod into_media_links_trait;
|
||||
+15
-1
@@ -11,4 +11,18 @@
|
||||
feature = "endpoints_fal-ai_bytedance"
|
||||
)))
|
||||
)]
|
||||
pub mod seedance;
|
||||
pub mod seedance;
|
||||
#[cfg(any(
|
||||
feature = "endpoints",
|
||||
feature = "endpoints_fal-ai",
|
||||
feature = "endpoints_fal-ai_bytedance"
|
||||
))]
|
||||
#[cfg_attr(
|
||||
docsrs,
|
||||
doc(cfg(any(
|
||||
feature = "endpoints",
|
||||
feature = "endpoints_fal-ai",
|
||||
feature = "endpoints_fal-ai_bytedance"
|
||||
)))
|
||||
)]
|
||||
pub mod seededit;
|
||||
+23
-15
@@ -5,6 +5,29 @@ use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ImageToVideoRequest {
|
||||
pub image_url: String,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub end_image_url: Option<String>,
|
||||
|
||||
/// The resolution of the generated video frame
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub resolution: Option<String>,
|
||||
|
||||
/// The duration of the generated video in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub camera_fixed: Option<bool>,
|
||||
|
||||
pub prompt: String,
|
||||
|
||||
pub seed: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct File {
|
||||
/// The mime type of the file.
|
||||
@@ -39,21 +62,6 @@ pub struct I2VOutput {
|
||||
pub video: File,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ImageToVideoRequest {
|
||||
/// The resolution of the generated video frame
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub resolution: Option<String>,
|
||||
/// The duration of the generated video in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<String>,
|
||||
pub image_url: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub camera_fixed: Option<bool>,
|
||||
pub prompt: String,
|
||||
pub seed: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ValidationError {
|
||||
pub loc: Vec<serde_json::Value>,
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#[allow(unused_imports)]
|
||||
use crate::prelude::*;
|
||||
#[allow(unused_imports)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct SeedEditV3Input {
|
||||
/// REQUIRED
|
||||
/// The prompt to generate the image with
|
||||
pub prompt: String,
|
||||
|
||||
/// REQUIRED
|
||||
/// The URL of the image to edit.
|
||||
pub image_url: String,
|
||||
|
||||
/// Optional.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub guidance_scale: Option<f64>,
|
||||
|
||||
/// Optional.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enable_safety_checker: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SeedEditV3Output {
|
||||
pub image: Vec<Image>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct Image {
|
||||
/// The URL where the file can be downloaded from.
|
||||
pub url: String,
|
||||
|
||||
/// The mime type of the file.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
|
||||
/// The name of the file. It will be auto-generated if not provided.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_name: Option<String>,
|
||||
|
||||
/// The size of the file in bytes.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_size: Option<i64>,
|
||||
|
||||
/// File data
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_data: Option<String>,
|
||||
|
||||
/// The width of the image in pixels.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub width: Option<u64>,
|
||||
|
||||
/// The height of the image in pixels.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub height: Option<u64>,
|
||||
}
|
||||
|
||||
pub fn seededit_v3_edit(
|
||||
params: SeedEditV3Input,
|
||||
) -> FalRequest<SeedEditV3Input, SeedEditV3Output> {
|
||||
FalRequest::new("fal-ai/bytedance/seededit/v3/edit-image", params)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod edit_image_v3;
|
||||
@@ -2168,6 +2168,20 @@ pub mod triposr;
|
||||
)))
|
||||
)]
|
||||
pub mod veo2;
|
||||
#[cfg(any(
|
||||
feature = "endpoints",
|
||||
feature = "endpoints_fal-ai",
|
||||
feature = "endpoints_fal-ai_veo3"
|
||||
))]
|
||||
#[cfg_attr(
|
||||
docsrs,
|
||||
doc(cfg(any(
|
||||
feature = "endpoints",
|
||||
feature = "endpoints_fal-ai",
|
||||
feature = "endpoints_fal-ai_veo3"
|
||||
)))
|
||||
)]
|
||||
pub mod veo3;
|
||||
#[cfg(any(
|
||||
feature = "endpoints",
|
||||
feature = "endpoints_fal-ai",
|
||||
@@ -2378,3 +2392,5 @@ pub mod yue;
|
||||
)))
|
||||
)]
|
||||
pub mod zonos;
|
||||
|
||||
pub mod qwen_image_edit;
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
#[allow(unused_imports)]
|
||||
use crate::prelude::*;
|
||||
#[allow(unused_imports)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
// "height": 768,
|
||||
// "content_type": "image/jpeg",
|
||||
// "url": "https://v3.fal.media/files/elephant/P-YCIAg6wtFn1hsF34fzL_qwen-edit.png",
|
||||
// "width": 1024
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct File {
|
||||
/// The URL where the file can be downloaded from.
|
||||
pub url: String,
|
||||
/// The mime type of the file.
|
||||
/// "image/png"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
/// File data
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_data: Option<String>,
|
||||
/// The name of the file. It will be auto-generated if not provided.
|
||||
/// "z9RV14K95DvU.png"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_name: Option<String>,
|
||||
/// The size of the file in bytes.
|
||||
/// 4404019
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_size: Option<i64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub height: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub width: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct QwenImageEditInput {
|
||||
/// REQUIRED
|
||||
/// The prompt to generate the image with
|
||||
pub prompt: String,
|
||||
|
||||
/// REQUIRED
|
||||
/// The URL of the image to edit.
|
||||
pub image_url: String,
|
||||
|
||||
/// Optional.
|
||||
/// Possible enum values: square_hd, square, portrait_4_3, portrait_16_9,
|
||||
/// landscape_4_3, landscape_16_9
|
||||
/// Note: This also supports a custom JSON width/height (not yet supported)
|
||||
pub image_size: Option<String>,
|
||||
|
||||
/// Optional.
|
||||
/// The number of inference steps to perform. Default value: 30
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub num_inference_steps: Option<u8>,
|
||||
|
||||
/// Optional.
|
||||
/// The same seed and the same prompt given to the same version of the model will
|
||||
/// output the same image every time.The number of inference steps to perform. Default value: 30
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub seed: Option<u64>,
|
||||
|
||||
/// Optional.
|
||||
/// Classifier free guidance
|
||||
/// The CFG (Classifier Free Guidance) scale is a measure of how close you want the
|
||||
/// model to stick to your prompt when looking for a related image to show you. Default value: 4
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub guidance_scale: Option<f64>,
|
||||
|
||||
/// Optional.
|
||||
/// The number of images to generate. Default value: 1
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub num_images: Option<u8>,
|
||||
|
||||
/// Optional.
|
||||
/// If set to true, the safety checker will be enabled. Default value: true
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enable_safety_checker: Option<bool>,
|
||||
|
||||
/// Optional.
|
||||
/// The format of the generated image. Default value: "png"
|
||||
// Possible enum values: jpeg, png
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub output_format: Option<String>,
|
||||
|
||||
/// Optional.
|
||||
/// The negative prompt for the generation Default value: " "
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub negative_prompt: Option<String>,
|
||||
|
||||
/// Optional.
|
||||
/// Acceleration level for image generation. Options: 'none', 'regular'.
|
||||
/// Higher acceleration increases speed. 'regular' balances speed and quality.
|
||||
/// Default value: "none"
|
||||
/// Possible enum values: none, regular, high
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub acceleration: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct QwenImageEditOutput {
|
||||
pub images: Vec<File>,
|
||||
}
|
||||
|
||||
pub fn qwen_image_edit(
|
||||
params: QwenImageEditInput,
|
||||
) -> FalRequest<QwenImageEditInput, QwenImageEditOutput> {
|
||||
FalRequest::new("fal-ai/qwen-image-edit", params)
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#[allow(unused_imports)]
|
||||
use crate::prelude::*;
|
||||
#[allow(unused_imports)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct File {
|
||||
/// The mime type of the file.
|
||||
/// "image/png"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
/// File data
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_data: Option<String>,
|
||||
/// The name of the file. It will be auto-generated if not provided.
|
||||
/// "z9RV14K95DvU.png"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_name: Option<String>,
|
||||
/// The size of the file in bytes.
|
||||
/// 4404019
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_size: Option<i64>,
|
||||
/// The URL where the file can be downloaded from.
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ImageToVideoInput {
|
||||
/// The text prompt describing how the image should be animated
|
||||
/// "A lego chef cooking eggs"
|
||||
pub prompt: String,
|
||||
|
||||
/// URL of the input image to animate. Should be 720p or higher resolution.
|
||||
/// "https://fal.media/files/elephant/6fq8JDSjb1osE_c3J_F2H.png"
|
||||
pub image_url: String,
|
||||
|
||||
/// The duration of the generated video in seconds
|
||||
/// eg "8s".
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<String>,
|
||||
|
||||
/// Generate audio
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub generate_audio: Option<bool>,
|
||||
|
||||
/// Resolution, eg. "720p"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub resolution: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ImageToVideoOutput {
|
||||
/// The generated video
|
||||
/// {"url":"https://v3.fal.media/files/zebra/uNu-1qkbNt8be8iHA1hiB_output.mp4"}
|
||||
pub video: File,
|
||||
}
|
||||
|
||||
pub fn image_to_video(
|
||||
params: ImageToVideoInput,
|
||||
) -> FalRequest<ImageToVideoInput, ImageToVideoOutput> {
|
||||
FalRequest::new("fal-ai/veo3/image-to-video", params)
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#[allow(unused_imports)]
|
||||
use crate::prelude::*;
|
||||
#[allow(unused_imports)]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct File {
|
||||
/// The mime type of the file.
|
||||
/// "image/png"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
/// File data
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_data: Option<String>,
|
||||
/// The name of the file. It will be auto-generated if not provided.
|
||||
/// "z9RV14K95DvU.png"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_name: Option<String>,
|
||||
/// The size of the file in bytes.
|
||||
/// 4404019
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub file_size: Option<i64>,
|
||||
/// The URL where the file can be downloaded from.
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ImageToVideoFastInput {
|
||||
/// The text prompt describing how the image should be animated
|
||||
/// "A lego chef cooking eggs"
|
||||
pub prompt: String,
|
||||
|
||||
/// URL of the input image to animate. Should be 720p or higher resolution.
|
||||
/// "https://fal.media/files/elephant/6fq8JDSjb1osE_c3J_F2H.png"
|
||||
pub image_url: String,
|
||||
|
||||
/// The duration of the generated video in seconds
|
||||
/// eg "8s".
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<String>,
|
||||
|
||||
/// Generate audio
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub generate_audio: Option<bool>,
|
||||
|
||||
/// Resolution, eg. "720p"
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub resolution: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ImageToVideoFastOutput {
|
||||
/// The generated video
|
||||
/// {"url":"https://v3.fal.media/files/zebra/uNu-1qkbNt8be8iHA1hiB_output.mp4"}
|
||||
pub video: File,
|
||||
}
|
||||
|
||||
pub fn image_to_video_fast(
|
||||
params: ImageToVideoFastInput,
|
||||
) -> FalRequest<ImageToVideoFastInput, ImageToVideoFastOutput> {
|
||||
FalRequest::new("fal-ai/veo3/fast/image-to-video", params)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod image_to_video;
|
||||
pub mod image_to_video_fast;
|
||||
@@ -1,9 +1,12 @@
|
||||
import { Button } from "@storyteller/ui-button";
|
||||
import { useImageEditCompleteEvent } from "@storyteller/tauri-events";
|
||||
import { faTrash } from "@fortawesome/pro-solid-svg-icons";
|
||||
import { faClockRotateLeft, faTrash, faTrashXmark, faXmark } from "@fortawesome/pro-solid-svg-icons";
|
||||
import { useRef, useState } from "react";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import { BaseSelectorImage } from "./BaseImageSelector";
|
||||
import { Tooltip } from "@storyteller/ui-tooltip";
|
||||
import { isActionReminderOpen, showActionReminder } from "@storyteller/ui-action-reminder-modal";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
export interface ImageBundle {
|
||||
images: BaseSelectorImage[];
|
||||
@@ -57,19 +60,11 @@ export const HistoryStack = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="max-h-1/2 glass h-auto w-16 overflow-y-auto rounded-lg p-1">
|
||||
<div className="flex flex-col-reverse items-center justify-center gap-2">
|
||||
<Button
|
||||
className="h-7 w-full rounded-md opacity-80"
|
||||
iconClassName="h-3 w-3"
|
||||
icon={faTrash}
|
||||
type="reset"
|
||||
onClick={handleClear}
|
||||
variant="destructive"
|
||||
/>
|
||||
{imageBundles.map((bundle) => (
|
||||
<div className="max-h-1/2 h-auto w-20 overflow-y-auto rounded-lg">
|
||||
<div className="flex glass rounded-lg flex-col-reverse items-center justify-center gap-2 p-1">
|
||||
{imageBundles.map((bundle, index) => (
|
||||
<>
|
||||
<hr className="h-0.5 w-3/4 rounded-md border-none bg-white/10" />
|
||||
{index < imageBundles.length - 1 && <hr className="h-0.5 w-3/4 rounded-md border-none bg-white/10" />}
|
||||
{bundle.images.map((image, imgIndex) => (
|
||||
<Button
|
||||
key={imgIndex}
|
||||
@@ -94,6 +89,33 @@ export const HistoryStack = ({
|
||||
))}
|
||||
</>
|
||||
))}
|
||||
<FontAwesomeIcon icon={faClockRotateLeft} className="p-1 text-gray-400" />
|
||||
</div>
|
||||
<div className="glass mt-4 rounded-full border-red/50 border-2 size-12 flex justify-center items-center mx-auto">
|
||||
<button
|
||||
className="flex h-full w-full aspect-square rounded-full items-center justify-center text-white transition-colors hover:bg-red/50"
|
||||
onClick={() =>
|
||||
showActionReminder({
|
||||
reminderType: "default",
|
||||
title: "Reset All",
|
||||
primaryActionIcon: faTrashXmark,
|
||||
primaryActionBtnClassName: "bg-red hover:bg-red/80",
|
||||
message: (
|
||||
<p className="text-sm text-white/70">
|
||||
Are you sure you want to reset all? This will clear all your
|
||||
work and cannot be undone.
|
||||
</p>
|
||||
),
|
||||
primaryActionText: "Reset all",
|
||||
onPrimaryAction: () => {
|
||||
handleClear();
|
||||
isActionReminderOpen.value = false;
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
<FontAwesomeIcon icon={faXmark} className="h-5 w-5 text-xl" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -21,10 +21,8 @@ import {
|
||||
useModelSelectorStore,
|
||||
} from "@storyteller/ui-model-selector";
|
||||
import { lookupModelByTauriId, ModelInfo } from "@storyteller/model-list";
|
||||
import { useImageEditCompleteEvent } from "@storyteller/tauri-events";
|
||||
import { HistoryStack, ImageBundle } from "./HistoryStack";
|
||||
import { ModelTag } from "libs/model-list/src/lib/ModelTag";
|
||||
import LeftResetStack from "./LeftResetStack";
|
||||
|
||||
const PAGE_ID: ModelPage = ModelPage.ImageEditor;
|
||||
|
||||
@@ -60,20 +58,6 @@ const PageEdit = () => {
|
||||
// Use the Zustand store
|
||||
const store = useEditStore();
|
||||
|
||||
useImageEditCompleteEvent(async (event) => {
|
||||
console.log("Image edit complete:", event);
|
||||
|
||||
// TODO: Logic to show edit history
|
||||
for (const editedImage of event.edited_images) {
|
||||
console.log("Edited image:", editedImage.media_token);
|
||||
console.log("Edited image url:", editedImage.cdn_url);
|
||||
console.log(
|
||||
"Edited image thumbnail template:",
|
||||
editedImage.maybe_thumbnail_template,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Pass store actions directly as callbacks
|
||||
useDeleteHotkeys({ onDelete: store.deleteSelectedItems });
|
||||
useUndoRedoHotkeys({ undo: store.undo, redo: store.redo });
|
||||
@@ -312,9 +296,8 @@ const PageEdit = () => {
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={`preserve-aspect-ratio fixed left-1/2 top-0 z-10 -translate-x-1/2 transform ${
|
||||
isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
className={`preserve-aspect-ratio fixed left-1/2 top-0 z-10 -translate-x-1/2 transform ${isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
style={{ display: store.activeTool === "edit" ? "block" : "none" }}
|
||||
>
|
||||
<DrawToolControlBar
|
||||
@@ -325,16 +308,8 @@ const PageEdit = () => {
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className={`preserve-aspect-ratio fixed left-4 top-1/2 z-10 -translate-y-1/2 transform ${
|
||||
isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
>
|
||||
<LeftResetStack onReset={() => store.RESET()} />
|
||||
</div>
|
||||
<div
|
||||
className={`preserve-aspect-ratio fixed right-4 top-1/2 z-10 -translate-y-1/2 transform ${
|
||||
isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
className={`preserve-aspect-ratio fixed right-4 top-1/2 z-10 -translate-y-1/2 transform ${isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
>
|
||||
<HistoryStack
|
||||
onClear={() => {
|
||||
@@ -348,9 +323,8 @@ const PageEdit = () => {
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className={`preserve-aspect-ratio fixed bottom-0 left-1/2 z-10 -translate-x-1/2 transform ${
|
||||
isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
className={`preserve-aspect-ratio fixed bottom-0 left-1/2 z-10 -translate-x-1/2 transform ${isSelecting ? "pointer-events-none" : "pointer-events-auto"
|
||||
}`}
|
||||
>
|
||||
<PromptEditor
|
||||
modelInfo={selectedModelInfo}
|
||||
|
||||
@@ -199,7 +199,12 @@ class Scene {
|
||||
obj.userData["media_id"] = name;
|
||||
} else {
|
||||
const loader = new THREE.TextureLoader();
|
||||
texture = loader.load(image_token);
|
||||
// NB(bt,2025-08-26): Images loaded throughout the rest of ArtCraft with the <img> tag set
|
||||
// the "sec-fetch-mode: no-cors" header. On Safari (Mac), this is cached and makes the image
|
||||
// permanently impossible to use in Three.js. We bypass this by appending a query parameter
|
||||
// to the URL.
|
||||
const modifiedUrl = image_token + "?threejs=true";
|
||||
texture = loader.load(modifiedUrl);
|
||||
texture.colorSpace = THREE.SRGBColorSpace;
|
||||
const image_material = new THREE.MeshBasicMaterial({
|
||||
color: 0xffffff,
|
||||
|
||||
@@ -14,14 +14,23 @@ export enum EnqueueImageToVideoErrorType {
|
||||
}
|
||||
|
||||
export interface EnqueueImageToVideoRequest {
|
||||
image_media_token?: string;
|
||||
// Required. The model to use.
|
||||
model?: ModelInfo;
|
||||
|
||||
// Required. Starting frame.
|
||||
image_media_token?: string;
|
||||
|
||||
// Optional. Ending frame.
|
||||
end_frame_image_media_token?: string;
|
||||
|
||||
// Optional. Text prompt to direct the video.
|
||||
prompt?: string;
|
||||
}
|
||||
|
||||
interface RawEnqueueImageToVideoRequest {
|
||||
image_media_token?: string;
|
||||
model?: string;
|
||||
image_media_token?: string;
|
||||
end_frame_image_media_token?: string;
|
||||
prompt?: string;
|
||||
}
|
||||
|
||||
@@ -31,9 +40,6 @@ export interface EnqueueImageToVideoError extends CommandResult {
|
||||
}
|
||||
|
||||
export interface EnqueueImageToVideoPayload {
|
||||
media_token: string;
|
||||
cdn_url: string;
|
||||
base64_bytes: string;
|
||||
}
|
||||
|
||||
export interface EnqueueImageToVideoSuccess extends CommandResult {
|
||||
@@ -46,14 +52,18 @@ export const EnqueueImageToVideo = async (request: EnqueueImageToVideoRequest) :
|
||||
const modelName = request.model?.tauri_id;
|
||||
|
||||
let mutableRequest : RawEnqueueImageToVideoRequest = {
|
||||
image_media_token: request.image_media_token,
|
||||
model: modelName,
|
||||
image_media_token: request.image_media_token,
|
||||
};
|
||||
|
||||
if (!!request.prompt) {
|
||||
mutableRequest.prompt = request.prompt;
|
||||
}
|
||||
|
||||
if (!!request.end_frame_image_media_token) {
|
||||
mutableRequest.end_frame_image_media_token = request.end_frame_image_media_token;
|
||||
}
|
||||
|
||||
const result = await invoke("enqueue_image_to_video_command", {
|
||||
request: mutableRequest,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user