Spaces:
Running
Running
Update test1.html
Browse files- test1.html +14 -11
test1.html
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
-
|
2 |
<html lang="es">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Modelo de Preguntas y Respuestas PDF</title>
|
7 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
|
|
|
|
|
|
|
|
|
8 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>
|
9 |
</head>
|
10 |
<body>
|
@@ -62,13 +66,12 @@
|
|
62 |
|
63 |
// Funci贸n para entrenar un modelo simple (esto es solo un ejemplo)
|
64 |
async function entrenarModelo(textoPDF) {
|
65 |
-
|
66 |
-
const
|
67 |
-
const inputs = tf.tensor(tokens);
|
68 |
|
69 |
// Aqu铆 simplemente estamos creando un modelo muy simple para ilustrar
|
70 |
const modelo = tf.sequential();
|
71 |
-
modelo.add(tf.layers.dense({ units: 64, inputShape: [
|
72 |
modelo.add(tf.layers.dense({ units: 32 }));
|
73 |
modelo.add(tf.layers.dense({ units: 1, activation: 'sigmoid' }));
|
74 |
|
@@ -102,13 +105,12 @@
|
|
102 |
async function responderPregunta() {
|
103 |
const pregunta = document.getElementById("inputPregunta").value;
|
104 |
if (modelo && pregunta) {
|
105 |
-
//
|
106 |
-
const
|
107 |
-
const
|
108 |
-
const input = tf.tensor(tokens);
|
109 |
|
110 |
const prediccion = modelo.predict(input);
|
111 |
-
document.getElementById("respuesta").innerText = prediccion.
|
112 |
} else {
|
113 |
alert("Por favor, cargue el PDF y entrene el modelo primero.");
|
114 |
}
|
@@ -116,3 +118,4 @@
|
|
116 |
</script>
|
117 |
</body>
|
118 |
</html>
|
|
|
|
1 |
+
<<!DOCTYPE html>
|
2 |
<html lang="es">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Modelo de Preguntas y Respuestas sobre un PDF</title>
|
7 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
|
8 |
+
<!-- Cargar PDF.js y especificar worker -->
|
9 |
+
<script>
|
10 |
+
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.worker.min.js";
|
11 |
+
</script>
|
12 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>
|
13 |
</head>
|
14 |
<body>
|
|
|
66 |
|
67 |
// Funci贸n para entrenar un modelo simple (esto es solo un ejemplo)
|
68 |
async function entrenarModelo(textoPDF) {
|
69 |
+
// Utilizar el texto extra铆do del PDF para crear un modelo simple
|
70 |
+
const inputs = tf.tensor([textoPDF.length]);
|
|
|
71 |
|
72 |
// Aqu铆 simplemente estamos creando un modelo muy simple para ilustrar
|
73 |
const modelo = tf.sequential();
|
74 |
+
modelo.add(tf.layers.dense({ units: 64, inputShape: [1] }));
|
75 |
modelo.add(tf.layers.dense({ units: 32 }));
|
76 |
modelo.add(tf.layers.dense({ units: 1, activation: 'sigmoid' }));
|
77 |
|
|
|
105 |
async function responderPregunta() {
|
106 |
const pregunta = document.getElementById("inputPregunta").value;
|
107 |
if (modelo && pregunta) {
|
108 |
+
// Aqu铆 usamos un enfoque simple para tokenizar la pregunta
|
109 |
+
const tokens = pregunta.split(" "); // Simple divisi贸n en palabras
|
110 |
+
const input = tf.tensor([tokens.length]);
|
|
|
111 |
|
112 |
const prediccion = modelo.predict(input);
|
113 |
+
document.getElementById("respuesta").innerText = `Respuesta: ${prediccion.dataSync()}`;
|
114 |
} else {
|
115 |
alert("Por favor, cargue el PDF y entrene el modelo primero.");
|
116 |
}
|
|
|
118 |
</script>
|
119 |
</body>
|
120 |
</html>
|
121 |
+
|