boazchung commited on
Commit
74e6aa1
1 Parent(s): 0281807

Update translation.html

Browse files
Files changed (1) hide show
  1. translation.html +17 -6
translation.html CHANGED
@@ -81,22 +81,33 @@
81
 
82
  <script type="module">
83
  import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm';
 
84
 
85
  // Initialize the sentiment analysis model
86
  async function initializeModel() {
87
  const token = document.getElementById('hf-token').value;
88
- const hf = new HfInference(token);
89
  }
90
 
91
  async function translateText() {
92
- const textFieldValue = document.getElementById("translationText2").value.trim();
 
 
 
 
 
 
93
 
 
94
  let result = await hf.translation({
95
- model: 't5-base',
96
- inputs: textFieldValue,
97
- });
98
  document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
99
- }
 
 
 
100
 
101
 
102
  /*
 
81
 
82
  <script type="module">
83
  import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm';
84
+ let hf;
85
 
86
  // Initialize the sentiment analysis model
87
  async function initializeModel() {
88
  const token = document.getElementById('hf-token').value;
89
+ hf = new HfInference(token);
90
  }
91
 
92
  async function translateText() {
93
+ // Ensure that hf is initialized before this function is called
94
+ if (!hf) {
95
+ console.error("HfInference is not initialized.");
96
+ return;
97
+ }
98
+
99
+ const textFieldValue = document.getElementById("translationText2").value.trim();
100
 
101
+ try {
102
  let result = await hf.translation({
103
+ model: 't5-base',
104
+ inputs: textFieldValue,
105
+ });
106
  document.getElementById("outputArea2").innerText = JSON.stringify(result, null, 2);
107
+ } catch (error) {
108
+ console.error("Error during translation:", error);
109
+ }
110
+ }
111
 
112
 
113
  /*