-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathImageSynthesisUsage.java
More file actions
72 lines (64 loc) · 2.82 KB
/
ImageSynthesisUsage.java
File metadata and controls
72 lines (64 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) Alibaba, Inc. and its affiliates.
import java.util.ArrayList;
import java.util.Arrays;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
public class ImageSynthesisUsage {
public static void basicCall() throws ApiException, NoApiKeyException {
// create with image2image, 参考文档(image2image|text2image)
ImageSynthesis is = new ImageSynthesis();
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.model(ImageSynthesis.Models.WANX_2_1_IMAGEEDIT)
.size("1024*1024")
.prompt("帮我编辑图片。把所选区域变成黑色")
.baseImageUrl("https://static.dingtalk.com/media/lQLPD2jl0mg85BvNBADNAkCwNJvjWJXBVMwHqrO0OvZlAA_576_1024.png_620x10000q90.png")
.maskImageUrl("https://static.dingtalk.com/media/lQLPD2ob9dfKPBvNBADNAkCwOcPjjaFVcEcHqrO8n1BLAA_576_1024.png_620x10000q90.png")
.function(ImageSynthesis.ImageEditFunction.DESCRIPTION_EDIT_WITH_MASK)
.build();
ImageSynthesisResult result = is.call(param);
System.out.println(result);
}
public static void synCall() throws ApiException, NoApiKeyException {
ImageSynthesis is = new ImageSynthesis();
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.model("wan2.2-t2i-flash")
.prompt("一直森林中的白色的猫")
.n(1)
.promptExtend(false)
.watermark(true)
.build();
ImageSynthesisResult result = is.syncCall(param);
System.out.println(result);
}
public static void listTask() throws ApiException, NoApiKeyException {
ImageSynthesis is = new ImageSynthesis();
AsyncTaskListParam param = AsyncTaskListParam.builder().build();
ImageSynthesisListResult result = is.list(param);
System.out.println(result);
}
public void fetchTask() throws ApiException, NoApiKeyException {
String taskId = "your task id";
ImageSynthesis is = new ImageSynthesis();
// If set DASHSCOPE_API_KEY environment variable, apiKey can null.
ImageSynthesisResult result = is.fetch(taskId, null);
System.out.println(result.getOutput());
System.out.println(result.getUsage());
}
public static void main(String[] args){
try{
// basicCall();
synCall();
//listTask();
}catch(ApiException|NoApiKeyException e){
System.out.println(e.getMessage());
}
System.exit(0);
}
}