mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 04:16:55 +00:00
pass prompt from frontend
This commit is contained in:
1 parent
ff9d2c6b34
commit
5ee910ad07
2 files changed
+28
-14
No files matched your search
@@ -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<String>,
|
||||
model_config: State<AppConfig>,
|
||||
model_cache: State<ModelCache>,
|
||||
prompt_cache: State<PromptCache>,
|
||||
@@ -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>) -> 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()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user