Spaces:
Running
Running
Update preguntar-pdf.html
Browse files- preguntar-pdf.html +21 -9
preguntar-pdf.html
CHANGED
@@ -8,9 +8,6 @@
|
|
8 |
</head>
|
9 |
<body>
|
10 |
<h1>Ask Questions to the Model</h1>
|
11 |
-
<a href="entrenament-pdf.html" style="margin:5px;padding: 5px; border:1px solid green">Entrenament PDF</a>
|
12 |
-
<a href="preguntar-pdf.html" style="margin:5px;padding: 5px; border:1px solid green">Preguntar PDF</a>
|
13 |
-
<br><br>
|
14 |
<input type="text" id="question" placeholder="Type your question here">
|
15 |
<button id="askQuestion">Ask</button>
|
16 |
|
@@ -19,16 +16,20 @@
|
|
19 |
<script>
|
20 |
async function loadModel() {
|
21 |
try {
|
|
|
22 |
const model = await tf.loadLayersModel('localstorage://pdf-trained-model');
|
|
|
23 |
return model;
|
24 |
} catch (err) {
|
25 |
document.getElementById('response').textContent = 'Model not found. Train it first!';
|
|
|
26 |
throw err;
|
27 |
}
|
28 |
}
|
29 |
|
30 |
function tokenizeQuestion(question, tokenizer) {
|
31 |
const tokens = question.split(/\s+/);
|
|
|
32 |
return tokens.map(token => tokenizer[token] || 0);
|
33 |
}
|
34 |
|
@@ -56,18 +57,29 @@
|
|
56 |
return;
|
57 |
}
|
58 |
|
59 |
-
const paddedInput = tf.pad(
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
const predictionArray = await prediction.array();
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
} catch (err) {
|
66 |
responseElement.textContent = 'Error: Could not load model or process question.';
|
67 |
-
console.error(err);
|
68 |
}
|
69 |
});
|
70 |
-
console.log('Model keys in local storage:', Object.keys(localStorage));
|
71 |
</script>
|
72 |
</body>
|
73 |
</html>
|
|
|
|
8 |
</head>
|
9 |
<body>
|
10 |
<h1>Ask Questions to the Model</h1>
|
|
|
|
|
|
|
11 |
<input type="text" id="question" placeholder="Type your question here">
|
12 |
<button id="askQuestion">Ask</button>
|
13 |
|
|
|
16 |
<script>
|
17 |
async function loadModel() {
|
18 |
try {
|
19 |
+
console.log('Checking available models in local storage:', Object.keys(localStorage));
|
20 |
const model = await tf.loadLayersModel('localstorage://pdf-trained-model');
|
21 |
+
console.log('Model loaded successfully.');
|
22 |
return model;
|
23 |
} catch (err) {
|
24 |
document.getElementById('response').textContent = 'Model not found. Train it first!';
|
25 |
+
console.error('Error loading model:', err);
|
26 |
throw err;
|
27 |
}
|
28 |
}
|
29 |
|
30 |
function tokenizeQuestion(question, tokenizer) {
|
31 |
const tokens = question.split(/\s+/);
|
32 |
+
console.log('Tokens from question:', tokens);
|
33 |
return tokens.map(token => tokenizer[token] || 0);
|
34 |
}
|
35 |
|
|
|
57 |
return;
|
58 |
}
|
59 |
|
60 |
+
const paddedInput = tf.pad(
|
61 |
+
tf.tensor2d([input], [1, input.length]),
|
62 |
+
[[0, 0], [0, Math.max(0, 10 - input.length)]],
|
63 |
+
'constant'
|
64 |
+
);
|
65 |
|
66 |
+
console.log('Padded input for prediction:', paddedInput.arraySync());
|
|
|
67 |
|
68 |
+
try {
|
69 |
+
const prediction = model.predict(paddedInput);
|
70 |
+
const predictionArray = await prediction.array();
|
71 |
+
console.log('Prediction result:', predictionArray);
|
72 |
+
responseElement.textContent = `Model response: ${JSON.stringify(predictionArray)}`;
|
73 |
+
} catch (err) {
|
74 |
+
console.error('Prediction error:', err);
|
75 |
+
responseElement.textContent = 'Error during prediction.';
|
76 |
+
}
|
77 |
} catch (err) {
|
78 |
responseElement.textContent = 'Error: Could not load model or process question.';
|
79 |
+
console.error('Error in processing question:', err);
|
80 |
}
|
81 |
});
|
|
|
82 |
</script>
|
83 |
</body>
|
84 |
</html>
|
85 |
+
|