File size: 1,889 Bytes
b39b5b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8184dbe
b39b5b7
 
 
 
8184dbe
b39b5b7
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mask Word Transformer</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body class="container mt-5">
    <h2 class="mb-4">Mask Word Transformer</h2>
    <form id="maskForm">
        <div class="form-group">
            <label for="inputText">Enter Text:</label>
            <input type="text" id="inputText" class="form-control" placeholder="Type your text here" required>
        </div>
        <button type="submit" class="btn btn-primary">Mask Words</button>
    </form>
    <h4 class="mt-4">Transformed Text:</h4>
    <p id="outputText" class="border p-3"></p>
    
    <script>
        document.getElementById('maskForm').addEventListener('submit', async function(event) {
            event.preventDefault();
            const inputText = document.getElementById('inputText').value;
            
            const response = await fetch('https://api-inference.huggingface.co/models/google-bert/bert-base-uncased', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer ${HF_TOKEN}'
                },
                body: JSON.stringify({ inputs: inputText })
            });
            
            const data = await response.json();
            if (Array.isArray(data) && data.length > 0) {
                document.getElementById('outputText').innerText = data[0].sequence;
            } else {
                document.getElementById('outputText').innerText = 'No result found';
            }
        });
    </script>
</body>
</html>