Skip to content

Commit

Permalink
feat: update image example
Browse files Browse the repository at this point in the history
Signed-off-by: yuluo-yx <yuluo08290126@gmail.com>
  • Loading branch information
yuluo-yx committed Oct 7, 2024
1 parent e355581 commit 6cb68d7
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,27 @@ public class ImageModelController {
this.imageModel = imageModel;
}

@RequestMapping("/image")
public String image(String input) {
@GetMapping("/image/{input}")
public void image(@PathVariable("input") String input, HttpServletResponse response) {

ImageOptions options = ImageOptionsBuilder.builder()
.withModel("wanx-v1")
.build();

ImagePrompt imagePrompt = new ImagePrompt(input, options);
ImageResponse response = imageModel.call(imagePrompt);
String imageUrl = response.getResult().getOutput().getUrl();

return "redirect:" + imageUrl;
ImageResponse imageResponse = imageModel.call(imagePrompt);
String imageUrl = imageResponse.getResult().getOutput().getUrl();

try {
URL url = new URL(imageUrl);
InputStream in = url.openStream();

response.setHeader("Content-Type", MediaType.IMAGE_PNG_VALUE);
response.getOutputStream().write(in.readAllBytes());
response.getOutputStream().flush();
} catch (IOException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}

}

0 comments on commit 6cb68d7

Please sign in to comment.