parent
8c203326f5
commit
1fc1588b12
@ -1,71 +0,0 @@
|
||||
package com.dsideal.aiSupport.Util.Liblib;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import cloud.liblibai.client.LibLib;
|
||||
import cloud.liblibai.openapi.client.ApiException;
|
||||
import cloud.liblibai.openapi.client.model.*;
|
||||
|
||||
public class ComfyTask {
|
||||
|
||||
public static void main(String[] args) throws ApiException, JsonProcessingException, InterruptedException {
|
||||
LibLib api = new LibLib();
|
||||
ComfyRequest request = new ComfyRequest();
|
||||
|
||||
request.templateUuid("");
|
||||
|
||||
ComfyNodeParams inputNode = new ComfyNodeParams();
|
||||
inputNode.classType("LoadImage")
|
||||
.putInputsItem("image", "https://liblibai-tmp-image.liblib.cloud/img/baf2e419ce1cb06812314957efd2e067/af0c523d3d2b4092ab45c64c72e4deb76babb12e9b8a178eb524143c3b71bf85.png");
|
||||
|
||||
ComfyNodeParams scaleNode = new ComfyNodeParams();
|
||||
scaleNode.classType("ScaleImage")
|
||||
.putInputsItem("width", 768);
|
||||
|
||||
ComfyNodeParams repeatLatentNode = new ComfyNodeParams();
|
||||
repeatLatentNode.classType("RepeatLatentImage")
|
||||
.putInputsItem("amount", 4);
|
||||
|
||||
ComfyRequestGenerateParams generateParams = new ComfyRequestGenerateParams();
|
||||
generateParams.workflowUuid("2f22ab7ce4c044afb6d5eee2e61547f3");
|
||||
generateParams.putAdditionalProperty("12", inputNode);
|
||||
generateParams.putAdditionalProperty("112", scaleNode);
|
||||
generateParams.putAdditionalProperty("136", repeatLatentNode);
|
||||
request.generateParams(generateParams);
|
||||
|
||||
// 异步 SDK API 调用
|
||||
SubmitComfyResponse submitComfyResponse = api.submitComfyTask(request);
|
||||
String uuid = submitComfyResponse.getData().getGenerateUuid();
|
||||
|
||||
boolean finished = false;
|
||||
while (!finished) {
|
||||
ComfyStatusResponse comfyStatus = api.getComfyStatus(new ComfyStatusRequest().generateUuid(uuid));
|
||||
GenerateStatus status = comfyStatus.getData().getGenerateStatus();
|
||||
System.out.println(comfyStatus);
|
||||
switch (status) {
|
||||
case RUNNING:
|
||||
case PENDING:
|
||||
case APPROVING:
|
||||
case GENERATED:
|
||||
break;
|
||||
case SUCCEED:
|
||||
finished = true;
|
||||
System.out.println(status);
|
||||
break;
|
||||
case TIMEOUT:
|
||||
case FAILED:
|
||||
finished = true;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown comfy status: " + status);
|
||||
}
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
|
||||
//同步 SDK API 调用 ComfyTask
|
||||
ComfyStatusResponseData comfyStatusResponseData = api.runComfy(request);
|
||||
if (comfyStatusResponseData.getGenerateStatus() == GenerateStatus.SUCCEED) {
|
||||
System.out.println("generated images: " + comfyStatusResponseData.getImages());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.dsideal.aiSupport.Util.Liblib;
|
||||
|
||||
import cloud.liblibai.client.LibLib;
|
||||
import cloud.liblibai.openapi.client.ApiException;
|
||||
import cloud.liblibai.openapi.client.model.*;
|
||||
|
||||
public class ControlNetExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
LibLib api = new LibLib();
|
||||
TextToImageRequest request = new TextToImageRequest();
|
||||
TextToImageRequestGenerateParams params = new TextToImageRequestGenerateParams();
|
||||
// ControlNet controlnet = new ControlNet();
|
||||
// controlnet.unitOrder(1);
|
||||
// controlnet.setModel()
|
||||
params.prompt("1 girl").imgCount(1);
|
||||
request.generateParams(params);
|
||||
request.templateUuid("6f7c4652458d4802969f8d089cf5b91f");
|
||||
|
||||
try {
|
||||
StatusResponseData statusResponseData = api.textToImage(request);
|
||||
if (statusResponseData.getGenerateStatus() == GenerateStatus.SUCCEED ) {
|
||||
System.out.println("Generated output examples" + statusResponseData.getImages());
|
||||
}
|
||||
|
||||
} catch (ApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.dsideal.aiSupport.Util.Liblib;
|
||||
|
||||
import cloud.liblibai.client.LibLib;
|
||||
import cloud.liblibai.openapi.client.ApiException;
|
||||
import cloud.liblibai.openapi.client.model.*;
|
||||
import com.dsideal.aiSupport.Plugin.YamlProp;
|
||||
import com.dsideal.aiSupport.Util.Liblib.Enum.SamplingMethod;
|
||||
import com.jfinal.kit.Prop;
|
||||
|
||||
import static com.dsideal.aiSupport.AiSupportApplication.getEnvPrefix;
|
||||
|
||||
public class TextToImage2 {
|
||||
// API访问凭证
|
||||
protected static final String ak; // Access Key
|
||||
protected static final String sk; // Secret Key
|
||||
public static Prop PropKit; // 配置文件工具
|
||||
|
||||
static {
|
||||
//加载配置文件
|
||||
String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix());
|
||||
PropKit = new YamlProp(configFile);
|
||||
ak = PropKit.get("LIBLIB.accessKey"); // 从配置文件获取Access Key
|
||||
sk = PropKit.get("LIBLIB.secretKey"); // 从配置文件获取Secret Key
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws ApiException, InterruptedException {
|
||||
LibLib api = new LibLib(ak, sk);
|
||||
GetModelVersionRequest getModelVersionRequest = new GetModelVersionRequest();
|
||||
// Dream Tech XL | 筑梦工业XL
|
||||
// https://www.liblib.art/modelinfo/5611e2f826be47f5b8c7eae45ed5434a?from=api&versionUuid=a57911b5dfe64c6aa78821be99367276
|
||||
getModelVersionRequest.setVersionUuid("ee0b113517dc4b5ca1ab4499db72cda1");
|
||||
VersionResponse modelVersion = api.getModelVersion(getModelVersionRequest);
|
||||
if (modelVersion.getData().getCommercialUse() == CommercialUseEnum.CommercialUse) {
|
||||
//显示模型信息
|
||||
System.out.println(modelVersion);
|
||||
}
|
||||
TextToImageRequest request = new TextToImageRequest();
|
||||
TextToImageRequestGenerateParams params = new TextToImageRequestGenerateParams();
|
||||
params.checkPointId("ee0b113517dc4b5ca1ab4499db72cda1");
|
||||
//提示词
|
||||
String prompt = "<lora:KTDW-000028:1>,3D cartoon style,This is a highly detailed CGI artwork depicting a young girl and a small rabbit in a serene, sunlit garden. The girl, with fair skin and large, expressive brown eyes, has her dark brown hair tied up with a yellow ribbon. She is wearing a sleeveless, floral dress in pastel shades of pink, green, and yellow. The girl is sitting on a beige, cushioned lounge chair, holding an open book in her hands. Beside her, a cute, fluffy rabbit with large ears and soft brown fur is also looking at the book. The background is a lush, green garden with blurred, sunlit foliage and white daisies, creating a dreamy atmosphere. Butterflies, one yellow and one orange, flutter around the scene, adding to the whimsical feel. The overall color palette is soft and warm, enhancing the peaceful and idyllic setting., (masterpiece:1.3),( best quality:1.3),(high detail:1.3)";
|
||||
params.prompt(prompt).imgCount(1);//生成一张图片
|
||||
//反向提示词
|
||||
String negativePrompt = "over sharpening,dirt,bad color matching,graying,(worst quality:2),(low quality:2),(normal quality:2),(Proportional imbalance:1.5),wrong perspective,distorted person,Twisted Car,(lowres:1.1),(monochrome),(grayscale),blurry,signature,drawing,graffiti,text,word,logo,cropped,out of frame,ugly,deformed,noisy,(low contrast:1.3),painting,illustration,NSFW,EasyNegative";
|
||||
params.negativePrompt(negativePrompt);
|
||||
// 参考图片右下方:
|
||||
// https://www.liblib.art/imageinfo/13ea5cca203f4ca59db98956e213aaf0
|
||||
params.cfgScale(1.0);
|
||||
params.setWidth(1024);
|
||||
params.setHeight(1360);
|
||||
params.setSteps(30);
|
||||
//https://liblibai.feishu.cn/wiki/UAMVw67NcifQHukf8fpccgS5n6d
|
||||
// 黄海自定义了枚举类,这样方便对照文档中的枚举值
|
||||
params.setSampler(SamplingMethod.EULER_A.getValue());
|
||||
params.seed(1430455276);
|
||||
|
||||
request.generateParams(params);
|
||||
request.templateUuid("6f7c4652458d4802969f8d089cf5b91f");
|
||||
|
||||
|
||||
//NOTE(gz): 异步 SDK 调用方法
|
||||
SubmitResponse submitResponse = api.submitTextToImage(request);
|
||||
while (true) {
|
||||
if (submitResponse.getData() == null) {
|
||||
System.out.println("Error: " + submitResponse.getMsg());
|
||||
break;
|
||||
}
|
||||
StatusResponse status = api.getStatus(new StatusRequest().generateUuid(submitResponse.getData().getGenerateUuid()));
|
||||
System.out.println(status);
|
||||
if (status.getData().getGenerateStatus() == GenerateStatus.SUCCEED) {
|
||||
System.out.println(status.getData().getImages());
|
||||
break;
|
||||
}
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue