File size: 1,488 Bytes
4bf0aa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import fs from 'fs';
import path from 'path';

async function testPythonServer() {
    const imagePath = 'C:/Users/T M lakshmi narasimh/.gemini/antigravity/brain/0c64704c-eaf9-41b2-8cdf-90a2f6c7f6e0/uploaded_image_1768470141222.jpg';

    if (!fs.existsSync(imagePath)) {
        console.error('Test image not found:', imagePath);
        return;
    }

    const imageBuffer = fs.readFileSync(imagePath);
    const imageBase64 = imageBuffer.toString('base64');

    console.log('Testing Python OCR Server at http://localhost:5001/ocr...');

    try {
        const response = await fetch('http://localhost:5001/ocr', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ imageBase64 })
        });

        if (!response.ok) {
            throw new Error(`Server error: ${response.status} ${response.statusText}`);
        }

        const result = await response.json();
        console.log('Response received!');

        if (result.success) {
            console.log('OCR Success!');
            console.log('Text length:', result.text.length);
            console.log('First 100 chars:', result.text.substring(0, 100));
            console.log('Structured data items:', result.structured_data.length);
        } else {
            console.error('OCR Failed:', result.error);
        }

    } catch (error) {
        console.error('Test failed:', error);
    }
}

testPythonServer();