rabiyulfahim commited on
Commit
484d307
·
verified ·
1 Parent(s): 84f3de7

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +29 -14
static/index.html CHANGED
@@ -4,39 +4,54 @@
4
  <meta charset="utf-8" />
5
  <title>QA GPT2 Interface</title>
6
  <style>
7
- body { font-family: Arial, sans-serif; margin: 30px; }
8
- .container { max-width: 600px; margin: auto; }
9
- input, button { width: 100%; padding: 10px; margin-top: 10px; }
10
- pre { background: #f4f4f4; padding: 10px; border-radius: 5px; }
 
 
 
11
  </style>
12
  </head>
13
  <body>
14
  <div class="container">
15
  <h2>Ask GPT2</h2>
16
  <input id="question" placeholder="Type your question..." />
17
- <input id="tokens" type="number" value="50" min="1" max="200" />
18
  <button id="askBtn">Ask</button>
19
 
20
- <h3>Response:</h3>
21
- <pre id="response">No answer yet.</pre>
 
 
22
  </div>
23
 
24
  <script>
25
  document.getElementById("askBtn").addEventListener("click", async () => {
26
- const q = document.getElementById("question").value;
27
- const max = document.getElementById("tokens").value;
 
28
 
29
- document.getElementById("response").textContent = "Loading...";
 
 
 
 
 
30
 
31
  try {
32
- const resp = await fetch(`/answers?question=${encodeURIComponent(q)}&max_new_tokens=${max}`);
33
  const data = await resp.json();
34
- document.getElementById("response").textContent = JSON.stringify(data, null, 2);
 
 
 
 
 
35
  } catch (err) {
36
- document.getElementById("response").textContent = "Error: " + err;
37
  }
38
  });
39
  </script>
40
  </body>
41
  </html>
42
-
 
4
  <meta charset="utf-8" />
5
  <title>QA GPT2 Interface</title>
6
  <style>
7
+ body { font-family: Arial, sans-serif; margin: 30px; background: #f9f9f9; }
8
+ .container { max-width: 600px; margin: auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
9
+ input, button { width: 100%; padding: 10px; margin-top: 10px; border-radius: 5px; border: 1px solid #ccc; font-size: 16px; }
10
+ button { background-color: #007bff; color: white; border: none; cursor: pointer; }
11
+ button:hover { background-color: #0056b3; }
12
+ .card { background: #f4f4f4; padding: 15px; border-radius: 5px; margin-top: 15px; white-space: pre-wrap; }
13
+ h2, h3 { text-align: center; }
14
  </style>
15
  </head>
16
  <body>
17
  <div class="container">
18
  <h2>Ask GPT2</h2>
19
  <input id="question" placeholder="Type your question..." />
20
+ <input id="tokens" type="number" value="50" min="1" max="200" placeholder="Max tokens" />
21
  <button id="askBtn">Ask</button>
22
 
23
+ <div id="responseContainer">
24
+ <h3>Response:</h3>
25
+ <div id="response" class="card">No answer yet.</div>
26
+ </div>
27
  </div>
28
 
29
  <script>
30
  document.getElementById("askBtn").addEventListener("click", async () => {
31
+ const question = document.getElementById("question").value.trim();
32
+ const maxTokens = document.getElementById("tokens").value;
33
+ const responseEl = document.getElementById("response");
34
 
35
+ if (!question) {
36
+ responseEl.textContent = "Please enter a question.";
37
+ return;
38
+ }
39
+
40
+ responseEl.textContent = "Loading...";
41
 
42
  try {
43
+ const resp = await fetch(`/answers?question=${encodeURIComponent(question)}&max_new_tokens=${maxTokens}`);
44
  const data = await resp.json();
45
+
46
+ // Structured display
47
+ responseEl.innerHTML = `
48
+ <strong>Question:</strong> ${data.question}<br/><br/>
49
+ <strong>Answer:</strong><br/>${data.answer.replace(/\n/g, "<br/>")}
50
+ `;
51
  } catch (err) {
52
+ responseEl.textContent = "Error: " + err;
53
  }
54
  });
55
  </script>
56
  </body>
57
  </html>