Alleinzellgaenger commited on
Commit
9c67f19
·
1 Parent(s): 28c07ab

Frontend changes

Browse files
Files changed (2) hide show
  1. frontend/script.js +35 -0
  2. frontend/styles.css +24 -0
frontend/script.js CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Listen for form submission
2
+ document.getElementById('textForm').addEventListener('submit', async (e) => {
3
+ e.preventDefault(); // Prevent page refresh
4
+ const inputText = document.getElementById('inputText').value;
5
+
6
+ try {
7
+ // Send a POST request to the /process endpoint
8
+ const response = await fetch('/process', {
9
+ method: 'POST',
10
+ headers: { 'Content-Type': 'application/json' },
11
+ body: JSON.stringify({ text: inputText })
12
+ });
13
+
14
+ if (!response.ok) {
15
+ throw new Error('Network response was not ok');
16
+ }
17
+ const data = await response.json();
18
+ displayOutput(data);
19
+ } catch (error) {
20
+ console.error('Error:', error);
21
+ document.getElementById('output').innerText = 'Error processing text.';
22
+ }
23
+ });
24
+
25
+ // Function to display the tokens and attention values
26
+ function displayOutput(data) {
27
+ const outputDiv = document.getElementById('output');
28
+ outputDiv.innerHTML = `
29
+ <h2>Tokens</h2>
30
+ <pre>${JSON.stringify(data.tokens, null, 2)}</pre>
31
+ <h2>Attention</h2>
32
+ <pre>${JSON.stringify(data.attention, null, 2)}</pre>
33
+ `;
34
+ }
35
+
frontend/styles.css CHANGED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial, sans-serif;
3
+ margin: 20px;
4
+ background-color: #f4f4f4;
5
+ }
6
+
7
+ h1 {
8
+ color: #333;
9
+ }
10
+
11
+ textarea {
12
+ width: 100%;
13
+ max-width: 600px;
14
+ }
15
+
16
+ #output {
17
+ margin-top: 20px;
18
+ padding: 10px;
19
+ background-color: #fff;
20
+ border: 1px solid #ddd;
21
+ max-width: 600px;
22
+ overflow-x: auto;
23
+ }
24
+