File size: 2,724 Bytes
135aa7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0574f1b
 
135aa7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spam Email Classifier</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
        }
        textarea {
            width: 100%;
            height: 150px;
        }
        button {
            margin-top: 10px;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        #result {
            margin-top: 20px;
            font-size: 18px;
            font-weight: bold;
        }
        #info {
            margin-top: 20px;
            font-size: 16px;
            font-style: italic;
        }
    </style>
</head>
<body>

    <h1>Spam Email Classifier</h1>
    <p>Enter your email below, and the model will predict if it's spam or not.</p>

    <form id="email-form">
        <textarea id="email-text" placeholder="Enter email content..."></textarea>
        <button type="submit">Classify Email</button>
    </form>

    <button id="info-button">Info</button>

    <div id="result"></div>
    <div id="info"></div>

    <script>
        // Local Server
        // const PREDICT_URL = "http://127.0.0.1:8000/predict/";
        // const INFO_URL = "http://127.0.0.1:8000/";

        // Remote Servers
        const PREDICT_URL = "https://dangminh214-spam-email-classifier.hf.space/predict/";
        const INFO_URL = "https://dangminh214-spam-email-classifier.hf.space/";

        // Handle email form submission
        document.getElementById('email-form').addEventListener('submit', async function(event) {
            event.preventDefault();

            const emailText = document.getElementById('email-text').value;

            const response = await fetch(PREDICT_URL, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ text: emailText })
            });

            const data = await response.json();
            let predictResult = "Legit E-Mail"

            if (data.prediction == "spam") predictResult = "Spam E-Mail"

            document.getElementById('result').textContent = `Prediction: ${predictResult}`;
        });

        // Handle info button click
        document.getElementById('info-button').addEventListener('click', async function() {
            const response = await fetch(INFO_URL);
            const data = await response.json();
            document.getElementById('info').textContent = data.info;
        });
    </script>

</body>
</html>