File size: 1,515 Bytes
55450db
 
 
 
 
 
4807797
5663e02
 
 
 
 
4807797
55450db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c72911
 
4807797
 
 
 
 
8c72911
55450db
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image to Sketch</title>
    <style>
        /* Style to make the image smaller */
        #result img {
            max-width: 100%;
            height: auto;
        }
    </style>
</head>
<body>
    <h1>Image to Sketch</h1>
    <form action="/upload/" method="post" enctype="multipart/form-data">
        <input type="file" name="file">
        <button type="submit">Upload</button>
    </form>
    <div id="result"></div>

    <script>
        async function uploadFile() {
            const formData = new FormData();
            const fileInput = document.querySelector('input[type="file"]');
            formData.append('file', fileInput.files[0]);

            const response = await fetch('/upload/', {
                method: 'POST',
                body: formData
            });

            const data = await response.json();
            const sketchImage = document.createElement('img');
            sketchImage.src = data.sketch_image_base64;

            // Clear previous result
            document.getElementById('result').innerHTML = '';

            // Append new image
            document.getElementById('result').appendChild(sketchImage);
        }

        document.querySelector('form').addEventListener('submit', function(event) {
            event.preventDefault();
            uploadFile();
        });
    </script>
</body>
</html>