File size: 4,395 Bytes
32652fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invoice Extraction</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: 'Poppins', sans-serif; background: linear-gradient(to right, #6a11cb, #2575fc); color: #333; display: flex; justify-content: center; align-items: center; height: 100vh; }
        .container { width: 90%; max-width: 600px; background: #ffffff; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); border-radius: 12px; padding: 30px; }
        .header { text-align: center; margin-bottom: 20px; }
        .header h1 { font-size: 28px; font-weight: 700; color: #333; }
        .header p { font-size: 14px; color: #777; }
        .upload-section { margin-bottom: 20px; }
        .upload-section label { display: block; font-size: 16px; font-weight: 500; margin-bottom: 10px; color: #555; }
        .upload-section input[type="file"] { display: block; padding: 12px; font-size: 14px; border: 1px solid #ddd; border-radius: 8px; width: 100%; transition: all 0.3s ease; }
        .upload-section input[type="file"]:focus { border-color: #2575fc; outline: none; }
        .actions { text-align: center; margin-top: 10px; }
        .actions button { background-color: #2575fc; color: white; padding: 12px 25px; border: none; border-radius: 8px; font-size: 16px; font-weight: 500; cursor: pointer; transition: background-color 0.3s ease; margin: 10px 5px; }
        .actions button:hover { background-color: #1a5bb8; }
        .output-section { margin-top: 20px; text-align: center; }
        .output-section img { max-width: 100%; margin-bottom: 15px; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); }
        .output-section button { background-color: #34c759; color: white; padding: 10px 20px; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: background-color 0.3s ease; }
        .output-section button:hover { background-color: #28a745; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>Invoice Processing</h1>
            <p>Upload your invoice and extract data with ease</p>
        </div>

        <div class="upload-section">
            <label for="invoice-upload">Upload Invoice Image:</label>
            <input type="file" id="invoice-upload" accept="image/*">
        </div>

        <div class="actions">
            <button id="upload-btn">Upload & Process</button>
        </div>

        <div class="output-section" id="output-section" style="display: none;">
            <img id="output-image" src="" alt="Annotated Image">
            <a id="download-csv" href="" download><button>Download CSV</button></a>
            <a id="download-image" href="" download><button>Download Annotated Image</button></a>
        </div>
    </div>

    <script>
        const uploadBtn = document.getElementById('upload-btn');
        const invoiceInput = document.getElementById('invoice-upload');
        const outputSection = document.getElementById('output-section');
        const outputImage = document.getElementById('output-image');
        const downloadCsvButton = document.getElementById('download-csv');
        const downloadImageButton = document.getElementById('download-image');

        uploadBtn.addEventListener('click', () => {
            const file = invoiceInput.files[0];
            if (!file) return alert('Please select a file.');

            const formData = new FormData();
            formData.append('invoice-upload', file);

            fetch('/upload', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                outputImage.src = data.image_path;
                downloadCsvButton.href = `/download_csv/${data.csv_path.split('/').pop()}`;
                downloadImageButton.href = `/download_image/${data.image_path.split('/').pop()}`;
                outputSection.style.display = 'block';
            })
            .catch(error => alert('Error processing the image: ' + error));
        });
    </script>
</body>
</html>