Spaces:
Running
Running
Update apps/aura_measure.js
Browse files- apps/aura_measure.js +26 -2
apps/aura_measure.js
CHANGED
|
@@ -142,10 +142,34 @@ router.post('/analyze', async (req, res) => {
|
|
| 142 |
let promptText = 'Analyze this image and calculate my Aura. Return JSON.';
|
| 143 |
let imagesToProcess = [media_base64];
|
| 144 |
|
|
|
|
| 145 |
if ((context_type === 'challenge' || context_type === 'thread') && reference_data) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
systemPrompt = AURA_PROMPT_CONTEXTUAL;
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
|
| 151 |
console.log('[Analyze] Running AI...');
|
|
|
|
| 142 |
let promptText = 'Analyze this image and calculate my Aura. Return JSON.';
|
| 143 |
let imagesToProcess = [media_base64];
|
| 144 |
|
| 145 |
+
// Handles Threads & Challenges context
|
| 146 |
if ((context_type === 'challenge' || context_type === 'thread') && reference_data) {
|
| 147 |
+
let refBase64 = reference_data.image_base64;
|
| 148 |
+
|
| 149 |
+
// FIX: If the frontend sent an HTTP URL instead of pure base64, fetch and convert it!
|
| 150 |
+
if (refBase64 && refBase64.startsWith('http')) {
|
| 151 |
+
try {
|
| 152 |
+
console.log('[Analyze] Downloading reference image URL for thread...');
|
| 153 |
+
const imgRes = await fetch(refBase64);
|
| 154 |
+
if (!imgRes.ok) throw new Error(`HTTP ${imgRes.status}`);
|
| 155 |
+
const arrayBuffer = await imgRes.arrayBuffer();
|
| 156 |
+
refBase64 = Buffer.from(arrayBuffer).toString('base64');
|
| 157 |
+
console.log('[Analyze] Successfully downloaded and encoded reference image.');
|
| 158 |
+
} catch (e) {
|
| 159 |
+
console.error('[Analyze] Failed to fetch reference image URL:', e);
|
| 160 |
+
return res.status(400).json({ success: false, error: 'Failed to load the reference image for this thread.' });
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
systemPrompt = AURA_PROMPT_CONTEXTUAL;
|
| 165 |
+
|
| 166 |
+
// Fallback for description if it wasn't provided or passed as 'undefined'
|
| 167 |
+
const descText = reference_data.description && reference_data.description !== 'undefined'
|
| 168 |
+
? reference_data.description
|
| 169 |
+
: 'Match the style, outfit, or vibe of the reference image.';
|
| 170 |
+
|
| 171 |
+
promptText = `CONTEXT TITLE: ${reference_data.title}\nCONTEXT DESCRIPTION: ${descText}\nEvaluate Image 2 against Image 1.`;
|
| 172 |
+
imagesToProcess = [refBase64, media_base64];
|
| 173 |
}
|
| 174 |
|
| 175 |
console.log('[Analyze] Running AI...');
|