MarcosRodrigo commited on
Commit
85201a3
1 Parent(s): ada589a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +56 -19
index.html CHANGED
@@ -1,19 +1,56 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>