From 5ee910ad07327c0343b780b1d9fd58e0100f3deb Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 18 Feb 2025 01:57:37 -0500 Subject: [PATCH] pass prompt from frontend --- .../src-tauri/src/endpoints/image_endpoint.rs | 34 +++++++++++++------ crates/desktop/src-tauri/tauri.conf.json | 8 ++--- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/crates/desktop/src-tauri/src/endpoints/image_endpoint.rs b/crates/desktop/src-tauri/src/endpoints/image_endpoint.rs index 50a5bdff0b..f19902af87 100644 --- a/crates/desktop/src-tauri/src/endpoints/image_endpoint.rs +++ b/crates/desktop/src-tauri/src/endpoints/image_endpoint.rs @@ -18,6 +18,7 @@ const PROMPT: &str = "A beautiful landscape with mountains and a lake"; #[tauri::command] pub fn infer_image( image: &str, + prompt: Option, model_config: State, model_cache: State, prompt_cache: State, @@ -26,17 +27,9 @@ pub fn infer_image( let bytes = BASE64_STANDARD.decode(image) .map_err(|err| format!("Base64 decode error: {}", err))?; - let prompt_file = PathBuf::from("prompt.txt").canonicalize() - .unwrap_or_else(|_| PathBuf::from("prompt.txt")); + let prompt = get_prompt(prompt); - let prompt = std::fs::read_to_string(&prompt_file) - .map_err(|err| format!("Failed to read prompt file: {}", err)) - .unwrap_or_else(|_| { - error!("Failed to read prompt file: {:?}", prompt_file); - PROMPT.to_string() - }) - .trim() - .to_string(); + info!("Prompt: {}", prompt); let image = ImageReader::new(Cursor::new(bytes)) .with_guessed_format() @@ -90,3 +83,24 @@ fn do_infer_image( Err(e) => Err(format!("Failed to generate image: {}", e)), } } + +fn get_prompt(user_prompt: Option) -> String { + let user_prompt = user_prompt.map(|prompt| prompt.trim().to_string()) + .filter(|prompt| !prompt.is_empty()); + + if let Some(prompt) = user_prompt { + return prompt; + } + + let prompt_file = PathBuf::from("prompt.txt").canonicalize() + .unwrap_or_else(|_| PathBuf::from("prompt.txt")); + + std::fs::read_to_string(&prompt_file) + .map_err(|err| format!("Failed to read prompt file: {}", err)) + .unwrap_or_else(|_| { + error!("Failed to read prompt file: {:?}", prompt_file); + PROMPT.to_string() + }) + .trim() + .to_string() +} diff --git a/crates/desktop/src-tauri/tauri.conf.json b/crates/desktop/src-tauri/tauri.conf.json index 309c499a91..f7f20f7628 100644 --- a/crates/desktop/src-tauri/tauri.conf.json +++ b/crates/desktop/src-tauri/tauri.conf.json @@ -1,6 +1,6 @@ { "$schema": "https://schema.tauri.app/config/2.0.0-rc", - "productName": "Storyteller Desktop App", + "productName": "Realtime Desktop App", "version": "0.1.0", "identifier": "com.unique.value.thing.why", "build": { @@ -12,9 +12,9 @@ "app": { "windows": [ { - "title": "Storyteller Desktop App Title Goes Here", - "width": 800, - "height": 600, + "title": "Realtime Desktop App Title Goes Here", + "width": 1200, + "height": 800, "resizable": true, "fullscreen": false }