File size: 1,344 Bytes
9b89541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image Background Removal</title>
</head>
<body>
    <h1>Image Background Removal</h1>
    <input type="file" id="fileInput" accept="image/*">
    <button onclick="processImage()">Process Image</button>
    <div id="output"></div>

    <script>
        async function processImage() {
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];

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

            try {
                const response = await fetch('/process-image/', {
                    method: 'POST',
                    body: formData
                });

                if (!response.ok) {
                    throw new Error('Failed to process image');
                }

                const blob = await response.blob();
                const imageUrl = URL.createObjectURL(blob);

                const outputDiv = document.getElementById('output');
                outputDiv.innerHTML = `<img src="${imageUrl}" alt="Processed Image">`;
            } catch (error) {
                console.error('Error:', error.message);
            }
        }
    </script>
</body>
</html>