File size: 2,221 Bytes
912ab32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Text Classification</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 50px;
        }
        .container {
            max-width: 500px;
            margin: 0 auto;
            text-align: center;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            font-size: 16px;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
        }
        .result {
            margin-top: 20px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Text Classification</h1>
        <input type="text" id="textInput" placeholder="Enter your text here">
        <button onclick="classifyText()">Classify</button>
        <div id="result" class="result"></div>
    </div>
    <script>
        async function classifyText() {
            const text = document.getElementById('textInput').value;

            if (!text.trim()) {
                document.getElementById('result').textContent = "Please enter some text!";
                return;
            }

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

                if (response.ok) {
                    const data = await response.json();
                    document.getElementById('result').textContent = `Prediction: ${data.prediction}`;
                } else {
                    document.getElementById('result').textContent = "Error: Unable to fetch prediction.";
                }
            } catch (error) {
                console.error("Error:", error);
                document.getElementById('result').textContent = "Error: Unable to fetch prediction.";
            }
        }
    </script>
</body>
</html>