Added dupplicate title support for more accurate results
This commit is contained in:
parent
9f1e5ef42f
commit
00e4779278
|
@ -314,6 +314,53 @@
|
||||||
return urlsArray;
|
return urlsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractJsonObjects(limit) {
|
||||||
|
// Set the default value of the limit parameter to Infinity
|
||||||
|
limit = limit || Infinity;
|
||||||
|
|
||||||
|
// Select all <div> elements with the class "font-medium"
|
||||||
|
const elements = document.querySelectorAll('div.font-medium');
|
||||||
|
|
||||||
|
// Initialize an empty array to store the JSON objects
|
||||||
|
const jsonObjects = [];
|
||||||
|
|
||||||
|
// Loop through the elements
|
||||||
|
for (const element of elements) {
|
||||||
|
// Extract the text inside the element
|
||||||
|
const text = element.textContent;
|
||||||
|
|
||||||
|
// Try to parse the text as JSON
|
||||||
|
try {
|
||||||
|
// Check if the text is a valid JSON object
|
||||||
|
if (text.startsWith('{') && text.endsWith('}')) {
|
||||||
|
// Parse the text as JSON
|
||||||
|
const jsonObject = JSON.parse(text);
|
||||||
|
|
||||||
|
// If the parsing is successful, add the JSON object to the array
|
||||||
|
jsonObjects.push(jsonObject);
|
||||||
|
} else {
|
||||||
|
// If the text is not a valid JSON object, try to parse it as a single property object
|
||||||
|
const jsonObject = JSON.parse(`{"data": "${text}"}`);
|
||||||
|
|
||||||
|
// If the parsing is successful, add the JSON object to the array
|
||||||
|
jsonObjects.push(jsonObject.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// If the parsing fails, log the text and the error message
|
||||||
|
console.error(`Failed to parse JSON from element: ${text}`);
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the limit has been reached, break the loop
|
||||||
|
if (jsonObjects.length >= limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the array of JSON objects
|
||||||
|
return jsonObjects;
|
||||||
|
}
|
||||||
|
|
||||||
async function urlsToBlobs(imageUrls) {
|
async function urlsToBlobs(imageUrls) {
|
||||||
const blobPromises = imageUrls.map(imageUrl => {
|
const blobPromises = imageUrls.map(imageUrl => {
|
||||||
return fetch(imageUrl)
|
return fetch(imageUrl)
|
||||||
|
@ -1060,7 +1107,7 @@
|
||||||
}
|
}
|
||||||
console.log('Question Informations (Review): ', questionResults);
|
console.log('Question Informations (Review): ', questionResults);
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
possibleCategories = getPossibleCategories();
|
possibleCategories = getPossibleCategories();
|
||||||
if (possibleCategories) {
|
if (possibleCategories) {
|
||||||
console.log('Possible Categories (Review): ', possibleCategories);
|
console.log('Possible Categories (Review): ', possibleCategories);
|
||||||
}
|
}
|
||||||
|
@ -1074,10 +1121,13 @@
|
||||||
var maxIndex = Math.min(numImages, 4) - 1;
|
var maxIndex = Math.min(numImages, 4) - 1;
|
||||||
|
|
||||||
if (maxIndex > -1) {
|
if (maxIndex > -1) {
|
||||||
|
var duplicateCheckTitles = extractJsonObjects(4)
|
||||||
|
console.log('Duplicate Check Titles (Review): ', duplicateCheckTitles);
|
||||||
for (let i = 0; i <= maxIndex; i++) {
|
for (let i = 0; i <= maxIndex; i++) {
|
||||||
if (!isSubmitted) {
|
if (!isSubmitted) {
|
||||||
var reviewImageDuplicate = await urlsToBlobs([mainPhoto, nearbyImages[i]])
|
var reviewImageDuplicate = await urlsToBlobs([mainPhoto, nearbyImages[i]])
|
||||||
var reviewDuplicateFinalString = reviewDuplicateText + bottomText
|
var reviewDuplicateTitle = `Title of First image: ${title}\nTitle of Second image: ${duplicateCheckTitles[i]}`;
|
||||||
|
var reviewDuplicateFinalString = reviewDuplicateText + reviewDuplicateTitle + bottomText
|
||||||
reviewDuplicateChoice[i] = await geminiCallAPI(reviewDuplicateFinalString, reviewImageDuplicate)
|
reviewDuplicateChoice[i] = await geminiCallAPI(reviewDuplicateFinalString, reviewImageDuplicate)
|
||||||
if (Object.values(reviewDuplicateChoice[i])[0] === true) {
|
if (Object.values(reviewDuplicateChoice[i])[0] === true) {
|
||||||
clickNearbyImages(i)
|
clickNearbyImages(i)
|
||||||
|
|
Loading…
Reference in New Issue