File size: 2,022 Bytes
2894987
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Smart Recycling Assistant</title>
    <style>

        body {

            font-family: Arial, sans-serif;

            text-align: center;

            margin: 50px;

        }

        input {

            margin-top: 20px;

        }

        img {

            max-width: 100%;

            margin-top: 20px;

        }

    </style>
</head>
<body>
    <h1>♻️ Smart Recycling Assistant</h1>
    <p>Upload an image of waste, and the AI will classify it for proper disposal.</p>
    
    <form id="upload-form" enctype="multipart/form-data">
        <input type="file" id="file" name="file" accept="image/*" required>
        <button type="submit">Predict</button>
    </form>

    <h3 id="prediction"></h3>
    <p id="guidelines"></p>
    <img id="preview" src="" style="display: none;"/>

    <script>

        document.getElementById("upload-form").addEventListener("submit", function(event) {

            event.preventDefault();

            let fileInput = document.getElementById("file").files[0];

            let formData = new FormData();

            formData.append("file", fileInput);



            fetch("/predict", {

                method: "POST",

                body: formData

            })

            .then(response => response.json())

            .then(data => {

                document.getElementById("prediction").innerText = "🗑️ Prediction: " + data.prediction;

                document.getElementById("guidelines").innerText = "♻️ Recycling Guidelines: " + data.recycling_guidelines;

                let imgPreview = document.getElementById("preview");

                imgPreview.src = URL.createObjectURL(fileInput);

                imgPreview.style.display = "block";

            })

            .catch(error => console.error("Error:", error));

        });

    </script>
</body>
</html>