diff --git a/dsAiSupport/pom.xml b/dsAiSupport/pom.xml index 61e9a91a..955f7b48 100644 --- a/dsAiSupport/pom.xml +++ b/dsAiSupport/pom.xml @@ -53,6 +53,13 @@ commons-io 2.15.0 + + + cloud.liblibai.openapi + java-sdk + 0.0.9 + compile + com.alibaba diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/ComfyTask.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/ComfyTask.java new file mode 100644 index 00000000..3308541e --- /dev/null +++ b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/ComfyTask.java @@ -0,0 +1,73 @@ +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.*; + +import java.util.HashMap; + +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()); + } + + } +} diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/ControlNetExample.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/ControlNetExample.java new file mode 100644 index 00000000..8784099b --- /dev/null +++ b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/ControlNetExample.java @@ -0,0 +1,31 @@ +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); + } + } + +} diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/LiblibTextToImage.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/LiblibTextToImage.java deleted file mode 100644 index d0543a1f..00000000 --- a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/LiblibTextToImage.java +++ /dev/null @@ -1,229 +0,0 @@ -package com.dsideal.aiSupport.Util.Liblib; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.dsideal.aiSupport.Plugin.YamlProp; -import com.jfinal.kit.Prop; -import lombok.Getter; -import lombok.Setter; -import okhttp3.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static com.dsideal.aiSupport.AiSupportApplication.getEnvPrefix; - -/** - * Liblib文生图API工具类 - */ -public class LiblibTextToImage { - - private static final String API_BASE_URL = "https://openapi.liblibai.cloud"; - private static final String TEXT_TO_IMG_URL = API_BASE_URL + "/api/generate/webui/text2img"; - // 移除路径末尾的斜杠,避免重复 - private static final String QUERY_STATUS_URL = API_BASE_URL + "/api/generate/webui/status"; - private static final Logger log = LoggerFactory.getLogger(LiblibTextToImage.class); - - // 获取项目根目录路径 - protected static String projectRoot = System.getProperty("user.dir").replace("\\","/")+"/dsAiSupport"; - // 拼接相对路径 - protected static String basePath = projectRoot + "/src/main/java/com/dsideal/aiSupport/Util/Liblib/Example/"; - - // 修改静态初始化块,添加accessKey - protected static String accessKey; // API访问密钥(AK) - protected static String secretKey; // API密钥(SK) - public static Prop PropKit; // 配置文件工具 - - static { - //加载配置文件 - String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix()); - PropKit = new YamlProp(configFile); - accessKey = PropKit.get("LIBLIB.accessKey"); - secretKey = PropKit.get("LIBLIB.secretKey"); - } - - /** - * 创建OkHttpClient实例 - * @return OkHttpClient实例 - */ - private static OkHttpClient createHttpClient() { - return new OkHttpClient.Builder() - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(60, TimeUnit.SECONDS) - .writeTimeout(60, TimeUnit.SECONDS) - .build(); - } - - /** - * 提交文生图任务 - * @param templateUuid 参数模板UUID (可选) - * @param checkPointId 底模ID - * @param prompt 提示词 - * @param negativePrompt 负面提示词 - * @param width 宽度 - * @param height 高度 - * @param imgCount 图片数量 - * @param seed 随机种子值,-1表示随机 - * @param additionalNetworks LoRA模型列表 - * @param enableHiRes 是否启用高分辨率修复 - * @return 生成任务UUID - * @throws IOException 异常信息 - */ - public static String submitTextToImageTask(String templateUuid, String checkPointId, String prompt, - String negativePrompt, int width, int height, int imgCount, - long seed, List additionalNetworks, boolean enableHiRes) throws IOException { - // 创建OkHttpClient - OkHttpClient client = createHttpClient(); - - // 构建请求体 - JSONObject requestBody = new JSONObject(); - - // 添加模板UUID (如果有) - if (templateUuid != null && !templateUuid.isEmpty()) { - requestBody.put("templateUuid", templateUuid); - } - - // 构建生成参数 - JSONObject generateParams = new JSONObject(); - generateParams.put("checkPointId", checkPointId); - generateParams.put("prompt", prompt); - generateParams.put("negativePrompt", negativePrompt); - generateParams.put("sampler", 15); // 采样方法 - generateParams.put("steps", 20); // 采样步数 - generateParams.put("cfgScale", 7); // 提示词引导系数 - generateParams.put("width", width); - generateParams.put("height", height); - generateParams.put("imgCount", imgCount); - generateParams.put("randnSource", 0); // 随机种子生成器 0 cpu,1 Gpu - generateParams.put("seed", seed); - generateParams.put("restoreFaces", 0); // 面部修复,0关闭,1开启 - - // 添加LoRA模型 - if (additionalNetworks != null && !additionalNetworks.isEmpty()) { - JSONArray loraArray = new JSONArray(); - for (LoraModel lora : additionalNetworks) { - JSONObject loraObj = new JSONObject(); - loraObj.put("modelId", lora.getModelId()); - loraObj.put("weight", lora.getWeight()); - loraArray.add(loraObj); - } - generateParams.put("additionalNetwork", loraArray); - } - - // 添加高分辨率修复参数 - if (enableHiRes) { - JSONObject hiResFixInfo = new JSONObject(); - hiResFixInfo.put("hiresSteps", 20); // 高分辨率修复的重绘步数 - hiResFixInfo.put("hiresDenoisingStrength", 0.75); // 高分辨率修复的重绘幅度 - hiResFixInfo.put("upscaler", 10); // 放大算法模型枚举 - hiResFixInfo.put("resizedWidth", (int)(width * 1.5)); // 放大后的宽度,转为整数 - hiResFixInfo.put("resizedHeight", (int)(height * 1.5)); // 放大后的高度,转为整数 - generateParams.put("hiResFixInfo", hiResFixInfo); - } - - // 将生成参数添加到请求体 - requestBody.put("generateParams", generateParams); - // 获取API路径 - String uri = "/api/generate/webui/text2img"; - // 生成签名信息 - SignUtil.SignatureInfo signInfo = SignUtil.makeSign(uri, secretKey); - - // 构建带签名的URL - HttpUrl.Builder urlBuilder = HttpUrl.parse(TEXT_TO_IMG_URL).newBuilder() - .addQueryParameter("AccessKey", accessKey) - .addQueryParameter("Signature", signInfo.getSignature()) - .addQueryParameter("Timestamp", String.valueOf(signInfo.getTimestamp())) - .addQueryParameter("SignatureNonce", signInfo.getSignatureNonce()); - - // 创建请求 - MediaType mediaType = MediaType.parse("application/json"); - RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString()); - Request request = new Request.Builder() - .url(urlBuilder.build()) - .method("POST", body) - .addHeader("Content-Type", "application/json") - .build(); - - // 执行请求 - log.info("提交文生图任务: {}", requestBody.toJSONString()); - log.info("请求URL: {}", urlBuilder.build()); - Response response = client.newCall(request).execute(); - - // 处理响应 - if (!response.isSuccessful()) { - String errorMsg = "文生图任务提交失败,状态码: " + response.code(); - log.error(errorMsg); - throw new IOException(errorMsg); - } - - // 解析响应 - String responseBody = response.body().string(); - log.info("文生图任务提交响应: {}", responseBody); - - JSONObject responseJson = JSON.parseObject(responseBody); - int code = responseJson.getIntValue("code"); - - if (code != 0) { - String errorMsg = "文生图任务提交失败,错误码: " + code + ", 错误信息: " + responseJson.getString("msg"); - log.error(errorMsg); - throw new IOException(errorMsg); - } - - // 获取生成任务UUID - String generateUuid = responseJson.getJSONObject("data").getString("generateUuid"); - log.info("文生图任务已提交,任务UUID: {}", generateUuid); - - return generateUuid; - } - - - /** - * LoRA模型类 - */ - @Setter - @Getter - public static class LoraModel { - private String modelId; // LoRA的模型版本UUID - private double weight; // LoRA权重 - - public LoraModel(String modelId, double weight) { - this.modelId = modelId; - this.weight = weight; - } - } - - /** - * 使用示例 - */ - public static void main(String[] args) { - try { - // 创建LoRA模型列表 -// List loraModels = new ArrayList<>(); -// loraModels.add(new LoraModel("31360f2f031b4ff6b589412a52713fcf", 0.3)); // 修改baseType为2 -// loraModels.add(new LoraModel("365e700254dd40bbb90d5e78c152ec7f", 0.6)); // 保持原值或根据查询结果修改 -// - // 提交文生图任务 - String generateUuid = submitTextToImageTask( - "e10adc3949ba59abbe56e057f20f883e", // 模板UUID - "0ea388c7eb854be3ba3c6f65aac6bfd3", // 底模ID - "Asian portrait,A young woman wearing a green baseball cap,covering one eye with her hand", // 提示词 - "ng_deepnegative_v1_75t,(badhandv4:1.2),EasyNegative,(worst quality:2),", // 负面提示词 - 768, // 宽度 - 1024, // 高度 - 1, // 图片数量 - 2228967414L, // 随机种子值 - null, // LoRA模型列表 - true // 启用高分辨率修复 - ); - - - - } catch (Exception e) { - log.error("文生图任务执行失败", e); - } - } -} \ No newline at end of file diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/QueryModel.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/QueryModel.java deleted file mode 100644 index 71379725..00000000 --- a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/QueryModel.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.dsideal.aiSupport.Util.Liblib; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.dsideal.aiSupport.Plugin.YamlProp; -import com.jfinal.kit.Prop; -import okhttp3.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import static com.dsideal.aiSupport.AiSupportApplication.getEnvPrefix; - -/** - * Liblib模型查询工具类 - */ -public class QueryModel { - - private static final String API_BASE_URL = "https://openapi.liblibai.cloud"; - private static final String MODEL_VERSION_URL = API_BASE_URL + "/api/model/version/get"; - - private static final Logger log = LoggerFactory.getLogger(QueryModel.class); - - // API访问密钥 - protected static String accessKey; - protected static String secretKey; - public static Prop PropKit; - - static { - //加载配置文件 - String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix()); - PropKit = new YamlProp(configFile); - accessKey = PropKit.get("LIBLIB.accessKey"); - secretKey = PropKit.get("LIBLIB.secretKey"); - } - - /** - * 创建OkHttpClient实例 - * @return OkHttpClient实例 - */ - private static OkHttpClient createHttpClient() { - return new OkHttpClient.Builder() - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(60, TimeUnit.SECONDS) - .writeTimeout(60, TimeUnit.SECONDS) - .build(); - } - - /** - * 查询模型版本信息 - * @param versionUuid 模型版本UUID - * @return 模型版本信息 - * @throws IOException 异常信息 - */ - public static JSONObject queryModelVersion(String versionUuid) throws IOException { - // 创建OkHttpClient - OkHttpClient client = createHttpClient(); - - // 构建请求体 - JSONObject requestBody = new JSONObject(); - requestBody.put("versionUuid", versionUuid); - - // 获取API路径 - String uri = "/api/model/version/get"; - - // 生成签名信息 - SignUtil.SignatureInfo signInfo = SignUtil.makeSign(uri, secretKey); - - // 构建带签名的URL - HttpUrl.Builder urlBuilder = HttpUrl.parse(MODEL_VERSION_URL).newBuilder() - .addQueryParameter("AccessKey", accessKey) - .addQueryParameter("Signature", signInfo.getSignature()) - .addQueryParameter("Timestamp", String.valueOf(signInfo.getTimestamp())) - .addQueryParameter("SignatureNonce", signInfo.getSignatureNonce()); - - // 创建请求 - MediaType mediaType = MediaType.parse("application/json"); - RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString()); - Request request = new Request.Builder() - .url(urlBuilder.build()) - .method("POST", body) - .addHeader("Content-Type", "application/json") - .build(); - - // 执行请求 - log.info("查询模型版本信息: {}", requestBody.toJSONString()); - log.info("请求URL: {}", urlBuilder.build()); - Response response = client.newCall(request).execute(); - - // 处理响应 - if (!response.isSuccessful()) { - String errorMsg = "查询模型版本信息失败,状态码: " + response.code(); - log.error(errorMsg); - throw new IOException(errorMsg); - } - - // 解析响应 - String responseBody = response.body().string(); - log.info("查询模型版本信息响应: {}", responseBody); - - JSONObject responseJson = JSON.parseObject(responseBody); - int code = responseJson.getIntValue("code"); - - if (code != 0) { - String errorMsg = "查询模型版本信息失败,错误码: " + code + ", 错误信息: " + responseJson.getString("msg"); - log.error(errorMsg); - throw new IOException(errorMsg); - } - - return responseJson.getJSONObject("data"); - } - - /** - * 使用示例 - */ - public static void main(String[] args) { - try { - // 查询模型版本信息 - //String versionUuid = "86961315d0b34f229d58fadb7f284972"; - String versionUuid = "31360f2f031b4ff6b589412a52713fcf"; - JSONObject modelVersionInfo = queryModelVersion(versionUuid); - - // 打印模型版本信息 - log.info("模型版本信息: {}", modelVersionInfo); - - // 提取关键信息 - String modelName = modelVersionInfo.getString("modelName"); - String versionName = modelVersionInfo.getString("versionName"); - String description = modelVersionInfo.getString("description"); - - log.info("模型名称: {}", modelName); - log.info("版本名称: {}", versionName); - log.info("描述: {}", description); - - } catch (Exception e) { - log.error("查询模型版本信息失败", e); - } - } -} diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/SignUtil.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/SignUtil.java deleted file mode 100644 index 6de17e4e..00000000 --- a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/SignUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.dsideal.aiSupport.Util.Liblib; - -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import lombok.Getter; -import lombok.Setter; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang3.RandomStringUtils; - -public class SignUtil { - - /** - * 生成请求签名 - * @param uri 请求API接口的uri地址 - * @param secretKey 密钥(SK) - * @return 签名信息对象,包含签名和相关参数 - */ - public static SignatureInfo makeSign(String uri, String secretKey) { - // 当前毫秒时间戳 - Long timestamp = System.currentTimeMillis(); - // 随机字符串 - String signatureNonce = RandomStringUtils.randomAlphanumeric(10); - // 拼接请求数据 - String content = uri + "&" + timestamp + "&" + signatureNonce; - - try { - // 生成签名 - SecretKeySpec secret = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1"); - Mac mac = Mac.getInstance("HmacSHA1"); - mac.init(secret); - String signature = Base64.encodeBase64URLSafeString(mac.doFinal(content.getBytes())); - - // 返回签名信息对象 - return new SignatureInfo(signature, timestamp, signatureNonce); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("no such algorithm"); - } catch (InvalidKeyException e) { - throw new RuntimeException(e); - } - } - /** - * 签名信息类,包含签名和相关参数 - */ - @Getter - @Setter - public static class SignatureInfo { - private final String signature; - private final Long timestamp; - private final String signatureNonce; - - public SignatureInfo(String signature, Long timestamp, String signatureNonce) { - this.signature = signature; - this.timestamp = timestamp; - this.signatureNonce = signatureNonce; - } - } -} \ No newline at end of file diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/TextToImage.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/TextToImage.java new file mode 100644 index 00000000..5d2a7b44 --- /dev/null +++ b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/TextToImage.java @@ -0,0 +1,63 @@ +package com.dsideal.aiSupport.Util.Liblib; + +import cloud.liblibai.client.LibLib; +import cloud.liblibai.openapi.client.ApiException; +import cloud.liblibai.openapi.client.model.*; + +import java.util.HashMap; +import java.util.Map; + +public class TextToImage { + public static void main(String[] args) throws ApiException, InterruptedException { + LibLib api = new LibLib(); + GetModelVersionRequest getModelVersionRequest = new GetModelVersionRequest(); + getModelVersionRequest.setVersionUuid("a57911b5dfe64c6aa78821be99367276"); + 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("a57911b5dfe64c6aa78821be99367276"); + params.prompt("1 girl").imgCount(2); + params.cfgScale(7.5); + ControlNet controlNet = new ControlNet(); + controlNet.width(1024).height(768); + Map annoParams = new HashMap<>(); + Map cannyParams = new HashMap<>(); + cannyParams.put("preprocessorResolution", 512); + annoParams.put("canny", cannyParams); + controlNet.unitOrder(1); + controlNet.model("efb97e9d8c237573298c3a5a7869b89c").preprocessor(1) + .sourceImage("https://liblibai-online.liblib.cloud/img/081e9f07d9bd4c2ba090efde163518f9/7c1cc38e-522c-43fe-aca9-07d5420d743e.png") + .annotationParameters(annoParams); + params.addControlNetItem(controlNet); + params.vaeId("2c1a337416e029dd65ab58784e8a4763"); + 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); + } + + //NOTE(gz): 同步 SDK 调用方法 +// StatusResponseData statusResponseData = api.textToImage(request); +// if (statusResponseData.getGenerateStatus() == GenerateStatus.SUCCEED) { +// System.out.println(statusResponseData.getImages()); +// } + + } +} diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/TextToImageUltra.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/TextToImageUltra.java new file mode 100644 index 00000000..086018da --- /dev/null +++ b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/Liblib/TextToImageUltra.java @@ -0,0 +1,29 @@ +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 TextToImageUltra { + public static void main(String[] args) throws ApiException, InterruptedException { + LibLib api = new LibLib(); + TextToImageUltraRequest request = new TextToImageUltraRequest(); + request.templateUuid("5d7e67009b344550bc1aa6ccbfa1d7f4"); + TextToImageUltraRequestGenerateParams params = new TextToImageUltraRequestGenerateParams(); + request.generateParams(params); + params.prompt("1 girl").aspectRatio(TextToImageUltraRequestGenerateParams.AspectRatioEnum.PORTRAIT) + .steps(30).imgCount(4); + SubmitResponse submitResponse = api.submitTextToImageUltra(request); + + while(true) { + StatusResponse status = api.getStatus(new StatusRequest().generateUuid(submitResponse.getData().getGenerateUuid())); + System.out.println(status.toJson()); + if (status.getData().getGenerateStatus() == GenerateStatus.SUCCEED) { + System.out.println(status.getData().getImages()); + break; + } + Thread.sleep(5000); + } + + } +}