Spaces:
Running
Running
<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/[email protected]/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> | |