调用文心一言画画
@Slf4j @Controller @RequestMapping("/wenxin") public class WenxinController { @RequestMapping("/draw") public String draw(Model model){ log.info("sdfsdfs"); String token="24.2592000.1706433751.282335-43397279"; String api="https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/text2image/sd_xl?access_token="+token; Map<String,Object> param=new HashMap<>(); param.put("prompt","画一幅画,有黄色的百合花、蓝色的绣球花"); param.put("negative_prompt","绿色"); param.put("size","768x1024"); param.put("steps",20); param.put("n",2); param.put("sampler_index","DPM++ SDE Karras"); String result=HttpUtil.post(api, JSONUtil.toJsonStr(param)); JSONObject jsonObject = JSONUtil.parseObj(result); if(jsonObject.containsKey("data")){ JSONArray arr = jsonObject.getJSONArray("data"); if(arr.size()>0){ JSONObject img = arr.getJSONObject(0); if(img.containsKey("b64_image")){ model.addAttribute("src","data:image/png;base64,"+img.getStr("b64_image")); return "wenxin/draw.html"; } } } log.error(result); model.addAttribute("src","data:image/png;base64,"); return "wenxin/draw.html"; } }