|
|
@ -11,6 +11,7 @@ import com.bnyer.common.core.utils.file.Base64ToMultipartFileUtils; |
|
|
import com.bnyer.common.core.vo.TextToImgVo; |
|
|
import com.bnyer.common.core.vo.TextToImgVo; |
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
import com.bnyer.common.redis.service.RedisService; |
|
|
import com.bnyer.file.api.RemoteFileService; |
|
|
import com.bnyer.file.api.RemoteFileService; |
|
|
|
|
|
import com.bnyer.img.config.StableDiffusionConfig; |
|
|
import com.bnyer.img.config.TencentTranslateConfig; |
|
|
import com.bnyer.img.config.TencentTranslateConfig; |
|
|
import com.bnyer.img.service.AiPaintService; |
|
|
import com.bnyer.img.service.AiPaintService; |
|
|
import com.bnyer.img.service.StableDiffusionService; |
|
|
import com.bnyer.img.service.StableDiffusionService; |
|
|
@ -52,6 +53,9 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private TencentTranslateConfig tencentTranslateConfig; |
|
|
private TencentTranslateConfig tencentTranslateConfig; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private StableDiffusionConfig stableDiffusionConfig; |
|
|
|
|
|
|
|
|
private String translate(String text){ |
|
|
private String translate(String text){ |
|
|
try{ |
|
|
try{ |
|
|
Credential cred = new Credential(tencentTranslateConfig.getSecretId(), tencentTranslateConfig.getSecretKey()); |
|
|
Credential cred = new Credential(tencentTranslateConfig.getSecretId(), tencentTranslateConfig.getSecretKey()); |
|
|
@ -71,6 +75,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
req.setProjectId(Long.parseLong(tencentTranslateConfig.getProjectId())); |
|
|
req.setProjectId(Long.parseLong(tencentTranslateConfig.getProjectId())); |
|
|
// 返回的resp是一个TextTranslateResponse的实例,与请求对象对应
|
|
|
// 返回的resp是一个TextTranslateResponse的实例,与请求对象对应
|
|
|
TextTranslateResponse resp = client.TextTranslate(req); |
|
|
TextTranslateResponse resp = client.TextTranslate(req); |
|
|
|
|
|
log.info("翻译后的文本为:【{}】",JSON.toJSONString(resp.getTargetText())); |
|
|
return resp.getTargetText(); |
|
|
return resp.getTargetText(); |
|
|
} catch (TencentCloudSDKException e) { |
|
|
} catch (TencentCloudSDKException e) { |
|
|
log.error("调用腾讯api失败"+e.toString()); |
|
|
log.error("调用腾讯api失败"+e.toString()); |
|
|
@ -106,10 +111,10 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { |
|
|
map.put("sampler_index","DPM++ 2S a Karras"); |
|
|
map.put("sampler_index","DPM++ 2S a Karras"); |
|
|
//map.put("sampler_index",param.getSamplerIndex());
|
|
|
//map.put("sampler_index",param.getSamplerIndex());
|
|
|
map.put("steps",25); |
|
|
map.put("steps",25); |
|
|
map.put("negative_prompt","nsfw"); |
|
|
map.put("negative_prompt","easynegative"); |
|
|
log.info("请求stable_diffusion请求体为:【{}】", JSON.toJSONString(map)); |
|
|
//log.info("请求stable_diffusion请求体为:【{}】", JSON.toJSONString(map));
|
|
|
JSONObject jsonObject = restTemplate.postForObject("http://localhost:7860/sdapi/v1/txt2img", map, JSONObject.class); |
|
|
JSONObject jsonObject = restTemplate.postForObject(stableDiffusionConfig.getTxt2ImgUrl(), map, JSONObject.class); |
|
|
log.info("请求stable_diffusion响应体的为:【{}】", JSON.toJSONString(jsonObject)); |
|
|
//log.info("请求stable_diffusion响应体的为:【{}】", JSON.toJSONString(jsonObject));
|
|
|
TextToImgVo img = new TextToImgVo(); |
|
|
TextToImgVo img = new TextToImgVo(); |
|
|
if(jsonObject != null && jsonObject.getJSONArray("images").size() > 0){ |
|
|
if(jsonObject != null && jsonObject.getJSONArray("images").size() > 0){ |
|
|
List<String> images = jsonObject.getJSONArray("images").toJavaList(String.class); |
|
|
List<String> images = jsonObject.getJSONArray("images").toJavaList(String.class); |
|
|
|