Spaces:
Running
Running
Update test5.html
Browse files- test5.html +35 -2
test5.html
CHANGED
@@ -42,6 +42,7 @@
|
|
42 |
<script>
|
43 |
// Global variable to hold extracted text
|
44 |
let extractedText = '';
|
|
|
45 |
|
46 |
// Function to process the uploaded files (PDF, TXT, DOCX)
|
47 |
function processFiles() {
|
@@ -145,6 +146,32 @@
|
|
145 |
});
|
146 |
}
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
// Function to validate inputs and send the question to Hugging Face API
|
149 |
async function askQuestion() {
|
150 |
const question = document.getElementById('question').value;
|
@@ -156,6 +183,12 @@
|
|
156 |
return;
|
157 |
}
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
// Prepare the request data
|
160 |
const data = {
|
161 |
inputs: {
|
@@ -163,9 +196,8 @@
|
|
163 |
context: context // Should be a string
|
164 |
}
|
165 |
};
|
166 |
-
|
167 |
console.log("key : " + cucu);
|
168 |
-
|
169 |
try {
|
170 |
const response = await fetch('https://api-inference.huggingface.co/models/distilbert-base-multilingual-cased', {
|
171 |
method: 'POST',
|
@@ -195,3 +227,4 @@
|
|
195 |
|
196 |
|
197 |
|
|
|
|
42 |
<script>
|
43 |
// Global variable to hold extracted text
|
44 |
let extractedText = '';
|
45 |
+
let modelReady = false;
|
46 |
|
47 |
// Function to process the uploaded files (PDF, TXT, DOCX)
|
48 |
function processFiles() {
|
|
|
146 |
});
|
147 |
}
|
148 |
|
149 |
+
// Function to check if the model is ready
|
150 |
+
async function checkModelReady() {
|
151 |
+
try {
|
152 |
+
const response = await fetch('https://api-inference.huggingface.co/models/distilbert-base-multilingual-cased', {
|
153 |
+
method: 'GET',
|
154 |
+
headers: {
|
155 |
+
'Authorization': 'Bearer your_huggingface_api_key' // Replace with your Hugging Face API key
|
156 |
+
}
|
157 |
+
});
|
158 |
+
|
159 |
+
const result = await response.json();
|
160 |
+
|
161 |
+
if (result.error && result.error.includes('currently loading')) {
|
162 |
+
const estimatedTime = result.estimated_time || 20;
|
163 |
+
alert(`El modelo est谩 cargando. Estimaci贸n de tiempo restante: ${Math.round(estimatedTime)} segundos.`);
|
164 |
+
return false;
|
165 |
+
}
|
166 |
+
|
167 |
+
modelReady = true;
|
168 |
+
return true;
|
169 |
+
} catch (error) {
|
170 |
+
console.error('Error al verificar si el modelo est谩 listo:', error);
|
171 |
+
return false;
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
// Function to validate inputs and send the question to Hugging Face API
|
176 |
async function askQuestion() {
|
177 |
const question = document.getElementById('question').value;
|
|
|
183 |
return;
|
184 |
}
|
185 |
|
186 |
+
// Check if the model is ready
|
187 |
+
const modelReady = await checkModelReady();
|
188 |
+
if (!modelReady) {
|
189 |
+
return; // Don't continue if the model isn't ready
|
190 |
+
}
|
191 |
+
|
192 |
// Prepare the request data
|
193 |
const data = {
|
194 |
inputs: {
|
|
|
196 |
context: context // Should be a string
|
197 |
}
|
198 |
};
|
199 |
+
const cucu = window.huggingface.variables["API_KEY_2"];
|
200 |
console.log("key : " + cucu);
|
|
|
201 |
try {
|
202 |
const response = await fetch('https://api-inference.huggingface.co/models/distilbert-base-multilingual-cased', {
|
203 |
method: 'POST',
|
|
|
227 |
|
228 |
|
229 |
|
230 |
+
|