forked from localminimum/QANet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
92 lines (85 loc) · 3.08 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script>
function hit(passage, question) {
var xhr = new XMLHttpRequest();
xhr.open("POST", '/answer', true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function () {
console.log(xhr.status);
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);
console.log(json.answer);
var ans = document.getElementById("answer");
ans.innerHTML = json.answer;
var textarea = document.getElementById("passage");
var index = textarea.value.indexOf(json.answer);
if (index >= 0)
textarea.focus();
textarea.setSelectionRange(index, index + json.answer.length);
}
};
var params = JSON.stringify({ "question": question, "passage": passage });
xhr.send(params);
console.log("sent");
}
</script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
</head>
<body>
<div class="container">
<br>
<div class="row">
<div class="col">
<h4>QANet for Machine Comprehension</h4>
</div>
</div>
<br>
<div class="row">
<div class="col-lg">
<div class="input-group">
<textarea class="form-control" id='passage' rows="15" placeholder='Your passage here'></textarea>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg">
<div class="input-group">
<textarea class="form-control" id='question' rows="2" placeholder='Your question here'></textarea>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg">
<div class="input-group">
<button class="btn btn-primary" id='GetAnswer'>Get Answer</button>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-lg">
<div class="input-group">
<p id='answer'>Your answer appears here</p>
</div>
</div>
</div>
</div>
<script>
var button = document.getElementById("GetAnswer");
button.onclick = function () {
var para = document.getElementById("passage");
var ques = document.getElementById("question");
console.log("hitting");
hit(para.value, ques.value);
};
</script>
</body>
</html>