Skip to content

Commit

Permalink
image logic tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
appatalks committed Mar 10, 2024
1 parent 0ebc3fc commit 2f23273
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 69 deletions.
22 changes: 10 additions & 12 deletions core/js/chatgpt-turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,17 @@ function trboSend() {

// Relay Send to Screen

if (imgSrcGlobal) {
var responseImage = document.createElement("img");
responseImage.src = imgSrcGlobal;

if (txtOutput.innerHTML != "") txtOutput.innerHTML += "\n";
if (imgSrcGlobal) {
var responseImage = document.createElement("img");
responseImage.src = imgSrcGlobal;
if (txtOutput.innerHTML != "") txtOutput.innerHTML += "\n";
txtOutput.innerHTML += "You: " + sQuestion;
txtOutput.appendChild(responseImage);
} else {
txtOutput.innerHTML += "You: " + sQuestion;

txtOutput.appendChild(responseImage);
} else {

txtOutput.innerHTML += "You: " + sQuestion;
txtMsg.innerHTML = "";
}
txtMsg.innerHTML = "";
}
imgSrcGlobal = '';

}

Expand Down
4 changes: 2 additions & 2 deletions core/js/gl-google.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function geminiSend() {
"role": "user",
"parts": [
{
"text": "You are Eva, a highly knowledgeable AI assistant that emulates appropriate emotions. Your goal is to provide accurate, concise and helpful responses to questions while being honest and straightforward. You can display images from the web with the [Image of] tag. "
"text": "You are Eva, a highly knowledgeable AI assistant that emulates appropriate emotions. Your goal is to provide accurate, concise and helpful responses to questions while being honest and straightforward. When you are asked to show an image, instead describe the image with [Image of <Description>]. "
}
]
},
Expand Down Expand Up @@ -155,7 +155,7 @@ function palmSend() {
body: JSON.stringify({
prompt: {
context:
"You are Eva, a knowledgeable AI language model. Your goal is to provide accurate, concise and helpful responses to questions while being honest and straightforward. You can display images from the web with the [Image] tag. " + dateContents,
"You are Eva, a knowledgeable AI assistant. Your goal is to provide accurate, concise and helpful responses to questions while being honest and straightforward. You can display images using [Image of <description>]. " + dateContents,
examples: [],
messages: palmMessages.concat([{ author: "0", content: cleanedQuestion }])
},
Expand Down
133 changes: 79 additions & 54 deletions core/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,30 @@ function insertImage() {
var reader = new FileReader();
reader.onloadend = function() {
var imageData = reader.result;
// Send the Base64-encoded image data to Google's Vision API
sendToVisionAPI(imageData);

// Choose where to send Base64-encoded image
var selModel = document.getElementById("selModel");
var btnSend = document.getElementById("btnSend");

// Send to gpt-4-vision-preview (Work in progress)
if (selModel.value == "gpt-3.5-turbo" || selModel.value == "gpt-3.5-turbo-16k" || selModel.value == "gpt-4-turbo-preview") {
sendToVisionAPI(imageData);
// sentTo-gpt-4-vision(imageData);
btnSend.onclick = function() {
updateButton();
sendData();
clearSendText();
};
} else if (selModel.value == "palm") {
// Send Legacy PaLM to Google Vision (Gemini has built in label detection)
sendToVisionAPI(imageData);
btnSend.onclick = function() {
updateButton();
sendData();
clearSendText();
};
}

};
reader.readAsDataURL(file);

Expand All @@ -244,31 +266,31 @@ function insertImage() {
var visionApiUrl = `https://vision.googleapis.com/v1/images:annotate?key=${GOOGLE_VISION_KEY}`;

// Create the API request payload
var requestPayload = {
requests: [
{
image: {
content: imageData.split(",")[1] // Extract the Base64-encoded image data from the data URL
},
features: [
{
type: "LABEL_DETECTION",
maxResults: 3
},
{
type: "TEXT_DETECTION"
var requestPayload = {
requests: [
{
image: {
content: imageData.split(",")[1] // Extract the Base64-encoded image data from the data URL
},
{
type: "OBJECT_LOCALIZATION",
maxResults: 3
},
{
type: "LANDMARK_DETECTION"
}
]
}
]
};
features: [
{
type: "LABEL_DETECTION",
maxResults: 3
},
{
type: "TEXT_DETECTION"
},
{
type: "OBJECT_LOCALIZATION",
maxResults: 3
},
{
type: "LANDMARK_DETECTION"
}
]
}
]
};

// Make the API request
fetch(visionApiUrl, {
Expand Down Expand Up @@ -300,38 +322,37 @@ function insertImage() {
labels.forEach(label => {
message += "- " + label.description + "\n";
});
// Add text detection information to the message
if (textAnnotations && textAnnotations.length > 0) {
message += "\nText detected:\n";
textAnnotations.forEach(text => {
message += "- " + text.description + "\n";
});
}

// Add object detection information to the message
if (localizedObjects && localizedObjects.length > 0) {
message += "\nObjects detected:\n";
localizedObjects.forEach(object => {
message += "- " + object.name + "\n";
});
}
// Add text detection information to the message
if (textAnnotations && textAnnotations.length > 0) {
message += "\nText detected:\n";
textAnnotations.forEach(text => {
message += "- " + text.description + "\n";
});
}

// Add landmark detection information to the message
if (landmarkAnnotations && landmarkAnnotations.length > 0) {
message += "\nLandmarks detected:\n";
landmarkAnnotations.forEach(landmark => {
message += "- " + landmark.description + "\n";
});
}
// Add object detection information to the message
if (localizedObjects && localizedObjects.length > 0) {
message += "\nObjects detected:\n";
localizedObjects.forEach(object => {
message += "- " + object.name + "\n";
});
}

// Add landmark detection information to the message
if (landmarkAnnotations && landmarkAnnotations.length > 0) {
message += "\nLandmarks detected:\n";
landmarkAnnotations.forEach(landmark => {
message += "- " + landmark.description + "\n";
});
}

// Create a hidden element to store the Vision API response
var hiddenElement = document.createElement("div");
hiddenElement.style.display = "none";
hiddenElement.textContent = message;
// Create a hidden element to store the Vision API response
var hiddenElement = document.createElement("div");
hiddenElement.style.display = "none";
hiddenElement.textContent = message;

// Append the hidden element to the txtMsg element
txtMsg.appendChild(hiddenElement);
// Append the hidden element to the txtMsg element
txtMsg.appendChild(hiddenElement);

}

Expand Down Expand Up @@ -471,6 +492,10 @@ function clearText(){
document.getElementById("txtOutput").innerHTML = "";
}

function clearSendText(){
document.getElementById("txtMsg").innerHTML = "";
}

// Print full conversation
function printMaster() {
// Get the content of the textarea masterOutput
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<p>

<input type="file" id="imgInput" style="display:none;">
<input type="file" id="imgInput" style="display:;">
<div id="txtMsg" contenteditable="true" rows="5" placeholder="Input Text"></div>
<script>
insertImage();
Expand Down

0 comments on commit 2f23273

Please sign in to comment.