main
HuangHai 2 months ago
parent 62f8be4f34
commit b7bfd6f22c

@ -0,0 +1,73 @@
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.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");
//提示词
params.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)")
.imgCount(1);//生成一张图片
params.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");
// 参考图片右下方:
// 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(1);
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…
Cancel
Save