|
@@ -2,25 +2,28 @@ package com.backendsys.modules.sdk.comfyui.service.impl;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.backendsys.modules.sdk.comfyui.entity.CFPromptResponse;
|
|
|
-import com.backendsys.modules.sdk.comfyui.entity.Text2Image;
|
|
|
-import com.backendsys.modules.sdk.comfyui.service.ComfyUIService;
|
|
|
-import com.backendsys.modules.sdk.comfyui.service.Text2ImageService;
|
|
|
+import com.backendsys.modules.sdk.comfyui.dao.ComfyuiTaskDao;
|
|
|
+import com.backendsys.modules.sdk.comfyui.entity.ComfyuiResponse;
|
|
|
+import com.backendsys.modules.sdk.comfyui.entity.ComfyuiText2Image;
|
|
|
+import com.backendsys.modules.sdk.comfyui.service.ComfyuiService;
|
|
|
+import com.backendsys.modules.sdk.comfyui.service.ComfyuiText2ImageService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
@Service
|
|
|
-public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
+public class ComfyuiText2ImageServiceImpl implements ComfyuiText2ImageService {
|
|
|
|
|
|
@Autowired
|
|
|
- private ComfyUIService comfyUIService;
|
|
|
+ private ComfyuiService comfyUIService;
|
|
|
+ @Autowired
|
|
|
+ private ComfyuiTaskDao comfyuiTaskDao;
|
|
|
|
|
|
/**
|
|
|
* [ComfyUI] 文生图 (7.4生图.json)
|
|
|
*/
|
|
|
@Override
|
|
|
- public CFPromptResponse generateText2Image(String client_id, Text2Image text2Image) {
|
|
|
+ public ComfyuiResponse generateText2Image(String client_id, ComfyuiText2Image comfyuiText2Image) {
|
|
|
|
|
|
String prompt = "{"+
|
|
|
" \"3\": {"+
|
|
@@ -47,7 +50,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"13\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"guidance\": " + text2Image.getPrompt_flux_guidance() + ","+
|
|
|
+ " \"guidance\": " + comfyuiText2Image.getPrompt_flux_guidance() + ","+
|
|
|
" \"conditioning\": ["+
|
|
|
" \"3\","+
|
|
|
" 0"+
|
|
@@ -120,7 +123,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"37\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"noise_seed\": " + text2Image.getSeed() +
|
|
|
+ " \"noise_seed\": " + comfyuiText2Image.getSeed() +
|
|
|
" },"+
|
|
|
" \"class_type\": \"RandomNoise\","+
|
|
|
" \"_meta\": {"+
|
|
@@ -159,7 +162,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"84\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"sampler_name\": \"" + text2Image.getSampler() + "\""+
|
|
|
+ " \"sampler_name\": \"" + comfyuiText2Image.getSampler() + "\""+
|
|
|
" },"+
|
|
|
" \"class_type\": \"KSamplerSelect\","+
|
|
|
" \"_meta\": {"+
|
|
@@ -176,7 +179,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" \"122\","+
|
|
|
" 0"+
|
|
|
" ],"+
|
|
|
- " \"batch_size\": " + text2Image.getBatch_size() +
|
|
|
+ " \"batch_size\": " + comfyuiText2Image.getBatch_size() +
|
|
|
" },"+
|
|
|
" \"class_type\": \"EmptySD3LatentImage\","+
|
|
|
" \"_meta\": {"+
|
|
@@ -214,7 +217,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"121\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"value\": " + text2Image.getWidth() +
|
|
|
+ " \"value\": " + comfyuiText2Image.getWidth() +
|
|
|
" },"+
|
|
|
" \"class_type\": \"easy int\","+
|
|
|
" \"_meta\": {"+
|
|
@@ -223,7 +226,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"122\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"value\": " + text2Image.getHeight() +
|
|
|
+ " \"value\": " + comfyuiText2Image.getHeight() +
|
|
|
" },"+
|
|
|
" \"class_type\": \"easy int\","+
|
|
|
" \"_meta\": {"+
|
|
@@ -276,7 +279,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" \"150\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
" \"scheduler\": \"normal\","+
|
|
|
- " \"steps\": " + text2Image.getStep() + ","+
|
|
|
+ " \"steps\": " + comfyuiText2Image.getStep() + ","+
|
|
|
" \"denoise\": 1,"+
|
|
|
" \"model\": ["+
|
|
|
" \"152\","+
|
|
@@ -290,7 +293,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"151\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"ckpt_name\": \"" + text2Image.getModel_name() + "\""+
|
|
|
+ " \"ckpt_name\": \"" + comfyuiText2Image.getModel_name() + "\""+
|
|
|
" },"+
|
|
|
" \"class_type\": \"CheckpointLoaderSimple\","+
|
|
|
" \"_meta\": {"+
|
|
@@ -313,7 +316,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
" },"+
|
|
|
" \"153\": {"+
|
|
|
" \"inputs\": {"+
|
|
|
- " \"text\": \"" + text2Image.getPrompt_text() + "\","+
|
|
|
+ " \"text\": \"" + comfyuiText2Image.getPrompt_text() + "\","+
|
|
|
" \"speak_and_recognation\": {"+
|
|
|
" \"__value__\": ["+
|
|
|
" false,"+
|
|
@@ -331,8 +334,8 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
JSONObject prompt_object = JSONUtil.parseObj(prompt);
|
|
|
|
|
|
// [ComfyUI] 执行任务
|
|
|
- Mono<CFPromptResponse> cfPromptResponseMono = comfyUIService.prompt(client_id, prompt_object);
|
|
|
- CFPromptResponse response = cfPromptResponseMono.block();
|
|
|
+ Mono<ComfyuiResponse> cfPromptResponseMono = comfyUIService.prompt(client_id, prompt_object);
|
|
|
+ ComfyuiResponse response = cfPromptResponseMono.block();
|
|
|
response.setClient_id(client_id);
|
|
|
return response;
|
|
|
}
|
|
@@ -342,19 +345,19 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
* [ComfyUI] 文生图 (基础生图)
|
|
|
*/
|
|
|
@Override
|
|
|
- public CFPromptResponse generateText2ImageSimple(String client_id, Text2Image text2Image) {
|
|
|
+ public ComfyuiResponse generateText2ImageSimple(String client_id, ComfyuiText2Image comfyuiText2Image) {
|
|
|
|
|
|
// [ComfyUI-基础生图]
|
|
|
String prompt = "{" +
|
|
|
"\"3\": {" +
|
|
|
"\"inputs\": {" +
|
|
|
// "\"seed\": 449753344472378," +
|
|
|
- "\"seed\": " + text2Image.getSeed() + "," +
|
|
|
+ "\"seed\": " + comfyuiText2Image.getSeed() + "," +
|
|
|
// "\"steps\": 20," +
|
|
|
- "\"steps\": " + text2Image.getStep() + "," +
|
|
|
+ "\"steps\": " + comfyuiText2Image.getStep() + "," +
|
|
|
"\"cfg\": 8," +
|
|
|
// "\"sampler_name\": \"euler\"," +
|
|
|
- "\"sampler_name\": \"" + text2Image.getSampler() + "\"," +
|
|
|
+ "\"sampler_name\": \"" + comfyuiText2Image.getSampler() + "\"," +
|
|
|
"\"scheduler\": \"normal\", \"denoise\": 1," +
|
|
|
"\"model\": [\"4\", 0], \"positive\": [\"6\", 0]," +
|
|
|
"\"negative\": [\"7\", 0], \"latent_image\": [\"5\", 0]" +
|
|
@@ -364,7 +367,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
"\"4\": {" +
|
|
|
"\"inputs\": {" +
|
|
|
// "\"ckpt_name\": \"v1-5-pruned-emaonly-fp16.safetensors\"" +
|
|
|
- "\"ckpt_name\": \"" + text2Image.getModel_name() + "\"" +
|
|
|
+ "\"ckpt_name\": \"" + comfyuiText2Image.getModel_name() + "\"" +
|
|
|
"}," +
|
|
|
"\"class_type\": \"CheckpointLoaderSimple\"," +
|
|
|
"\"_meta\": { \"title\": \"Checkpoint加载器(简易)\" }" +
|
|
@@ -374,9 +377,9 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
// "\"width\": 512," +
|
|
|
// "\"height\": 512," +
|
|
|
// "\"batch_size\": 1" +
|
|
|
- "\"width\": " + text2Image.getWidth() + "," +
|
|
|
- "\"height\": " + text2Image.getHeight() + "," +
|
|
|
- "\"batch_size\": " + text2Image.getBatch_size() +
|
|
|
+ "\"width\": " + comfyuiText2Image.getWidth() + "," +
|
|
|
+ "\"height\": " + comfyuiText2Image.getHeight() + "," +
|
|
|
+ "\"batch_size\": " + comfyuiText2Image.getBatch_size() +
|
|
|
"}," +
|
|
|
"\"class_type\": \"EmptyLatentImage\"," +
|
|
|
"\"_meta\": { \"title\": \"空Latent图像\" }" +
|
|
@@ -384,7 +387,7 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
"\"6\": {" +
|
|
|
"\"inputs\": {" +
|
|
|
// "\"text\": \"beautiful scenery nature glass bottle landscape, , purple galaxy bottle,\"," +
|
|
|
- "\"text\": \"" + text2Image.getPrompt_text() + "\"," +
|
|
|
+ "\"text\": \"" + comfyuiText2Image.getPrompt_text() + "\"," +
|
|
|
"\"speak_and_recognation\": { \"__value__\": [false, true] }," +
|
|
|
"\"clip\": [\"4\", 1]" +
|
|
|
"}," +
|
|
@@ -415,8 +418,8 @@ public class Text2ImageServiceImpl implements Text2ImageService {
|
|
|
JSONObject prompt_object = JSONUtil.parseObj(prompt);
|
|
|
|
|
|
// [ComfyUI] 执行任务
|
|
|
- Mono<CFPromptResponse> cfPromptResponseMono = comfyUIService.prompt(client_id, prompt_object);
|
|
|
- CFPromptResponse response = cfPromptResponseMono.block();
|
|
|
+ Mono<ComfyuiResponse> cfPromptResponseMono = comfyUIService.prompt(client_id, prompt_object);
|
|
|
+ ComfyuiResponse response = cfPromptResponseMono.block();
|
|
|
response.setClient_id(client_id);
|
|
|
return response;
|
|
|
}
|