Skip to content

Commit 6bac439

Browse files
authored
Merge pull request #17 from paulparkinson/main
init for oracle-ai-for-sustainable-dev workshop part 2
2 parents c8a75a9 + e55f47b commit 6bac439

21 files changed

+312
-67
lines changed

build_and_run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#source ~/Downloads/env.properties
44
source env.properties
55

6-
mvn clean package ; java -Djava.security.debug="access,failure" -jar target/oracleai-0.0.1-SNAPSHOT.jar
6+
mvn clean package ; java -Djava.security.debug="access,failure" -jar target/oracleai-0.0.1-SNAPSHOT.jar

pom.xml

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@
9191
<artifactId>oci-java-sdk-ailanguage</artifactId>
9292
<version>${oci.sdk.version}</version>
9393
</dependency>
94-
<!-- <dependency>-->
95-
<!-- <groupId>com.oracle.oci.sdk</groupId>-->
96-
<!-- <artifactId>oci-java-sdk-streaming</artifactId>-->
97-
<!-- <version>${oci.sdk.version}</version>-->
98-
<!-- </dependency>-->
9994
<dependency>
10095
<groupId>com.oracle.oci.sdk</groupId>
10196
<artifactId>oci-java-sdk-objectstorage</artifactId>
@@ -112,31 +107,31 @@
112107
<artifactId>spring-boot-starter-web</artifactId>
113108
<version>${spring.boot.version}</version>
114109
</dependency>
115-
<dependency>
116-
<groupId>com.oracle.database.jdbc</groupId>
117-
<artifactId>ojdbc8</artifactId>
118-
<version>${oracle.jdbc.version}</version>
119-
</dependency>
120-
<dependency>
121-
<groupId>com.oracle.database.jdbc</groupId>
122-
<artifactId>ucp</artifactId>
123-
<version>${oracle.jdbc.version}</version>
124-
</dependency>
125-
<dependency>
126-
<groupId>com.oracle.database.security</groupId>
127-
<artifactId>oraclepki</artifactId>
128-
<version>${oracle.jdbc.version}</version>
129-
</dependency>
130-
<dependency>
131-
<groupId>com.oracle.database.security</groupId>
132-
<artifactId>osdt_core</artifactId>
133-
<version>${oracle.jdbc.version}</version>
134-
</dependency>
135-
<dependency>
136-
<groupId>com.oracle.database.security</groupId>
137-
<artifactId>osdt_cert</artifactId>
138-
<version>${oracle.jdbc.version}</version>
139-
</dependency>
110+
<!-- <dependency>-->
111+
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
112+
<!-- <artifactId>ojdbc8</artifactId>-->
113+
<!-- <version>${oracle.jdbc.version}</version>-->
114+
<!-- </dependency>-->
115+
<!-- <dependency>-->
116+
<!-- <groupId>com.oracle.database.jdbc</groupId>-->
117+
<!-- <artifactId>ucp</artifactId>-->
118+
<!-- <version>${oracle.jdbc.version}</version>-->
119+
<!-- </dependency>-->
120+
<!-- <dependency>-->
121+
<!-- <groupId>com.oracle.database.security</groupId>-->
122+
<!-- <artifactId>oraclepki</artifactId>-->
123+
<!-- <version>${oracle.jdbc.version}</version>-->
124+
<!-- </dependency>-->
125+
<!-- <dependency>-->
126+
<!-- <groupId>com.oracle.database.security</groupId>-->
127+
<!-- <artifactId>osdt_core</artifactId>-->
128+
<!-- <version>${oracle.jdbc.version}</version>-->
129+
<!-- </dependency>-->
130+
<!-- <dependency>-->
131+
<!-- <groupId>com.oracle.database.security</groupId>-->
132+
<!-- <artifactId>osdt_cert</artifactId>-->
133+
<!-- <version>${oracle.jdbc.version}</version>-->
134+
<!-- </dependency>-->
140135
<dependency>
141136
<groupId>org.springframework.boot</groupId>
142137
<artifactId>spring-boot-starter-test</artifactId>

src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
@RequestMapping("/health")
1919
public class ExplainAndAdviseOnHealthTestResults {
2020

21-
private static Logger log = LoggerFactory.getLogger(ExplainAndAdviseOnHealthTestResults.class);
2221

2322
@PostMapping("/analyzedoc")
2423
public String analyzedoc(@RequestParam("file") MultipartFile multipartFile,
2524
@RequestParam("opts") String opts, Model model)
2625
throws Exception {
27-
log.info("analyzing image file:" + multipartFile);
26+
System.out.println("analyzedocmultipartFile = " + multipartFile + ", opts = " + opts);
2827
String concatenatedText;
2928
if (opts.equals("inline")) {
3029
String objectDetectionResults = OracleVisionAI.processImage(
@@ -45,7 +44,7 @@ public String analyzedoc(@RequestParam("file") MultipartFile multipartFile,
4544
"MedicalReportSummary");
4645
}
4746
System.out.println(concatenatedText);
48-
log.info("fullText = " + concatenatedText);
47+
System.out.println("analyzedoc fullText = " + concatenatedText);
4948
String explanationOfResults =
5049
OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
5150
"and tell me what should I do to get better results: \"" + concatenatedText + "\"");

src/main/java/oracleai/FaceRecognition.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package oracleai;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
3+
import com.oracle.bmc.aivision.model.FaceDetectionFeature;
4+
import oracleai.services.OracleVisionAI;
55
import org.springframework.stereotype.Controller;
66
import org.springframework.ui.Model;
77
import org.springframework.web.bind.annotation.PostMapping;
@@ -14,12 +14,12 @@
1414
@RequestMapping("/facerecognition")
1515
public class FaceRecognition {
1616

17-
private static Logger log = LoggerFactory.getLogger(ExplainAndAdviseOnHealthTestResults.class);
1817

1918
@PostMapping("/facerecognition")
2019
public String facerecognition(@RequestParam("file") MultipartFile multipartFile, Model model)
2120
throws Exception {
22-
model.addAttribute("results", "facerecognition");
21+
model.addAttribute("results",
22+
OracleVisionAI.processImage(multipartFile.getBytes(), FaceDetectionFeature.builder().shouldReturnLandmarks(true).build()));
2323
return "resultspage";
2424
}
2525
}

src/main/java/oracleai/GenerateAPictureStoryUsingOnlySpeech.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ public String reset(Model model) {
2525
return "resultspage";
2626
}
2727

28-
@GetMapping("/picturestory")
28+
@PostMapping("/picturestory")
2929
public String picturestory(@RequestParam("genopts") String genopts,
30-
MultipartFile multipartFile, Model model) throws Exception {
30+
@RequestParam("file") MultipartFile multipartFile, Model model) throws Exception {
3131
OracleObjectStore.sendToObjectStorage(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
32-
String transcriptionJobId = OracleSpeechAI.getTranscriptFromOCISpeech(multipartFile.getOriginalFilename()); //json file
33-
// String transcriptionJobId = getTranscriptFromOCISpeech("testing123.wav");
32+
String transcriptionJobId = OracleSpeechAI.getTranscriptFromOCISpeech(multipartFile.getOriginalFilename());
3433
System.out.println("transcriptionJobId: " + transcriptionJobId);
3534
String jsonTranscriptFromObjectStorage =
3635
OracleObjectStore.getFromObjectStorage(transcriptionJobId,
37-
// AIApplication.OBJECTSTORAGE_NAMESPACE + "_" + AIApplication.OBJECTSTORAGE_BUCKETNAME + "_" + "testing123.wav" + ".json"));
3836
AIApplication.OBJECTSTORAGE_NAMESPACE + "_" + AIApplication.OBJECTSTORAGE_BUCKETNAME + "_" + multipartFile.getOriginalFilename() + ".json");
3937
System.out.println("jsonTranscriptFromObjectStorage: " + jsonTranscriptFromObjectStorage);
4038
// System.out.println("getFromObjectStorage: " + getFromObjectStorage("leia.m4a"));

src/main/java/oracleai/services/ORDSCalls.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static String callAnalyzeImageInline(String ordsEndpoint, String visionSe
2727
}
2828

2929

30-
//As written only supports on feature type per call
30+
//As written only supports one feature type per call
3131
public static String analyzeImageInObjectStore(
3232
String ordsEndpoint, String visionServiceEndpoint, String compartmentOcid,
3333
String bucketName, String namespaceName, String objectName, String featureType, String label) {

src/main/java/oracleai/services/OracleGenAI.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.oracle.bmc.Region;
44
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
5-
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
6-
import com.oracle.bmc.auth.InstancePrincipalsAuthenticationDetailsProvider;
75
import com.oracle.bmc.generativeai.GenerativeAiClient;
86
import com.oracle.bmc.generativeai.model.GenerateTextDetails;
97
import com.oracle.bmc.generativeai.model.GenerateTextResult;

src/main/java/oracleai/services/OracleLanguageAI.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import com.oracle.bmc.ailanguage.model.SentimentAspect;
77
import com.oracle.bmc.ailanguage.requests.DetectLanguageSentimentsRequest;
88
import com.oracle.bmc.ailanguage.responses.DetectLanguageSentimentsResponse;
9-
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
10-
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
119
import com.oracle.bmc.model.BmcException;
1210

1311
import java.io.IOException;

src/main/java/oracleai/services/OracleSpeechAI.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package oracleai.services;
22

3-
import com.oracle.bmc.Region;
43
import com.oracle.bmc.aispeech.AIServiceSpeechClient;
54
import com.oracle.bmc.aispeech.model.*;
65
import com.oracle.bmc.aispeech.requests.CreateTranscriptionJobRequest;
@@ -16,7 +15,7 @@
1615

1716
public class OracleSpeechAI {
1817

19-
public static String getTranscriptFromOCISpeech(String fileName) throws IOException {
18+
public static String getTranscriptFromOCISpeech(String fileName) throws IOException, InterruptedException {
2019
AuthenticationDetailsProvider provider = AuthProvider.getAuthenticationDetailsProvider();
2120
AIServiceSpeechClient client =
2221
AIServiceSpeechClient.builder().build(provider);
@@ -71,16 +70,21 @@ public static String getTranscriptFromOCISpeech(String fileName) throws IOExcept
7170
.build();
7271
GetTranscriptionJobResponse getTranscriptionJobResponseresponse = null;
7372
TranscriptionJob.LifecycleState transcriptJobState = null;
73+
TranscriptionJob.LifecycleState lastState;
7474
while (
7575
transcriptJobState == null ||
7676
(
7777
!transcriptJobState.equals(TranscriptionJob.LifecycleState.Succeeded) &&
78+
!transcriptJobState.equals(TranscriptionJob.LifecycleState.Canceling) &&
7879
!transcriptJobState.equals(TranscriptionJob.LifecycleState.Canceled) &&
7980
!transcriptJobState.equals(TranscriptionJob.LifecycleState.Failed))
8081
) {
82+
Thread.currentThread().sleep(1000);
83+
lastState = transcriptJobState;
8184
getTranscriptionJobResponseresponse =
8285
client.getTranscriptionJob(getTranscriptionJobRequest);
8386
transcriptJobState = getTranscriptionJobResponseresponse.getTranscriptionJob().getLifecycleState();
87+
if(lastState != null && lastState.equals(transcriptJobState)) System.out.print(".");
8488
System.out.println("transcriptJobState:" + transcriptJobState);
8589
}
8690
System.out.println("getInputLocation:" +

src/main/resources/static/FaceRecognition.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ <h2>Develop with Oracle AI Services and Oracle Database</h2>
2424
</div>
2525

2626
<div class="w3-container">
27-
<h3>Obtain facial recognition information using Oracle Vision AI Document</h3>
27+
28+
<h4>Obtain facial recognition information</h4>
2829
<br>
29-
<h4>Provide a picture containing faces and receive a return of the faces recognized and location of various facial features.</h4>
30+
<h5>Provide a picture containing faces and receive a return of the faces recognized and location of various facial features.</h5>
31+
<h5>Uses Oracle Vision AI</h5>
3032
<br>
3133
<form method="post" action="/facerecognition/facerecognition" enctype="multipart/form-data">
3234
Select an image file to conduct face recognition upon...<br>
3335
<input type="file" name="file" accept="image/*" />
34-
<br>You can use the sample image found <a href="images/faces.jpeg">here</a>
36+
<br>You can use the sample image found <a href="images/faces.png">here</a>
3537
<br>
3638
<br>
3739
<br><input type="submit" value="Submit"><br>

0 commit comments

Comments
 (0)