-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
121 lines (111 loc) · 3.91 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://kit.fontawesome.com/yourcode.js" crossorigin="anonymous"></script>
<title>Test</title>
</head>
<body>
<style>
.center {
position: relative;
width: 90%;
text-align: center;
margin: auto;
}
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: bold;
font-family: 'Courier New', Courier, monospace;
transition: background-color 0.3s ease;
}
.button:hover {
background-color: #45a049; /* Darker green on hover */
}
label:hover {
background-color: #45a049; /* Darker green on hover */
}
img {
width: 30%;
height: auto;
}
input[type="file"] {
display: none;
}
.custom-file-upload {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
font-weight: 900;
font-family: 'Courier New', Courier, monospace;
}
p {
font-size: 16px;
font-weight: bold;
font-family: 'Courier New', Courier, monospace;
}
</style>
<script type="text/javascript">
function previewFile() {
const preview = document.getElementById('serverMsg');
var file = document.getElementById('fileInput').files[0];
const reader = new FileReader();
reader.addEventListener("load", function() {
preview.innerText = "File uploaded successfully:" + file.name + "\n Push the predict button to see suggestions."; // show image in <img> tag
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
function get_label_display(label) {
if (label < 1) {
return "Don't buy!";
} else {
return "Buy!";
}
}
function uploadFile(file) {
var file = document.getElementById('fileInput').files[0];
if (file) {
var formData = new FormData();
formData.append('file', file);
document.getElementById("serverMsg").innerHTML = "Waiting ..."
fetch('https://mlsd-indicatorss.darkube.app/predict', {
method: 'POST',
body: formData,
// credentials: "include",
})
.then(response => response.json())
.then(data => {
document.getElementById("serverMsg").innerHTML = "Suggestion: " + "<span style='color: light-green; font-weight: bolder;'>" + get_label_display(data.label) + "</span>"
})
.catch(error => {
console.error(error);
});
}
}
</script>
<div class="center" style="top: 20%;">
<label for="fileInput" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i> Upload .csv file
</label>
<input id="fileInput" type="file" onchange="previewFile()"/>
<input class="button" type="button" value="Predict the trend" onclick="uploadFile()">
<button class="button" onClick="window.location.reload();">Try new .csv</button>
<p id="serverMsg">Upload a .csv file and push the predict button.</p>
<!-- <img height="200"> -->
<p id="box"> </p>
</div>
</body>
</html>