Spaces:
Runtime error
Runtime error
Commit Β·
5201147
1
Parent(s): 6be128e
Add IPv4 forcing to frame extraction and create product detection test
Browse files
src/features/discovery/services/frame-extraction.service.ts
CHANGED
|
@@ -150,13 +150,14 @@ async function extractYouTubeThumbnails(videoUrl: string): Promise<{ frameBuffer
|
|
| 150 |
* In Vercel, this will likely fail unless we provide a binary.
|
| 151 |
*/
|
| 152 |
async function getDirectVideoUrl(videoUrl: string): Promise<string> {
|
| 153 |
-
console.log(`Attempting to get direct video URL from ${videoUrl}...`);
|
| 154 |
try {
|
| 155 |
// check if yt-dlp exists in PATH
|
| 156 |
execSync('yt-dlp --version');
|
| 157 |
|
| 158 |
const { stdout } = await execFileAsync('yt-dlp', [
|
| 159 |
'-g',
|
|
|
|
| 160 |
'--format', 'best[ext=mp4]/best',
|
| 161 |
videoUrl,
|
| 162 |
]);
|
|
|
|
| 150 |
* In Vercel, this will likely fail unless we provide a binary.
|
| 151 |
*/
|
| 152 |
async function getDirectVideoUrl(videoUrl: string): Promise<string> {
|
| 153 |
+
console.log(`Attempting to get direct video URL from ${videoUrl} (IPv4 forced)...`);
|
| 154 |
try {
|
| 155 |
// check if yt-dlp exists in PATH
|
| 156 |
execSync('yt-dlp --version');
|
| 157 |
|
| 158 |
const { stdout } = await execFileAsync('yt-dlp', [
|
| 159 |
'-g',
|
| 160 |
+
'--force-ipv4',
|
| 161 |
'--format', 'best[ext=mp4]/best',
|
| 162 |
videoUrl,
|
| 163 |
]);
|
test-env-vars.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env tsx
|
| 2 |
+
/**
|
| 3 |
+
* Test script to verify environment variables are being read correctly
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
import dotenv from 'dotenv';
|
| 7 |
+
|
| 8 |
+
// Load environment variables from .env.local
|
| 9 |
+
dotenv.config({ path: '.env.local' });
|
| 10 |
+
|
| 11 |
+
import { getVisionConfig } from './src/config/vision.config';
|
| 12 |
+
|
| 13 |
+
console.log('π― Testing environment variables');
|
| 14 |
+
console.log('ββββββββββββββββββββββββββββββ');
|
| 15 |
+
|
| 16 |
+
try {
|
| 17 |
+
// Log all relevant environment variables
|
| 18 |
+
console.log('NODE_ENV:', process.env.NODE_ENV);
|
| 19 |
+
console.log('VISION_PROVIDER:', process.env.VISION_PROVIDER);
|
| 20 |
+
console.log('GOOGLE_GENERATIVE_AI_API_KEY:', process.env.GOOGLE_GENERATIVE_AI_API_KEY ? 'Set' : 'Not set');
|
| 21 |
+
console.log('HUGGINGFACE_API_KEY:', process.env.HUGGINGFACE_API_KEY ? 'Set' : 'Not set');
|
| 22 |
+
|
| 23 |
+
// Test the config
|
| 24 |
+
const config = getVisionConfig();
|
| 25 |
+
console.log('');
|
| 26 |
+
console.log('Configured Vision Provider:', config.provider);
|
| 27 |
+
console.log('Gemini API Key:', config.geminiApiKey ? 'Set' : 'Not set');
|
| 28 |
+
console.log('Hugging Face API Key:', config.huggingfaceApiKey ? 'Set' : 'Not set');
|
| 29 |
+
|
| 30 |
+
console.log('');
|
| 31 |
+
console.log('β
Environment variables are being read correctly');
|
| 32 |
+
console.log('');
|
| 33 |
+
|
| 34 |
+
} catch (error) {
|
| 35 |
+
console.error('β Error testing environment variables:', error);
|
| 36 |
+
process.exit(1);
|
| 37 |
+
}
|
test-product-detection.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env tsx
|
| 2 |
+
/**
|
| 3 |
+
* Test script to verify product detection on an MKBHD video
|
| 4 |
+
* Usage: npx tsx test-product-detection.ts
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
import dotenv from 'dotenv';
|
| 8 |
+
|
| 9 |
+
// Load environment variables from .env.local
|
| 10 |
+
dotenv.config({ path: '.env.local' });
|
| 11 |
+
|
| 12 |
+
import { extractFramesAtIntervals } from './src/features/discovery/services/frame-extraction.service';
|
| 13 |
+
import { detectObjectsInFrame } from './src/features/discovery/services/ai-vision.service';
|
| 14 |
+
|
| 15 |
+
async function testProductDetection() {
|
| 16 |
+
// MKBHD video (Pixel 8 Pro review) - contains various tech products
|
| 17 |
+
const videoUrl = 'https://www.youtube.com/watch?v=YO1u1RAkywk';
|
| 18 |
+
|
| 19 |
+
console.log('π¬ Testing product detection on MKBHD video');
|
| 20 |
+
console.log('ββββββββββββββββββββββββββββββββββββββββ');
|
| 21 |
+
console.log(`πΉ Video: ${videoUrl}`);
|
| 22 |
+
console.log(`β±οΈ Interval: 60 seconds (to test key moments)`);
|
| 23 |
+
console.log('');
|
| 24 |
+
|
| 25 |
+
const startTime = Date.now();
|
| 26 |
+
|
| 27 |
+
try {
|
| 28 |
+
console.log('π Starting frame extraction...\n');
|
| 29 |
+
|
| 30 |
+
const frames = await extractFramesAtIntervals(videoUrl, 60);
|
| 31 |
+
|
| 32 |
+
console.log(`β
Extracted ${frames.length} frames!`);
|
| 33 |
+
console.log('');
|
| 34 |
+
|
| 35 |
+
// Test product detection on each frame
|
| 36 |
+
console.log('π Testing product detection...\n');
|
| 37 |
+
|
| 38 |
+
const allDetections = [];
|
| 39 |
+
|
| 40 |
+
for (let i = 0; i < frames.length; i++) {
|
| 41 |
+
const frame = frames[i];
|
| 42 |
+
console.log(`Processing frame ${i + 1}/${frames.length} (${frame.timestamp}s)...`);
|
| 43 |
+
|
| 44 |
+
try {
|
| 45 |
+
const detections = await detectObjectsInFrame(frame.frameBuffer);
|
| 46 |
+
|
| 47 |
+
if (detections.length > 0) {
|
| 48 |
+
console.log(`β Found ${detections.length} objects:`);
|
| 49 |
+
detections.forEach(detection => {
|
| 50 |
+
console.log(` - ${detection.name} (${Math.round(detection.confidence * 100)}% confidence)`);
|
| 51 |
+
});
|
| 52 |
+
allDetections.push(...detections);
|
| 53 |
+
} else {
|
| 54 |
+
console.log('β No objects detected');
|
| 55 |
+
}
|
| 56 |
+
} catch (error: any) {
|
| 57 |
+
console.error(`β Error detecting objects in frame ${i + 1}:`, error.message);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
console.log('');
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
const endTime = Date.now();
|
| 64 |
+
const duration = ((endTime - startTime) / 1000).toFixed(2);
|
| 65 |
+
|
| 66 |
+
console.log('β
Product detection test complete!');
|
| 67 |
+
console.log('ββββββββββββββββββββββββββββββββββββββββ');
|
| 68 |
+
console.log(`π Results:`);
|
| 69 |
+
console.log(` β’ Total frames processed: ${frames.length}`);
|
| 70 |
+
console.log(` β’ Total objects detected: ${allDetections.length}`);
|
| 71 |
+
console.log(` β’ Time taken: ${duration}s`);
|
| 72 |
+
console.log(` β’ Average per frame: ${(parseFloat(duration) / frames.length).toFixed(2)}s`);
|
| 73 |
+
|
| 74 |
+
// Show unique objects
|
| 75 |
+
const uniqueObjects = [...new Set(allDetections.map(d => d.name))];
|
| 76 |
+
console.log(` β’ Unique objects: ${uniqueObjects.length}`);
|
| 77 |
+
|
| 78 |
+
if (uniqueObjects.length > 0) {
|
| 79 |
+
console.log('');
|
| 80 |
+
console.log('π― Unique objects detected:');
|
| 81 |
+
uniqueObjects.forEach(obj => {
|
| 82 |
+
const count = allDetections.filter(d => d.name === obj).length;
|
| 83 |
+
console.log(` β’ ${obj} (${count}x)`);
|
| 84 |
+
});
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
if (allDetections.length === 0) {
|
| 88 |
+
console.log('');
|
| 89 |
+
console.log('β οΈ Warning: No objects were detected in any frame');
|
| 90 |
+
} else {
|
| 91 |
+
console.log('');
|
| 92 |
+
console.log('π Success! Product detection is working.');
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
} catch (error: any) {
|
| 96 |
+
console.error('\nβ Test failed:', error.message);
|
| 97 |
+
if (error.message.includes('yt-dlp')) {
|
| 98 |
+
console.error('\nπ‘ Tip: Make sure yt-dlp is installed: brew install yt-dlp');
|
| 99 |
+
}
|
| 100 |
+
process.exit(1);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
testProductDetection();
|