Use the SD image generation service
更新时间:
复制 MD 格式
Prerequisites
The Intelligent Creation Workshop public cloud service has been activated.
Quick test
Procedure
Step 1: Create an application and view its details
In the console, navigate to Application Management. Click Create Application and enter the application information.
Select the application that you created and click View Details.
Step 2: Get the WebUI endpoint
Click Generate Test Link. Select the default role and click Generate Now. Open the WebUI endpoint in your browser to start creating images.
SDK call
Procedure
Step 1: Create an application and get the service AK and SK
In the console, navigate to Application Management. Click Create Application and enter the application information.
Select the application that you created. Click View Details to view the application AK and SK.
Step 2: Integrate the SDK
Language |
Document |
Java |
|
Python |
|
Node.js |
Step 3: Allocate a token (Java example)
package com.example.demo;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
public class Demo {
public static void main(String[] args) throws Exception {
String endpoint = "openai.edu-aliyun.com";
HttpClientBuilderParams httpsParam = new HttpClientBuilderParams();
httpsParam.setHost(endpoint);
httpsParam.setAppKey("Application AK");
httpsParam.setAppSecret("Application SK");
httpsParam.setReadTimeout(300000L);
HttpsApiClient.instance.init(httpsParam);
// token api path
String apiPath = "/scc/allocate_token";
ApiResponse apiResponse = HttpsApiClient.instance.invoke(apiPath, null);
System.out.println("Result Code:" + apiResponse.getCode());
System.out.println("Message:" + apiResponse.getMessage());
// get api token
JSONObject body = JSON.parseObject(new String(apiResponse.getBody()));
System.out.println("Token:" + ((Map<String, Object>) body.get("data")).get("apiToken"));
}
}
Step 4: Allocate a session and get the WebUI endpoint (Java example)
package com.example.demo;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class Demo {
public static void main(String[] args) throws Exception {
String endpoint = "openai.edu-aliyun.com";
HttpClientBuilderParams httpsParam = new HttpClientBuilderParams();
httpsParam.setHost(endpoint);
httpsParam.setAppKey("Application AK");
httpsParam.setAppSecret("Application SK");
httpsParam.setReadTimeout(300000L);
HttpsApiClient.instance.init(httpsParam);
// token api path
String apiPath = "/scc/spRefreshOrCreateSession";
Map<String, Object> params = new HashMap<>();
params.put("apiToken", "The allocated token");
ApiResponse apiResponse = HttpsApiClient.instance.invoke(apiPath, params);
System.out.println("Result Code:" + apiResponse.getCode());
System.out.println("Message:" + apiResponse.getMessage());
// get api token
JSONObject body = JSON.parseObject(new String(apiResponse.getBody()));
System.out.println("SD WebUI Url:" + ((Map<String, Object>) body.get("data")).get("sessionUrl"));
}
}
Open the WebUI endpoint in your browser to start creating images.
该文章对您有帮助吗?