|
1 | 1 | package oracleai.services;
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.databind.JsonNode; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
3 | 5 | import oracleai.AIApplication;
|
4 | 6 | import oracleai.ImageStore;
|
5 | 7 | import oracleai.ImageStoreWrapper;
|
|
9 | 11 | import org.springframework.web.client.RestTemplate;
|
10 | 12 | import org.springframework.web.multipart.MultipartFile;
|
11 | 13 |
|
| 14 | +import java.io.IOException; |
12 | 15 | import java.util.Base64;
|
13 | 16 | import java.util.Collections;
|
14 | 17 | import java.util.HashMap;
|
@@ -103,5 +106,48 @@ public static ImageStore[] getImageStoreData() {
|
103 | 106 | return new ImageStore[0];
|
104 | 107 | }
|
105 | 108 | }
|
| 109 | + |
| 110 | + public static ImageStore[] make3Drequest() { |
| 111 | + String url = AIApplication.ORDS_ENDPOINT_URL + "image_store/"; |
| 112 | + RestTemplate restTemplate = new RestTemplate(); |
| 113 | + ResponseEntity<ImageStoreWrapper> response = restTemplate.getForEntity(url, ImageStoreWrapper.class); |
| 114 | + ImageStoreWrapper wrapper = response.getBody(); |
| 115 | + if (wrapper != null) { |
| 116 | + for (ImageStore imageStore : wrapper.getItems()) { |
| 117 | + System.out.println("Image Name: " + imageStore.getImageName()); |
| 118 | + } |
| 119 | + return wrapper.getItems().toArray(new ImageStore[0]); |
| 120 | + } else { |
| 121 | + return new ImageStore[0]; |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + public static String convertImage() { |
| 126 | + String apiUrl = "https://api.meshy.ai/v1/image-to-3d"; |
| 127 | + RestTemplate restTemplate = new RestTemplate(); |
| 128 | + HttpHeaders headers = new HttpHeaders(); |
| 129 | + headers.setContentType(MediaType.APPLICATION_JSON); |
| 130 | + headers.set("Authorization", "Bearer " + AIApplication.THREEDEY); |
| 131 | + String requestJson = |
| 132 | + "{\"image_url\": \"https://upload.wikimedia.org/wikipedia/commons/e/e1/Face_%E2%80%93_Alexander.jpg\", " + |
| 133 | + "\"enable_pbr\": true, \"surface_mode\": \"hard\"}"; |
| 134 | + HttpEntity<String> entity = new HttpEntity<>(requestJson, headers); |
| 135 | + ResponseEntity<String> response = restTemplate.postForEntity(apiUrl, entity, String.class); |
| 136 | + ObjectMapper mapper = new ObjectMapper(); |
| 137 | + try { |
| 138 | + JsonNode root = mapper.readTree(response.getBody()); |
| 139 | + return root.path("result").asText(); // Return the result value |
| 140 | + } catch (IOException e) { |
| 141 | + e.printStackTrace(); |
| 142 | + return "Error parsing JSON"; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | +
|
| 148 | + curl https://api.meshy.ai/v1/image-to-3d/01917ce6-09a1-7bf6-8240-ff5d77f01d97 \ |
| 149 | + -H "Authorization: Bearer msy_oCS1X5nuRxS06AjdlTJ0vCHg3OFyOhpaCMoa" |
| 150 | +
|
| 151 | + */ |
106 | 152 | }
|
107 | 153 |
|
0 commit comments