Skip to content

Commit b5ce3c1

Browse files
committed
init
1 parent 5b39752 commit b5ce3c1

File tree

3 files changed

+122
-38
lines changed

3 files changed

+122
-38
lines changed

sql/aiuser-tables-indexes-functions.sql

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,15 @@ CREATE TABLE aivision_results
44
(id RAW (16) NOT NULL,
55
date_loaded TIMESTAMP WITH TIME ZONE,
66
label varchar2(20),
7+
textfromai varchar2(32767),
78
jsondata CLOB
89
CONSTRAINT ensure_aivision_results_json CHECK (jsondata IS JSON));
9-
create index aivisionresultsindex on aivision_results(jsondata) indextype is ctxsys.context;
10+
/
11+
12+
create index aivisionresultsindex on aivision_results(textfromai) indextype is ctxsys.context;
1013
--select index_name, index_type, status from user_indexes where index_name = 'AIVISIONAIRESULTSINDEX';
1114
--select idx_name, idx_table, idx_text_name from ctx_user_indexes;
1215
--select token_text from dr$aivisionresultsindex$i;
13-
14-
15-
CREATE TABLE aispeech_results
16-
(id RAW (16) NOT NULL,
17-
date_loaded TIMESTAMP WITH TIME ZONE,
18-
label varchar2(20),
19-
jsondata CLOB
20-
CONSTRAINT aispeech_results_json CHECK (jsondata IS JSON));
21-
create index aispeechresultsindex on aispeech_results(jsondata) indextype is ctxsys.context;
22-
--select index_name, index_type, status from user_indexes where index_name = 'AISPEECHRESULTSINDEX';
23-
--select idx_name, idx_table, idx_text_name from ctx_user_indexes;
24-
--select token_text from dr$aispeechresultsindex$i;
25-
26-
CREATE OR REPLACE FUNCTION execute_dynamic_sql(p_sql IN VARCHAR2) RETURN VARCHAR2 IS
27-
v_result VARCHAR2(4000);
28-
BEGIN
29-
EXECUTE IMMEDIATE p_sql INTO v_result;
30-
RETURN v_result;
31-
EXCEPTION
32-
WHEN OTHERS THEN
33-
RETURN SQLERRM;
34-
END execute_dynamic_sql;
3516
/
3617

3718
BEGIN
@@ -59,18 +40,18 @@ dbms_cloud.create_credential (
5940
);
6041
END;
6142

62-
63-
create or replace FUNCTION call_analyze_image_api_objectstore (
43+
CREATE OR REPLACE FUNCTION call_analyze_image_api_objectstore (
6444
p_endpoint VARCHAR2,
6545
p_compartment_ocid VARCHAR2,
6646
p_namespaceName VARCHAR2,
6747
p_bucketName VARCHAR2,
6848
p_objectName VARCHAR2,
6949
p_featureType VARCHAR2,
7050
p_label VARCHAR2
71-
) RETURN CLOB IS
51+
) RETURN VARCHAR2 IS
7252
resp DBMS_CLOUD_TYPES.resp;
7353
json_response CLOB;
54+
v_textfromai VARCHAR2(32767);
7455
BEGIN
7556
resp := DBMS_CLOUD.send_request(
7657
credential_name => 'OCI_KEY_CRED',
@@ -92,9 +73,16 @@ BEGIN
9273
)
9374
);
9475
json_response := DBMS_CLOUD.get_response_text(resp);
95-
-- dbms_output.put_line('json_response: ' || json_response);
96-
INSERT INTO aivision_results VALUES (SYS_GUID(), SYSTIMESTAMP, p_label, json_response );
97-
RETURN json_response;
76+
SELECT LISTAGG(name, ', ') WITHIN GROUP (ORDER BY ROWNUM)
77+
INTO v_textfromai
78+
FROM JSON_TABLE(json_response, '$.imageObjects[*]'
79+
COLUMNS (
80+
name VARCHAR2(100) PATH '$.name'
81+
)
82+
);
83+
INSERT INTO aivision_results (id, date_loaded, label, textfromai, jsondata)
84+
VALUES (SYS_GUID(), SYSTIMESTAMP, p_label, v_textfromai, json_response);
85+
RETURN v_textfromai;
9886
EXCEPTION
9987
WHEN OTHERS THEN
10088
RAISE;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ public static String analyzeImageInObjectStore(
3737
"{\"p_bucketname\": \"%s\", \"p_compartment_ocid\": \"%s\", \"p_endpoint\": \"%s\", " +
3838
"\"p_namespacename\": \"%s\", \"p_objectname\": \"%s\", \"p_featuretype\": \"%s\", \"p_label\": \"%s\"}",
3939
bucketName, compartmentOcid, visionServiceEndpoint, namespaceName, objectName, featureType, label);
40-
// jsonPayload = "{\"p_bucketname\": \"doc\",\n" +
41-
// "\"p_compartment_ocid\": \"ocid1.compartment.oc1..aaaaaaaafnah3ogykjsg34qruhixhb2drls6zhsejzm7mubi2i5qj66slcoq\",\n" +
42-
// "\"p_endpoint\": \"https://vision.aiservice.us-ashburn-1.oci.oraclecloud.com\",\n" +
43-
// "\"p_namespacename\": \"oradbclouducm\",\n" +
44-
// "\"p_objectname\": \"bloodsugarreport.jpeg\",\n" +
45-
// "\"p_featuretype\": \"TEXT_DETECTION\",\n" +
46-
// "\"p_label\": \"MedicalReportSummary\"}";
4740
System.out.println("ORDSCalls.analyzeImageInObjectStore jsonPayload:" + jsonPayload);
4841
HttpHeaders headers = new HttpHeaders();
4942
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
@@ -53,7 +46,6 @@ public static String analyzeImageInObjectStore(
5346
System.out.println("ORDSCalls.analyzeImageInObjectStore response.getBody():" + response.getBody());
5447
return response.getBody();
5548
}
56-
5749
public static String executeDynamicSQL(
5850
String ordsEndpoint, String sql) {
5951
System.out.println("executeDynamicSQL ordsEndpoint = " + ordsEndpoint + ", sql = " + sql);

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class OracleVisionAI {
2929
.build();
3030
*
3131
*/
32-
3332
public static String processImage(byte[] bytes, ImageFeature feature) throws Exception {
3433
AuthenticationDetailsProvider provider = AuthProvider.getAuthenticationDetailsProvider();
3534
AIServiceVisionClient aiServiceVisionClient = AIServiceVisionClient.builder().build(provider);
@@ -56,6 +55,111 @@ public static String processImage(byte[] bytes, ImageFeature feature) throws Exc
5655

5756

5857
//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+
*/
59163

60164
@JsonIgnoreProperties(ignoreUnknown = true)
61165
@Getter

0 commit comments

Comments
 (0)