Update translation.html
Browse files- translation.html +36 -57
translation.html
CHANGED
|
@@ -3,14 +3,14 @@
|
|
| 3 |
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
-
<title>Translation -
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
// Import the library
|
| 10 |
-
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
| 11 |
|
| 12 |
// Make it available globally
|
| 13 |
-
window.pipeline = pipeline;
|
| 14 |
</script>
|
| 15 |
|
| 16 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
@@ -20,19 +20,6 @@
|
|
| 20 |
|
| 21 |
<body>
|
| 22 |
<div class="container-main">
|
| 23 |
-
<!-- Page Header -->
|
| 24 |
-
<div class="header">
|
| 25 |
-
<div class="header-logo">
|
| 26 |
-
<img src="images/logo.png" alt="logo">
|
| 27 |
-
</div>
|
| 28 |
-
<div class="header-main-text">
|
| 29 |
-
<h1>Hugging Face Transformers.js</h1>
|
| 30 |
-
</div>
|
| 31 |
-
<div class="header-sub-text">
|
| 32 |
-
<h3>Free AI Models for JavaScript Web Development</h3>
|
| 33 |
-
</div>
|
| 34 |
-
</div>
|
| 35 |
-
<hr> <!-- Separator -->
|
| 36 |
|
| 37 |
<!-- Back to Home button -->
|
| 38 |
<div class="row mt-5">
|
|
@@ -51,32 +38,15 @@
|
|
| 51 |
</div>
|
| 52 |
|
| 53 |
<!-- Actual Content of this page -->
|
| 54 |
-
<div id="translation-container" class="container mt-4">
|
| 55 |
-
<h5>Multilingual Translation w/ Xenova/nllb-200-distilled-600M:</h5>
|
| 56 |
-
<div class="d-flex align-items-center">
|
| 57 |
-
<label for="translationText" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to
|
| 58 |
-
Translate:</label>
|
| 59 |
-
<input type="text" class="form-control flex-grow-1" id="translationText"
|
| 60 |
-
value="जीवन एक चॉकलेट बॉक्स की तरह है।" placeholder="Enter text"
|
| 61 |
-
style="margin-right: 15px; margin-left: 15px;">
|
| 62 |
-
<button id="translateButton" class="btn btn-primary" onclick="translateText()">Translate</button>
|
| 63 |
-
</div>
|
| 64 |
-
<div class="mt-4">
|
| 65 |
-
<h4>Output:</h4>
|
| 66 |
-
<pre id="outputArea"></pre>
|
| 67 |
-
</div>
|
| 68 |
-
</div>
|
| 69 |
-
|
| 70 |
-
<hr> <!-- Line Separator -->
|
| 71 |
|
| 72 |
<div id="translation-container" class="container mt-4">
|
| 73 |
<h5>Multilingual Translation w/ Xenova/m2m100_418M:</h5>
|
| 74 |
<div class="d-flex align-items-center">
|
| 75 |
<label for="translationText2" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to
|
| 76 |
Translate:</label>
|
| 77 |
-
<input type="text" class="form-control flex-grow-1" id="translationText2" value="
|
| 78 |
placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;">
|
| 79 |
-
<button id="translateButton2" class="btn btn-primary" onclick="
|
| 80 |
</div>
|
| 81 |
<div class="mt-4">
|
| 82 |
<h4>Output:</h4>
|
|
@@ -94,40 +64,49 @@
|
|
| 94 |
</div>
|
| 95 |
</div>
|
| 96 |
|
| 97 |
-
<script>
|
|
|
|
| 98 |
|
| 99 |
let translator;
|
| 100 |
let translator2;
|
| 101 |
|
| 102 |
// Initialize the sentiment analysis model
|
| 103 |
async function initializeModel() {
|
| 104 |
-
|
| 105 |
-
|
| 106 |
|
| 107 |
}
|
| 108 |
|
| 109 |
async function translateText() {
|
| 110 |
const textFieldValue = document.getElementById("translationText").value.trim();
|
| 111 |
|
| 112 |
-
let result = await
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
// Initialize the model after the DOM is completely loaded
|
| 132 |
window.addEventListener("DOMContentLoaded", initializeModel);
|
| 133 |
</script>
|
|
|
|
| 3 |
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
+
<title>Translation - huggingface.js</title>
|
| 7 |
|
| 8 |
<script type="module">
|
| 9 |
// Import the library
|
| 10 |
+
//import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
| 11 |
|
| 12 |
// Make it available globally
|
| 13 |
+
//window.pipeline = pipeline;
|
| 14 |
</script>
|
| 15 |
|
| 16 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
|
|
| 20 |
|
| 21 |
<body>
|
| 22 |
<div class="container-main">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
<!-- Back to Home button -->
|
| 25 |
<div class="row mt-5">
|
|
|
|
| 38 |
</div>
|
| 39 |
|
| 40 |
<!-- Actual Content of this page -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
<div id="translation-container" class="container mt-4">
|
| 43 |
<h5>Multilingual Translation w/ Xenova/m2m100_418M:</h5>
|
| 44 |
<div class="d-flex align-items-center">
|
| 45 |
<label for="translationText2" class="mb-0 text-nowrap" style="margin-right: 15px;">Enter Text to
|
| 46 |
Translate:</label>
|
| 47 |
+
<input type="text" class="form-control flex-grow-1" id="translationText2" value="My name is Wolfgang and I live in Amsterdam"
|
| 48 |
placeholder="Enter text" style="margin-right: 15px; margin-left: 15px;">
|
| 49 |
+
<button id="translateButton2" class="btn btn-primary" onclick="translateText()">Translate</button>
|
| 50 |
</div>
|
| 51 |
<div class="mt-4">
|
| 52 |
<h4>Output:</h4>
|
|
|
|
| 64 |
</div>
|
| 65 |
</div>
|
| 66 |
|
| 67 |
+
<script type="module">
|
| 68 |
+
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm';
|
| 69 |
|
| 70 |
let translator;
|
| 71 |
let translator2;
|
| 72 |
|
| 73 |
// Initialize the sentiment analysis model
|
| 74 |
async function initializeModel() {
|
| 75 |
+
const token = document.getElementById('hf-token').value;
|
| 76 |
+
const hf = new HfInference(token);
|
| 77 |
|
| 78 |
}
|
| 79 |
|
| 80 |
async function translateText() {
|
| 81 |
const textFieldValue = document.getElementById("translationText").value.trim();
|
| 82 |
|
| 83 |
+
let result = await hf.translation({
|
| 84 |
+
model: 't5-base',
|
| 85 |
+
inputs: textFieldValue,
|
| 86 |
+
document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
/*
|
| 94 |
+
document.getElementById('hf-form').addEventListener('submit', async (event) => {
|
| 95 |
+
event.preventDefault();
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
// You can also omit "model" to use the recommended model for the task
|
| 100 |
+
let result = await hf.translation({
|
| 101 |
+
model: 't5-base',
|
| 102 |
+
inputs: textFieldValue,
|
| 103 |
+
document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
console.log(result);
|
| 107 |
+
});
|
| 108 |
+
|
| 109 |
+
*/
|
| 110 |
// Initialize the model after the DOM is completely loaded
|
| 111 |
window.addEventListener("DOMContentLoaded", initializeModel);
|
| 112 |
</script>
|