send test event to javascript from tauri

This commit is contained in:
Brandon Thomas committed 2025-03-04 15:13:55 -05:00
1 parent c29d6377a4
commit e088f8e4fd
2 files changed
+9 -2

No files matched your search

@@ -9,7 +9,7 @@ use image::{DynamicImage, ImageFormat, ImageReader};
use log::{error, info};
use std::io::Cursor;
use std::path::PathBuf;
use tauri::State;
use tauri::{AppHandle, State};
const PROMPT_FILENAME : &str = "prompt.txt";
const PROMPT: &str = "A beautiful landscape with mountains and a lake";
@@ -26,6 +26,7 @@ pub fn infer_image(
model_config: State<AppConfig>,
model_cache: State<ModelCache>,
prompt_cache: State<PromptCache>,
app: AppHandle,
) -> Result<String, String> {
let prompt = get_prompt_or_fallback(prompt);
@@ -36,7 +37,7 @@ pub fn infer_image(
let image = hydrate_base64_image(image)
.map_err(|err| format!("Couldn't hydrate image from base64: {}", err))?;
let result = do_infer_image(&prompt, image, strength, &model_config, &model_cache, prompt_cache);
let result = do_infer_image(&prompt, image, strength, &model_config, &model_cache, prompt_cache, app);
if let Err(err) = result.as_deref() {
error!("There was an error: {:?}", err);
@@ -52,6 +53,7 @@ fn do_infer_image(
config: &AppConfig,
model_cache: &ModelCache,
prompt_cache: State<PromptCache>,
app: AppHandle,
) -> Result<String, String> {
println!("infer_image called; generating image with SDXL Turbo...");
@@ -65,6 +67,7 @@ fn do_infer_image(
prompt_cache: &prompt_cache,
i2i_strength: strength,
cfg_scale: config.cfg_scale,
app: &app,
};
match stable_diffusion_pipeline(args) {
@@ -14,6 +14,7 @@ use candle_transformers::models::stable_diffusion::vae::DiagonalGaussianDistribu
use image::DynamicImage;
use log::info;
use rand::Rng;
use tauri::{AppHandle, Emitter};
pub struct Args<'a> {
pub image: &'a DynamicImage,
@@ -24,6 +25,7 @@ pub struct Args<'a> {
pub configs: &'a AppConfig,
pub model_cache: &'a ModelCache,
pub prompt_cache: &'a PromptCache,
pub app: &'a AppHandle,
}
pub fn stable_diffusion_pipeline(args: Args<'_>) -> Result<RgbImage> {
@@ -67,6 +69,8 @@ pub fn stable_diffusion_pipeline(args: Args<'_>) -> Result<RgbImage> {
let mut text_embeddings = if let Some(tensor) = maybe_cached {
tensor
} else {
args.app.emit("event", "loading model");
info!("Prompt is NOT cached! Calculating embedding...");
let tensor = infer_clip_text_embeddings(
&args.prompt,