Spaces:
Running
Running
Update test2.html
Browse files- test2.html +38 -14
test2.html
CHANGED
@@ -68,24 +68,48 @@
|
|
68 |
return;
|
69 |
}
|
70 |
|
71 |
-
//
|
72 |
-
const
|
73 |
-
const context = textoPDF;
|
74 |
-
|
75 |
-
// Usar un modelo preentrenado como BERT o T5 de HuggingFace
|
76 |
-
const response = await obtenerRespuestaDeModelo(question, context);
|
77 |
|
78 |
// Mostrar la respuesta
|
79 |
-
document.getElementById("respuesta").innerText = "Respuesta: " +
|
80 |
}
|
81 |
|
82 |
-
// Funci贸n para obtener respuesta utilizando el modelo de Hugging Face
|
83 |
-
async function obtenerRespuestaDeModelo(
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
const
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
}
|
90 |
</script>
|
91 |
</body>
|
|
|
68 |
return;
|
69 |
}
|
70 |
|
71 |
+
// Enviar la pregunta y el texto del PDF a la API de Hugging Face para obtener la respuesta
|
72 |
+
const respuesta = await obtenerRespuestaDeModelo(pregunta, textoPDF);
|
|
|
|
|
|
|
|
|
73 |
|
74 |
// Mostrar la respuesta
|
75 |
+
document.getElementById("respuesta").innerText = "Respuesta: " + respuesta;
|
76 |
}
|
77 |
|
78 |
+
// Funci贸n para obtener respuesta utilizando el modelo BERT de Hugging Face
|
79 |
+
async function obtenerRespuestaDeModelo(pregunta, contexto) {
|
80 |
+
const endpoint = "https://api-inference.huggingface.co/models/deepset/roberta-large-squad2"; // Usar el modelo BERT o RoBERTa preentrenado
|
81 |
+
const token = 'tu_token_de_huggingface'; // Sustituye con tu token de Hugging Face
|
82 |
+
|
83 |
+
const requestData = {
|
84 |
+
inputs: {
|
85 |
+
question: pregunta,
|
86 |
+
context: contexto
|
87 |
+
}
|
88 |
+
};
|
89 |
+
|
90 |
+
try {
|
91 |
+
const response = await fetch(endpoint, {
|
92 |
+
method: 'POST',
|
93 |
+
headers: {
|
94 |
+
'Authorization': `Bearer ${token}`,
|
95 |
+
'Content-Type': 'application/json'
|
96 |
+
},
|
97 |
+
body: JSON.stringify(requestData)
|
98 |
+
});
|
99 |
+
|
100 |
+
const data = await response.json();
|
101 |
+
|
102 |
+
// Extraer la respuesta del modelo
|
103 |
+
if (data && data.answer) {
|
104 |
+
return data.answer;
|
105 |
+
} else {
|
106 |
+
return "No se pudo encontrar una respuesta.";
|
107 |
+
}
|
108 |
+
|
109 |
+
} catch (error) {
|
110 |
+
console.error("Error al obtener la respuesta de Hugging Face:", error);
|
111 |
+
return "Error al obtener la respuesta.";
|
112 |
+
}
|
113 |
}
|
114 |
</script>
|
115 |
</body>
|