Spaces:
Running
Running
MarcosRodrigo
commited on
Commit
•
85201a3
1
Parent(s):
ada589a
Update index.html
Browse files- index.html +56 -19
index.html
CHANGED
@@ -1,19 +1,56 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Question-Answering Bot</title>
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
|
8 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/qna"></script>
|
9 |
+
</head>
|
10 |
+
<body>
|
11 |
+
<h1>Question-Answering Bot</h1>
|
12 |
+
<p>Enter the context text and ask a question about it.</p>
|
13 |
+
|
14 |
+
<textarea id="context" rows="10" cols="50" placeholder="Enter context here"></textarea><br><br>
|
15 |
+
<input type="text" id="question" placeholder="Enter your question"><br><br>
|
16 |
+
<button onclick="getAnswer()">Get Answer</button>
|
17 |
+
|
18 |
+
<div id="result"></div>
|
19 |
+
|
20 |
+
<script>
|
21 |
+
let model;
|
22 |
+
|
23 |
+
// Load the QnA model
|
24 |
+
qna.load().then((loadedModel) => {
|
25 |
+
model = loadedModel;
|
26 |
+
console.log('Model loaded');
|
27 |
+
});
|
28 |
+
|
29 |
+
async function getAnswer() {
|
30 |
+
const context = document.getElementById('context').value;
|
31 |
+
const question = document.getElementById('question').value;
|
32 |
+
const resultDiv = document.getElementById('result');
|
33 |
+
|
34 |
+
if (context && question) {
|
35 |
+
if (!model) {
|
36 |
+
resultDiv.innerHTML = "Model is still loading. Please wait and try again.";
|
37 |
+
return;
|
38 |
+
}
|
39 |
+
|
40 |
+
const answers = await model.findAnswers(question, context);
|
41 |
+
|
42 |
+
if (answers.length > 0) {
|
43 |
+
resultDiv.innerHTML = `
|
44 |
+
<p><strong>Question:</strong> ${question}</p>
|
45 |
+
<p><strong>Answer:</strong> ${answers[0].text}</p>
|
46 |
+
`;
|
47 |
+
} else {
|
48 |
+
resultDiv.innerHTML = "No answer found.";
|
49 |
+
}
|
50 |
+
} else {
|
51 |
+
resultDiv.innerHTML = "Please enter both the context and the question.";
|
52 |
+
}
|
53 |
+
}
|
54 |
+
</script>
|
55 |
+
</body>
|
56 |
+
</html>
|