WIP: UI编辑器自动分图层切图标 #304

Draft
k88936 wants to merge 100 commits from feat/ui-editor-auto-seperation into master
Showing only changes of commit feb6bc0ad4 - Show all commits
@@ -89,27 +89,6 @@ pub fn apply_batch_patch(
Ok(())
}
fn mark_batch_problematic(
state: &mut SeparationState,
tree_index: usize,
batch: &[&SeparationNode],
error: String,
) {
app_log!(
"ui_separation.batch_problematic tree_index={} nodes={} error={}",
tree_index,
batch.len(),
error
);
for node in batch {
state.problematic_nodes.push(ProblematicNode {
node_id: node.id.clone(),
problem_description: error.clone(),
rework_count: node.rework_count,
});
}
}
fn increment_rework_count(node: &mut SeparationNode, id: &NodeId, count: u32) {
if node.id == *id {
node.rework_count = count;
@@ -299,17 +278,15 @@ async fn visual_binding(
let client = client.clone();
let llm_config = llm_config.clone();
async move {
let request = LlmRunRequest::new(vec![
LlmMessage::user_multimodal(vec![
LlmMessageContentPart::InputText { text: prompt },
LlmMessageContentPart::InputImage {
image_url: source_url,
},
LlmMessageContentPart::InputImage {
image_url: processed_url,
},
]),
])
let request = LlmRunRequest::new(vec![LlmMessage::user_multimodal(vec![
LlmMessageContentPart::InputText { text: prompt },
LlmMessageContentPart::InputImage {
image_url: source_url,
},
LlmMessageContentPart::InputImage {
image_url: processed_url,
},
])])
.with_function_tools(vec![tool.clone()])
.with_tool_choice(LlmToolChoice::Required);
request_ui_editor_llm(&client, &llm_config, request)
@@ -476,10 +453,8 @@ pub(crate) async fn separate_ui_impl(
tree_index,
batch_index
);
mark_batch_problematic(&mut separation, tree_index, &batch, error);
write_separation_state(&state_path, &separation)?;
batch_index += 1;
continue;
return Err(error);
}
};
let processed_url = match raw_image_edit(
@@ -498,10 +473,8 @@ pub(crate) async fn separate_ui_impl(
tree_index,
batch_index
);
mark_batch_problematic(&mut separation, tree_index, &batch, error);
write_separation_state(&state_path, &separation)?;
batch_index += 1;
continue;
return Err(error);
}
};
let processed_path = sidecar.join(format!("processed-{}.png", separation.bound.len()));
@@ -513,10 +486,8 @@ pub(crate) async fn separate_ui_impl(
tree_index,
batch_index
);
mark_batch_problematic(&mut separation, tree_index, &batch, error);
write_separation_state(&state_path, &separation)?;
batch_index += 1;
continue;
return Err(error);
}
let binding = match visual_binding(source_url.clone(), processed_url, &batch).await {
Ok(value) => value,
@@ -526,10 +497,8 @@ pub(crate) async fn separate_ui_impl(
tree_index,
batch_index
);
mark_batch_problematic(&mut separation, tree_index, &batch, error);
write_separation_state(&state_path, &separation)?;
batch_index += 1;
continue;
return Err(error);
}
};
app_log!(
@@ -578,10 +547,8 @@ pub(crate) async fn separate_ui_impl(
tree_index,
batch_index
);
mark_batch_problematic(&mut separation, tree_index, &batch, error);
write_separation_state(&state_path, &separation)?;
batch_index += 1;
continue;
return Err(error);
}
apply_batch_patch(&mut separation, tree_index, &binding.decisions, &cut_paths)?;
write_separation_state(&state_path, &separation)?;