Skip to content

Commit 07efa96

Browse files
committed
init
1 parent c701526 commit 07efa96

12 files changed

+49
-161
lines changed

env.properties

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
#export COMPARTMENT_ID="ocid1.compartment.oc1..mycompartmentvalue"
1111
#export OBJECTSTORAGE_NAMESPACE="myobjectstorenamespacename"
1212
#export OBJECTSTORAGE_BUCKETNAME="myobjectstorebucketname"
13-
#export ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE="myordsendpoint"
14-
#export ORDS_ENDPOINT_ANALYZE_AUDIO_OBJECTSTORE="myordsendpoint"
15-
#export ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL="myordsendpoint"
13+
#export ORDS_ENDPOINT_URL="myordsendpointurl"
1614
#export OCI_VISION_SERVICE_ENDPOINT="https://vision.aiservice.myregion.oci.oraclecloud.com"
1715
#export OCI_SPEECH_SERVICE_ENDPOINT="https://speech.aiservice.myregion.oci.oraclecloud.com"
18-
#export OCI_GENAI_SERVICE_ENDPOINT="https://vision.aiservice.us-chicago-1.oci.oraclecloud.com"
16+
#export OCI_GENAI_SERVICE_ENDPOINT="https://genai.aiservice.us-chicago-1.oci.oraclecloud.com"
1917

2018
## The following are only applicable when using Kubernetes...
2119
#export KUBECONFIG=~/.kube/config-mykubeconfig

sql/aiuser-tables-indexes-functions.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,27 @@ create index aivisionresultsindex on aivision_results(textfromai) indextype is c
1515
--select token_text from dr$aivisionresultsindex$i;
1616
/
1717

18+
CREATE OR REPLACE FUNCTION VISIONAI_RESULTS_TEXT_SEARCH(p_sql IN VARCHAR2) RETURN SYS_REFCURSOR AS refcursor SYS_REFCURSOR;
19+
BEGIN
20+
OPEN refcursor FOR
21+
select textfromai from AIVISION_RESULTS where contains ( textfromai, p_sql ) > 0;
22+
RETURN refcursor;
23+
END VISIONAI_RESULTS_TEXT_SEARCH;
24+
/
25+
26+
1827
BEGIN
1928
ORDS.ENABLE_OBJECT(
2029
P_ENABLED => TRUE,
2130
P_SCHEMA => 'AIUSER',
22-
P_OBJECT => 'EXECUTE_DYNAMIC_SQL',
31+
P_OBJECT => 'VISIONAI_RESULTS_TEXT_SEARCH',
2332
P_OBJECT_TYPE => 'FUNCTION',
24-
P_OBJECT_ALIAS => 'EXECUTE_DYNAMIC_SQL',
33+
P_OBJECT_ALIAS => 'VISIONAI_RESULTS_TEXT_SEARCH',
2534
P_AUTO_REST_AUTH => FALSE
2635
);
2736
COMMIT;
2837
END;
38+
/
2939

3040
--Easy Text Search over Multiple Tables and Views with DBMS_SEARCH in 23c
3141
--workshop: https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/view-workshop?wid=3721
@@ -89,8 +99,6 @@ EXCEPTION
8999
END call_analyze_image_api_objectstore;
90100
/
91101

92-
93-
94102
BEGIN
95103
ORDS.ENABLE_OBJECT(
96104
P_ENABLED => TRUE,

src/main/java/oracleai/AIApplication.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ public class AIApplication {
99
public static final String COMPARTMENT_ID = System.getenv("COMPARTMENT_ID");
1010
public static final String OBJECTSTORAGE_NAMESPACE = System.getenv("OBJECTSTORAGE_NAMESPACE");
1111
public static final String OBJECTSTORAGE_BUCKETNAME = System.getenv("OBJECTSTORAGE_BUCKETNAME");
12-
public static final String ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE = System.getenv("ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE");
13-
public static final String ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE = System.getenv("ORDS_ENDPOINT_ANALYZE_IMAGE_INLINE");
14-
public static final String ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL = System.getenv("ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL");
12+
public static final String ORDS_ENDPOINT_URL = System.getenv("ORDS_ENDPOINT_URL");
1513
public static final String OCI_VISION_SERVICE_ENDPOINT = System.getenv("OCI_VISION_SERVICE_ENDPOINT");
1614
public static final String OCI_SPEECH_SERVICE_ENDPOINT = System.getenv("OCI_SPEECH_SERVICE_ENDPOINT");
1715
public static final String OCI_GENAI_SERVICE_ENDPOINT = System.getenv("OCI_GENAI_SERVICE_ENDPOINT");
@@ -20,8 +18,7 @@ public class AIApplication {
2018
System.out.println("AIApplication.static initializer COMPARTMENT_ID:" + COMPARTMENT_ID);
2119
System.out.println("AIApplication.static initializer OBJECTSTORAGE_NAMESPACE:" + OBJECTSTORAGE_NAMESPACE);
2220
System.out.println("AIApplication.static initializer OBJECTSTORAGE_BUCKETNAME:" + OBJECTSTORAGE_BUCKETNAME);
23-
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE:" + ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE);
24-
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL:" + ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL);
21+
System.out.println("AIApplication.static initializer ORDS_ENDPOINT_URL:" + ORDS_ENDPOINT_URL);
2522
System.out.println("AIApplication.static initializer OCI_VISION_SERVICE_ENDPOINT:" + OCI_VISION_SERVICE_ENDPOINT);
2623
}
2724
public static void main(String[] args) {

src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import oracleai.services.ORDSCalls;
66
import oracleai.services.OracleGenAI;
77
import oracleai.services.OracleVisionAI;
8-
import org.jetbrains.annotations.NotNull;
98
import org.slf4j.Logger;
109
import org.slf4j.LoggerFactory;
1110
import org.springframework.stereotype.Controller;
@@ -27,11 +26,13 @@ public String analyzedoc(@RequestParam("file") MultipartFile multipartFile,
2726
log.info("analyzing image file:" + multipartFile);
2827
String concatenatedText;
2928
if (opts.equals("inline")) {
30-
String objectDetectionResults = OracleVisionAI.processImage(multipartFile.getBytes(), ImageTextDetectionFeature.builder().build());
31-
OracleVisionAI.ImageData imageData = new ObjectMapper().readValue(objectDetectionResults, OracleVisionAI.ImageData.class);
29+
String objectDetectionResults = OracleVisionAI.processImage(
30+
multipartFile.getBytes(), ImageTextDetectionFeature.builder().build());
31+
OracleVisionAI.ImageData imageData =
32+
new ObjectMapper().readValue(objectDetectionResults, OracleVisionAI.ImageData.class);
3233
concatenatedText = concatenateText(imageData);
3334
} else concatenatedText = ORDSCalls.analyzeImageInObjectStore(
34-
AIApplication.ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE,
35+
AIApplication.ORDS_ENDPOINT_URL + "call_analyze_image_api_objectstore",
3536
AIApplication.OCI_VISION_SERVICE_ENDPOINT,
3637
AIApplication.COMPARTMENT_ID,
3738
AIApplication.OBJECTSTORAGE_BUCKETNAME,

src/main/java/oracleai/TextSearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class TextSearch {
1515

1616
@PostMapping("/textsearch")
1717
public String textsearch(@RequestParam("sql") String sql, Model model) {
18-
String explanationOfResults = ORDSCalls.executeDynamicSQL(
19-
AIApplication.ORDS_ENDPOINT_EXECUTE_DYNAMIC_SQL, sql);
18+
String explanationOfResults = ORDSCalls.executeTextSearchContains(
19+
AIApplication.ORDS_ENDPOINT_URL + "VISIONAI_RESULTS_TEXT_SEARCH", sql);
2020
model.addAttribute("results", explanationOfResults);
2121
return "resultspage";
2222
}

src/main/java/oracleai/WriteAStoryAboutAPictureAndGiveItsSentiments.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public String tellastory(@RequestParam("file") MultipartFile multipartFile, @Req
3232
System.out.println("WriteAStoryAboutAPictureAndGiveItsSentiments.tellastory images = " + fullText);
3333
}
3434
else fullText = ORDSCalls.analyzeImageInObjectStore(
35-
AIApplication.ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE,
35+
AIApplication.ORDS_ENDPOINT_URL + "call_analyze_image_api_objectstore",
3636
AIApplication.OCI_VISION_SERVICE_ENDPOINT,
3737
AIApplication.COMPARTMENT_ID,
3838
AIApplication.OBJECTSTORAGE_BUCKETNAME,
@@ -42,8 +42,8 @@ public String tellastory(@RequestParam("file") MultipartFile multipartFile, @Req
4242
"TellAStory");
4343
String generatedstory = OracleGenAI.chat("using strong negative and positive sentiments, " +
4444
"write a story that is " + genopts + " and includes " + fullText );
45-
model.addAttribute("results", "STORY: " + generatedstory);
46-
model.addAttribute("results2", "SENTIMENT ANALYSIS: " + OracleLanguageAI.sentimentAnalysis(generatedstory) );
45+
model.addAttribute("results", "STORY: " + generatedstory +
46+
" --->SENTIMENT ANALYSIS: " + OracleLanguageAI.sentimentAnalysis(generatedstory) );
4747
return "resultspage";
4848
}
4949

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

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

3+
import org.jetbrains.annotations.Nullable;
34
import org.springframework.http.*;
45
import org.springframework.stereotype.Service;
56
import org.springframework.web.client.RestTemplate;
@@ -46,15 +47,21 @@ public static String analyzeImageInObjectStore(
4647
System.out.println("ORDSCalls.analyzeImageInObjectStore response.getBody():" + response.getBody());
4748
return response.getBody();
4849
}
49-
public static String executeDynamicSQL(
50-
String ordsEndpoint, String sql) {
51-
System.out.println("executeDynamicSQL ordsEndpoint = " + ordsEndpoint + ", sql = " + sql);
52-
RestTemplate restTemplate = new RestTemplate();
53-
String jsonPayload = String.format( "{\"p_sql\": \"%s\"}", sql);
50+
public static String executeTextSearchContains(String ordsEndpoint, String sql) {
51+
String jsonPayload = String.format( "{\"p_sql\": \"%s\"}", sql);
52+
return callTextSearch(ordsEndpoint, jsonPayload);
53+
}
54+
public static String executeTextSearchOR(String ordsEndpoint, String sql, String sql2) {
55+
String jsonPayload = String.format( "{\"p_sql\": \"%s\", \"p_sql\": \"%s\"}", sql, sql2);
56+
return callTextSearch(ordsEndpoint, jsonPayload);
57+
}
58+
59+
@Nullable
60+
private static String callTextSearch(String ordsEndpoint, String jsonPayload) {
5461
HttpHeaders headers = new HttpHeaders();
5562
headers.setContentType(MediaType.APPLICATION_JSON);
5663
HttpEntity<String> entity = new HttpEntity<>(jsonPayload, headers);
57-
ResponseEntity<String> response = restTemplate.exchange(ordsEndpoint, HttpMethod.POST, entity, String.class);
64+
ResponseEntity<String> response = new RestTemplate().exchange(ordsEndpoint, HttpMethod.POST, entity, String.class);
5865
System.out.println("ORDSCalls.analyzeImageInObjectStore response.getBody():" + response.getBody());
5966
return response.getBody();
6067
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public static String sentimentAnalysis(String textcontent) throws IOException {
3636
DetectLanguageSentimentsResult detectLanguageSentimentsResult = response.getDetectLanguageSentimentsResult();
3737
String sentimentReturn = "";
3838
for (SentimentAspect aspect : detectLanguageSentimentsResult.getAspects()) {
39-
sentimentReturn += "<br>sentiment:" + aspect.getSentiment();
39+
sentimentReturn += " sentiment:" + aspect.getSentiment();
4040
sentimentReturn += " text:" + aspect.getText();
41-
sentimentReturn += "\n";
41+
sentimentReturn += ", ";
4242
}
4343
return sentimentReturn;
4444
}

src/main/java/oracleai/services/OracleVisionAI.java

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -48,119 +48,11 @@ public static String processImage(byte[] bytes, ImageFeature feature) throws Exc
4848
ObjectMapper mapper = new ObjectMapper();
4949
mapper.setFilterProvider(new SimpleFilterProvider().setFailOnUnknownId(false));
5050
String json = mapper.writeValueAsString(response.getAnalyzeImageResult());
51-
// System.out.println("AnalyzeImage Result");
52-
// System.out.println(json);
5351
return json;
5452
}
5553

5654

5755
//For Text Detection....
58-
/**
59-
{
60-
"imageObjects": [
61-
{
62-
"name": "Wine Glass",
63-
"confidence": 0.9297104,
64-
"boundingPolygon": {
65-
"normalizedVertices": [
66-
{
67-
"x": 0.6124005305039788,
68-
"y": 0.02100673801030519
69-
},
70-
{
71-
"x": 0.7443633952254642,
72-
"y": 0.02100673801030519
73-
},
74-
{
75-
"x": 0.7443633952254642,
76-
"y": 0.19421323820848196
77-
},
78-
{
79-
"x": 0.6124005305039788,
80-
"y": 0.19421323820848196
81-
}
82-
]
83-
}
84-
},
85-
{
86-
"name": "Spoon",
87-
"confidence": 0.88298225,
88-
"boundingPolygon": {
89-
"normalizedVertices": [
90-
{
91-
"x": 0.6114058355437666,
92-
"y": 0.40745144669044786
93-
},
94-
{
95-
"x": 0.919761273209549,
96-
"y": 0.40745144669044786
97-
},
98-
{
99-
"x": 0.919761273209549,
100-
"y": 0.622671422909235
101-
},
102-
{
103-
"x": 0.6114058355437666,
104-
"y": 0.622671422909235
105-
}
106-
]
107-
}
108-
}
109-
],
110-
"labels": null,
111-
"ontologyClasses": [
112-
{
113-
"name": "Wine Glass",
114-
"parentNames": [
115-
"Tableware",
116-
"Glass"
117-
],
118-
"synonymNames": []
119-
},
120-
{
121-
"name": "Spoon",
122-
"parentNames": [
123-
"Tableware",
124-
"Cutlery",
125-
"Kitchen utensil"
126-
],
127-
"synonymNames": []
128-
},
129-
{
130-
"name": "Glass",
131-
"parentNames": [],
132-
"synonymNames": []
133-
},
134-
{
135-
"name": "Kitchen utensil",
136-
"parentNames": [
137-
"Kitchenware"
138-
],
139-
"synonymNames": []
140-
},
141-
{
142-
"name": "Cutlery",
143-
"parentNames": [],
144-
"synonymNames": []
145-
},
146-
{
147-
"name": "Kitchenware",
148-
"parentNames": [],
149-
"synonymNames": []
150-
}
151-
],
152-
"imageText": null,
153-
"objectProposals": null,
154-
"detectedFaces": null,
155-
"imageClassificationModelVersion": null,
156-
"objectDetectionModelVersion": "1.3.557",
157-
"textDetectionModelVersion": null,
158-
"objectProposalModelVersion": null,
159-
"faceDetectionModelVersion": null,
160-
"errors": []
161-
}
162-
*/
163-
16456
@JsonIgnoreProperties(ignoreUnknown = true)
16557
@Getter
16658
@Setter

src/main/resources/static/ObjectDetectionGenAIAndSentimentAnalysis.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h5>&nbsp; &nbsp; Uses Oracle Vision AI, Oracle Language AI, and Oracle Gen AI</
3737
<br><input type="radio" name="genopts" value="romantic">romantic
3838
<br><input type="radio" name="genopts" value="a dystopia">a dystopia
3939
<br><input type="radio" name="genopts" value="a documentary">a documentary
40-
<br><input type="radio" name="genopts" value="an anime movie">an anime movie
40+
<br><input type="radio" name="genopts" value="an anime">an anime
4141
<br> <br> <b>Options...</b>
4242
<br><input type="radio" name="opts" value="inline" checked >Process image inline (do not store image or results)
4343
<br>(makes calls to Vision AI and Gen AI directly from this application)

0 commit comments

Comments
 (0)