mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-12 04:42:16 +00:00
wip - need to back up the queue state for later hydration
This commit is contained in:
1 parent
6cfa3dc32f
commit
a610d90389
7 files changed
+41
-7
No files matched your search
Generated
+1
@@ -4254,6 +4254,7 @@ dependencies = [
|
||||
"file_to_base64_url",
|
||||
"filesys",
|
||||
"futures 0.3.31",
|
||||
"serde",
|
||||
"testing",
|
||||
"tokio",
|
||||
"url",
|
||||
|
||||
@@ -25,6 +25,7 @@ anyhow = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
fal = { version = "0.3.6", features = ["endpoints"] }
|
||||
futures = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
url = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
//! A wrapper for the "fal" crate that bakes in a few extra recipes and utilities.
|
||||
|
||||
// Re-export
|
||||
extern crate fal;
|
||||
|
||||
|
||||
pub mod creds;
|
||||
pub mod fal_error_plus;
|
||||
pub mod requests;
|
||||
pub mod utils;
|
||||
@@ -7,6 +7,8 @@ use fal_client::file_to_base64_url::file_to_base64_url;
|
||||
use futures::StreamExt;
|
||||
use std::path::Path;
|
||||
use chrono::Utc;
|
||||
use fal::endpoints::fal_ai::kling_video::v1::pro::effects::I2VOutput;
|
||||
use fal::queue::Queue;
|
||||
use url::Url;
|
||||
|
||||
pub struct Kling16Args<'a, P: AsRef<Path>> {
|
||||
@@ -28,7 +30,7 @@ pub enum Kling16Duration {
|
||||
pub async fn kling_16_image_to_video<P: AsRef<Path>>(args: Kling16Args<'_, P>) -> Result<Kling16Response, FalErrorPlus> {
|
||||
println!("Image to base64... {:?}", Utc::now().format("%Y-%m-%dT%H:%M:%S").to_string());
|
||||
std::io::stdout().flush().unwrap();
|
||||
|
||||
|
||||
let image_url = file_to_base64_url(args.image_path)?;
|
||||
|
||||
/*
|
||||
@@ -36,7 +38,7 @@ pub async fn kling_16_image_to_video<P: AsRef<Path>>(args: Kling16Args<'_, P>) -
|
||||
FalError(FalError(Other("{\"detail\": \"Invalid Key Authorization header format. Expected '<key_id>:<key_secret>'.\"}")))
|
||||
FalError(FalError(Other("{\"detail\": \"No user found for Key ID and Secret\"}")))
|
||||
*/
|
||||
|
||||
|
||||
let duration = match args.duration{
|
||||
Kling16Duration::Default => None,
|
||||
Kling16Duration::FiveSeconds => Some("5".to_string()),
|
||||
@@ -55,15 +57,24 @@ pub async fn kling_16_image_to_video<P: AsRef<Path>>(args: Kling16Args<'_, P>) -
|
||||
|
||||
println!("Sending request... {:?}", Utc::now().format("%Y-%m-%dT%H:%M:%S").to_string());
|
||||
std::io::stdout().flush().unwrap();
|
||||
|
||||
|
||||
let result = image_to_video(request)
|
||||
.with_api_key(&args.api_key.0)
|
||||
.queue()
|
||||
.await?;
|
||||
|
||||
let payload = result.payload;
|
||||
|
||||
let test : Queue<I2VOutput> = Queue::new(;
|
||||
result.client().clone(),
|
||||
result.endpoint(),
|
||||
args.api_key.0.clone(),
|
||||
result.payload().clone(),
|
||||
);
|
||||
|
||||
println!("Result... {:?} - {:?}", result, Utc::now().format("%Y-%m-%dT%H:%M:%S").to_string());
|
||||
std::io::stdout().flush().unwrap();
|
||||
|
||||
|
||||
let mut stream = result.stream(true).await?;
|
||||
|
||||
let mut i = 0;
|
||||
@@ -74,13 +85,13 @@ pub async fn kling_16_image_to_video<P: AsRef<Path>>(args: Kling16Args<'_, P>) -
|
||||
if status.status == Status::Completed {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if i > 5 {
|
||||
return Err(FalErrorPlus::FalError(
|
||||
fal::prelude::FalError::Other("Timed out waiting for video to be created".to_string()),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
i+= 1;
|
||||
}
|
||||
|
||||
@@ -112,7 +123,7 @@ mod tests {
|
||||
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,
|
||||
api_key: &api_key,
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
use fal::queue::{Queue, QueueResponse};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
pub fn clone_queue_payload<R: DeserializeOwned>(payload: &Queue<R>) -> QueueResponse {
|
||||
// TODO...
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
use fal::queue::QueueResponse;
|
||||
|
||||
pub fn clone_queue_response(response: &QueueResponse) -> QueueResponse {
|
||||
QueueResponse {
|
||||
request_id: response.request_id.clone(),
|
||||
response_url: response.response_url.clone(),
|
||||
status_url: response.status_url.clone(),
|
||||
cancel_url: response.cancel_url.clone(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod clone_queue_payload;
|
||||
mod clone_queue_response;
|
||||
Reference in new issue
Block a user