Skip to content

Commit c701526

Browse files
committed
init
1 parent b5ce3c1 commit c701526

8 files changed

+50
-59
lines changed

sql/aiuser-tables-indexes-functions.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ EXCEPTION
8989
END call_analyze_image_api_objectstore;
9090
/
9191

92+
93+
9294
BEGIN
9395
ORDS.ENABLE_OBJECT(
9496
P_ENABLED => TRUE,

src/main/java/oracleai/ExplainAndAdviseOnHealthTestResults.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ public String analyzedoc(@RequestParam("file") MultipartFile multipartFile,
2525
@RequestParam("opts") String opts, Model model)
2626
throws Exception {
2727
log.info("analyzing image file:" + multipartFile);
28-
if (opts.equals("inline")) return analyzedocInline(multipartFile, model);
29-
else return analyzeDocObjectStorage(multipartFile, model);
30-
}
31-
32-
@NotNull
33-
private static String analyzeDocObjectStorage(MultipartFile multipartFile, Model model) throws Exception {
34-
// OracleObjectStore.sendToObjectStorage(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
35-
String objectDetectionResults = ORDSCalls.analyzeImageInObjectStore(
28+
String concatenatedText;
29+
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);
32+
concatenatedText = concatenateText(imageData);
33+
} else concatenatedText = ORDSCalls.analyzeImageInObjectStore(
3634
AIApplication.ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE,
3735
AIApplication.OCI_VISION_SERVICE_ENDPOINT,
3836
AIApplication.COMPARTMENT_ID,
@@ -41,33 +39,13 @@ private static String analyzeDocObjectStorage(MultipartFile multipartFile, Model
4139
multipartFile.getOriginalFilename(), //"objectdetectiontestimage.jpg"
4240
"TEXT_DETECTION",
4341
"MedicalReportSummary");
44-
ObjectMapper mapper = new ObjectMapper();
45-
OracleVisionAI.ImageData imageData = mapper.readValue(objectDetectionResults, OracleVisionAI.ImageData.class);
46-
String concatenatedText = concatenateText(imageData);
47-
System.out.println(concatenatedText);
48-
log.info("fullText = " + concatenatedText);
49-
String explanationOfResults =
50-
OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
51-
"and tell me what should I do to get better results: \"" + concatenatedText + "\"");
52-
System.out.println("ExplainAndAdviseOnHealthTestResults.analyzedoc explanationOfResults:" + explanationOfResults);
53-
model.addAttribute("results", explanationOfResults);
54-
return "resultspage";
55-
}
56-
57-
public String analyzedocInline(MultipartFile file, Model model)
58-
throws Exception {
59-
log.info("analyzing image file:" + file);
60-
String objectDetectionResults = OracleVisionAI.processImage(file.getBytes(), ImageTextDetectionFeature.builder().build());
61-
ObjectMapper mapper = new ObjectMapper();
62-
OracleVisionAI.ImageData imageData = mapper.readValue(objectDetectionResults, OracleVisionAI.ImageData.class);
63-
String concatenatedText = concatenateText(imageData);
6442
System.out.println(concatenatedText);
6543
log.info("fullText = " + concatenatedText);
6644
String explanationOfResults =
6745
OracleGenAI.chat("explain these test results in simple terms, in less than 100 words, " +
6846
"and tell me what should I do to get better results: \"" + concatenatedText + "\"");
6947
System.out.println("ExplainAndAdviseOnHealthTestResults.analyzedoc explanationOfResults:" + explanationOfResults);
70-
model.addAttribute("results", explanationOfResults);
48+
model.addAttribute("results", "SUMMARY WITH ADVICE: " + explanationOfResults);
7149
return "resultspage";
7250
}
7351

src/main/java/oracleai/GenerateAPictureStoryUsingOnlySpeech.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public String reset(Model model) {
2626
}
2727

2828
@GetMapping("/picturestory")
29-
public String picturestory(@RequestParam("genopts") String genopts, MultipartFile multipartFile, Model model) throws Exception {
29+
public String picturestory(@RequestParam("genopts") String genopts,
30+
MultipartFile multipartFile, Model model) throws Exception {
3031
OracleObjectStore.sendToObjectStorage(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
3132
String transcriptionJobId = OracleSpeechAI.getTranscriptFromOCISpeech(multipartFile.getOriginalFilename()); //json file
3233
// String transcriptionJobId = getTranscriptFromOCISpeech("testing123.wav");

src/main/java/oracleai/WriteAStoryAboutAPictureAndGiveItsSentiments.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,32 @@
66
import oracleai.services.OracleGenAI;
77
import oracleai.services.OracleLanguageAI;
88
import oracleai.services.OracleVisionAI;
9+
import org.springframework.stereotype.Controller;
910
import org.springframework.web.bind.annotation.*;
1011
import org.springframework.web.multipart.MultipartFile;
1112
import org.springframework.ui.Model;
1213

13-
@RestController
14+
@Controller
1415
@RequestMapping("/tellastory")
1516
public class WriteAStoryAboutAPictureAndGiveItsSentiments {
1617

1718
@PostMapping("/tellastory")
18-
public String tellastory(@RequestParam("file") MultipartFile multipartFile ,
19+
public String tellastory(@RequestParam("file") MultipartFile multipartFile, @RequestParam("opts") String opts,
1920
@RequestParam("genopts") String genopts, Model model)
2021
throws Exception {
2122
System.out.println("WriteAStoryAboutAPictureAndGiveItsSentiments.tellastory file = " +
2223
multipartFile.getOriginalFilename());
23-
String objectDetectionResults;
24-
if(genopts.equals("inline")) objectDetectionResults =
25-
OracleVisionAI.processImage(multipartFile.getBytes(),
26-
ImageObjectDetectionFeature.builder().maxResults(10).build());
27-
else objectDetectionResults = ORDSCalls.analyzeImageInObjectStore(
24+
String fullText = "";
25+
if(opts.equals("inline")) {
26+
String objectDetectionResults =
27+
OracleVisionAI.processImage(multipartFile.getBytes(),
28+
ImageObjectDetectionFeature.builder().maxResults(10).build());
29+
OracleVisionAI.ImageAnalysisResult imageAnalysis =
30+
new ObjectMapper().readValue(objectDetectionResults, OracleVisionAI.ImageAnalysisResult.class);
31+
for (OracleVisionAI.ImageObject image : imageAnalysis.getImageObjects()) fullText += image.getName() + ", ";
32+
System.out.println("WriteAStoryAboutAPictureAndGiveItsSentiments.tellastory images = " + fullText);
33+
}
34+
else fullText = ORDSCalls.analyzeImageInObjectStore(
2835
AIApplication.ORDS_ENDPOINT_ANALYZE_IMAGE_OBJECTSTORE,
2936
AIApplication.OCI_VISION_SERVICE_ENDPOINT,
3037
AIApplication.COMPARTMENT_ID,
@@ -33,17 +40,10 @@ public String tellastory(@RequestParam("file") MultipartFile multipartFile ,
3340
multipartFile.getOriginalFilename(), //"objectdetectiontestimage.jpg"
3441
"OBJECT_DETECTION",
3542
"TellAStory");
36-
ObjectMapper mapper = new ObjectMapper();
37-
OracleVisionAI.ImageAnalysisResult imageAnalysis =
38-
mapper.readValue(objectDetectionResults, OracleVisionAI.ImageAnalysisResult.class);
39-
String fullText = "";
40-
for (OracleVisionAI.ImageObject image : imageAnalysis.getImageObjects()) fullText += image.getName() + ", ";
41-
System.out.println("WriteAStoryAboutAPictureAndGiveItsSentiments.tellastory images = " + fullText);
42-
String generatedstory =
43-
OracleGenAI.chat("using strong negative and positive sentiments, " +
43+
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-
"<br><br>sentiment analysis:" + OracleLanguageAI.sentimentAnalysis(generatedstory) );
45+
model.addAttribute("results", "STORY: " + generatedstory);
46+
model.addAttribute("results2", "SENTIMENT ANALYSIS: " + OracleLanguageAI.sentimentAnalysis(generatedstory) );
4747
return "resultspage";
4848
}
4949

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static class ImageObject {
205205
@JsonIgnoreProperties(ignoreUnknown = true)
206206
@Getter
207207
@Setter
208-
public class BoundingPolygon {
208+
public static class BoundingPolygon {
209209
private List<Vertex> normalizedVertices;
210210
}
211211

src/main/resources/static/ObjectDetectionGenAIAndSentimentAnalysis.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ <h5>&nbsp; &nbsp; Uses Oracle Vision AI, Oracle Language AI, and Oracle Gen AI</
3232
<input type="file" name="file" accept="image/*">
3333
<br>(You can download and use the sample image found <a href="images/objectdetectiontestimage.jpg">here</a>)
3434
<br>
35-
<br><b>Options...</b>
35+
<br><b>Options for story generation...</b>
3636
<br><input type="radio" name="genopts" value="an adventure" checked >an adventure
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
4040
<br><input type="radio" name="genopts" value="an anime movie">an anime movie
41-
<br><input type="submit" value="Submit">
41+
<br> <br> <b>Options...</b>
42+
<br><input type="radio" name="opts" value="inline" checked >Process image inline (do not store image or results)
43+
<br>(makes calls to Vision AI and Gen AI directly from this application)
44+
<br>
45+
<br><input type="radio" name="opts" value="objectstore">Store image in objectstore and summary text results in database
46+
<br>(makes calls to Vision AI and Gen AI from the Oracle Database using DBMS_CLOUD)
47+
<br><br><input type="submit" value="Submit">
48+
<br>
4249
</form>
4350
</div>
4451

src/main/resources/static/TextSearch.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ <h5>Uses Oracle Text Indexing Searches (and in 23c DBMS_SEARCH multi-table searc
3232
<form method="post" action="/textsearch/textsearch" enctype="multipart/form-data">
3333
Enter SQL for text search...
3434
<br>
35-
<textarea name="sql" rows="3" cols="60">select jsondata from aivision_results
35+
<textarea name="sql" rows="3" cols="60">select textfromai from AIVISION_RESULTS where contains ( textfromai, 'Wine' ) > 0
3636
</textarea>
3737
<br><b>Examples...</b>
3838
<br>CONTAINS operator
39-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where contains ( jsondata, 'john' ) > 0
39+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where contains ( textfromai, 'john' ) > 0
4040
<br>Mixed Queries
41-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where amount < 100 and contains ( jsondata, 'smith' ) > 0
41+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where amount < 100 and contains ( textfromai, 'smith' ) > 0
4242
<br>OR search
43-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where contains ( jsondata, 'john OR johnny' ) > 0
43+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where contains ( textfromai, 'john OR johnny' ) > 0
4444
<br>Wildcards (% matches any string of characters, and an underscore _ character matches any single character)
45-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where contains ( jsondata, 'john%' ) > 0
45+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where contains ( textfromai, 'john%' ) > 0
4646
<br>Phrase searches (an AND search similar to OR but implicit)
47-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where contains ( jsondata, 'first order' ) > 0
47+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where contains ( textfromai, 'first order' ) > 0
4848
<br>Fuzzy searches (find not only the original search word, but also all those similar to it)
49-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where contains ( jsondata, 'fuzzy(popins)' ) > 0
49+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where contains ( textfromai, 'fuzzy(popins)' ) > 0
5050
<br>Near searches (words within specified distance of each other)
51-
<br>&nbsp;&nbsp;&nbsp;&nbsp;select jsondata from aivision_results where contains ( jsondata, 'near((order, smith), 1)' ) > 0
51+
<br>&nbsp;&nbsp;&nbsp;&nbsp;select textfromai from aivision_results where contains ( textfromai, 'near((order, smith), 1)' ) > 0
5252
<br>
5353
<br><input type="submit" value="Submit"><br>
5454
</form>

src/main/resources/templates/resultspage.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ <h2>Develop with Oracle AI Services and Oracle Database</h2>
2626
</div>
2727

2828
<div class="w3-container">
29-
<span th:text="'Summary with advice:' + ${results}"></span>
29+
<span th:text="'' + ${results}"></span>
30+
<br>
31+
<br>
32+
<span th:text="'' + ${results2}"></span>
3033
</div>
3134

3235
</div>

0 commit comments

Comments
 (0)