-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (56 loc) · 1.76 KB
/
script.js
File metadata and controls
60 lines (56 loc) · 1.76 KB
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
function uploadFiles() {
const lawFile = document.getElementById('lawFile').files[0];
const contractFile = document.getElementById('contractFile').files[0];
const lawFormData = new FormData();
lawFormData.append('lawFile', lawFile);
const contractFormData = new FormData();
contractFormData.append('contractFile', contractFile);
fetch('/upload-law', {
method: 'POST',
body: lawFormData
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to upload law file');
}
return response.json();
})
.then(lawData => {
console.log(lawData);
fetch('/upload-contract', {
method: 'POST',
body: contractFormData
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to upload contract file');
}
return response.json();
})
.then(contractData => {
console.log(contractData);
analyzeDocuments(lawData.text, contractData.text);
})
.catch(error => {
console.error('Error:', error);
});
})
.catch(error => {
console.error('Error:', error);
});
}
function analyzeDocuments(lawText, contractText) {
fetch('/analyze', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ law_text: lawText, contract_text: contractText })
})
.then(response => response.json())
.then(data => {
console.log(data);
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = JSON.stringify(data, null, 2);
});
}