Spaces:
Running
Running
feat: add static html
Browse files- index.html +199 -0
- restful/utilities.py +1 -1
index.html
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Cryptocurrency Price Prediction</title>
|
8 |
+
|
9 |
+
<link rel="shortcut icon" type="image/x-icon" href="https://raw.githubusercontent.com/belajarqywok/belajarqywok.github.io/main/favicon.ico">
|
10 |
+
|
11 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
12 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
13 |
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
|
14 |
+
</head>
|
15 |
+
|
16 |
+
<body onload="predict()">
|
17 |
+
|
18 |
+
<header class="bg-dark py-3 mb-4">
|
19 |
+
<div class="container">
|
20 |
+
<div class="row">
|
21 |
+
<div class="col">
|
22 |
+
<h1 class="text-white">Cryptocurrency Price Prediction</h1>
|
23 |
+
</div>
|
24 |
+
</div>
|
25 |
+
</div>
|
26 |
+
</header>
|
27 |
+
|
28 |
+
<div class="container">
|
29 |
+
<div class="card shadow-sm">
|
30 |
+
<div class="card-body">
|
31 |
+
<div class="row mb-3">
|
32 |
+
<div class="col-md-3">
|
33 |
+
<label for="days" class="form-label">Days to Predict:</label>
|
34 |
+
<input type="number" id="days" name="days" class="form-control" min="1" value="7" onchange="predict()">
|
35 |
+
</div>
|
36 |
+
<div class="col-md-3">
|
37 |
+
<label for="crypto" class="form-label">Cryptocurrency:</label>
|
38 |
+
<select id="crypto" class="form-select" onchange="predict()">
|
39 |
+
<option value="ADA-USD">ADA-USD</option>
|
40 |
+
</select>
|
41 |
+
</div>
|
42 |
+
<div class="col-md-3 align-self-end">
|
43 |
+
<div class="spinner-border text-primary d-none" role="status" id="loadingSpinner">
|
44 |
+
<span class="visually-hidden">Loading...</span>
|
45 |
+
</div>
|
46 |
+
</div>
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
|
51 |
+
<div class="row mt-4">
|
52 |
+
<div class="col">
|
53 |
+
<canvas id="myChart" width="400" height="200"></canvas>
|
54 |
+
</div>
|
55 |
+
</div>
|
56 |
+
</div>
|
57 |
+
<br \>
|
58 |
+
|
59 |
+
<script>
|
60 |
+
fetch('https://qywok-cryptocurrency-prediction.hf.space/crypto/lists')
|
61 |
+
.then(response => response.json())
|
62 |
+
.then(data => {
|
63 |
+
const cryptoList = data.data
|
64 |
+
const selectCrypto = document.getElementById('crypto')
|
65 |
+
|
66 |
+
selectCrypto.innerHTML = ''
|
67 |
+
cryptoList.forEach(crypto => {
|
68 |
+
const option = document.createElement('option')
|
69 |
+
option.value = crypto
|
70 |
+
option.text = crypto
|
71 |
+
|
72 |
+
selectCrypto.appendChild(option)
|
73 |
+
})
|
74 |
+
})
|
75 |
+
.catch(error => console.error('Error fetching crypto list:', error))
|
76 |
+
</script>
|
77 |
+
|
78 |
+
<script>
|
79 |
+
let myChart
|
80 |
+
|
81 |
+
const predict = async () => {
|
82 |
+
const days = document.getElementById('days').value
|
83 |
+
const crypto = document.getElementById('crypto').value
|
84 |
+
const loadingSpinner = document.getElementById('loadingSpinner')
|
85 |
+
loadingSpinner.classList.remove('d-none')
|
86 |
+
|
87 |
+
const apiUrl = 'https://qywok-cryptocurrency-prediction.hf.space/crypto/prediction'
|
88 |
+
|
89 |
+
try {
|
90 |
+
const response = await fetch(apiUrl, {
|
91 |
+
method: 'POST',
|
92 |
+
headers: {
|
93 |
+
'Accept': 'application/json',
|
94 |
+
'Content-Type': 'application/json'
|
95 |
+
},
|
96 |
+
body: JSON.stringify({
|
97 |
+
days: days,
|
98 |
+
currency: crypto
|
99 |
+
})
|
100 |
+
})
|
101 |
+
|
102 |
+
if (!response.ok) throw new Error('Network response was not ok')
|
103 |
+
|
104 |
+
const data = await response.json()
|
105 |
+
updateChart(data)
|
106 |
+
|
107 |
+
} catch (error) {
|
108 |
+
console.error('Error fetching data:', error)
|
109 |
+
} finally {
|
110 |
+
loadingSpinner.classList.add('d-none')
|
111 |
+
}
|
112 |
+
}
|
113 |
+
</script>
|
114 |
+
|
115 |
+
<script>
|
116 |
+
const updateChart = (data) => {
|
117 |
+
const actualDates = data.data.predictions
|
118 |
+
.actuals.map(entry => new Date(entry.date))
|
119 |
+
|
120 |
+
const actualPrices = data.data.predictions
|
121 |
+
.actuals.map(entry => entry.price)
|
122 |
+
|
123 |
+
const predictionDates = data.data.predictions
|
124 |
+
.predictions.map(entry => new Date(entry.date))
|
125 |
+
|
126 |
+
const predictionPrices = data.data.predictions
|
127 |
+
.predictions.map(entry => entry.price)
|
128 |
+
|
129 |
+
const dates = [...actualDates, ...predictionDates]
|
130 |
+
const prices = [...actualPrices, ...predictionPrices]
|
131 |
+
|
132 |
+
if (myChart) {
|
133 |
+
myChart.data.labels = dates
|
134 |
+
myChart.data.datasets[0].data = actualDates.map(
|
135 |
+
(date, index) => ({ x: date, y: actualPrices[index] })
|
136 |
+
)
|
137 |
+
|
138 |
+
myChart.data.datasets[1].data = predictionDates.map(
|
139 |
+
(date, index) => ({ x: date, y: predictionPrices[index] })
|
140 |
+
)
|
141 |
+
|
142 |
+
myChart.update()
|
143 |
+
} else {
|
144 |
+
const ctx = document.getElementById('myChart').getContext('2d')
|
145 |
+
myChart = new Chart(ctx, {
|
146 |
+
type: 'line',
|
147 |
+
data: {
|
148 |
+
labels: dates,
|
149 |
+
datasets: [
|
150 |
+
{
|
151 |
+
label: 'Actual',
|
152 |
+
data: actualDates.map(
|
153 |
+
(date, index) => ({ x: date, y: actualPrices[index] })
|
154 |
+
),
|
155 |
+
borderColor: 'rgba(75, 192, 192, 1)',
|
156 |
+
borderWidth: 1,
|
157 |
+
fill: false,
|
158 |
+
tension: 0.1
|
159 |
+
},
|
160 |
+
{
|
161 |
+
label: 'Prediction',
|
162 |
+
data: predictionDates.map(
|
163 |
+
(date, index) => ({ x: date, y: predictionPrices[index] })
|
164 |
+
),
|
165 |
+
borderColor: 'rgba(255, 99, 132, 1)',
|
166 |
+
borderWidth: 1,
|
167 |
+
fill: false,
|
168 |
+
tension: 0.1
|
169 |
+
}
|
170 |
+
]
|
171 |
+
},
|
172 |
+
options: {
|
173 |
+
scales: {
|
174 |
+
x: {
|
175 |
+
type: 'time',
|
176 |
+
time: {
|
177 |
+
unit: 'day',
|
178 |
+
tooltipFormat: 'yyyy-MM-dd'
|
179 |
+
},
|
180 |
+
title: {
|
181 |
+
display: true,
|
182 |
+
text: 'Date'
|
183 |
+
}
|
184 |
+
},
|
185 |
+
y: {
|
186 |
+
beginAtZero: false,
|
187 |
+
title: {
|
188 |
+
display: true,
|
189 |
+
text: 'Price (USD)'
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
}
|
194 |
+
})
|
195 |
+
}
|
196 |
+
}
|
197 |
+
</script>
|
198 |
+
</body>
|
199 |
+
</html>
|
restful/utilities.py
CHANGED
@@ -13,7 +13,7 @@ class Utilities:
|
|
13 |
self.scaler_path = './pickles'
|
14 |
|
15 |
async def cryptocurrency_prediction_utils(self,
|
16 |
-
days: int,sequence_length: int, model_name: str) -> tuple:
|
17 |
model_path = os.path.join(self.model_path, f'{model_name}.keras')
|
18 |
model = load_model(model_path)
|
19 |
|
|
|
13 |
self.scaler_path = './pickles'
|
14 |
|
15 |
async def cryptocurrency_prediction_utils(self,
|
16 |
+
days: int, sequence_length: int, model_name: str) -> tuple:
|
17 |
model_path = os.path.join(self.model_path, f'{model_name}.keras')
|
18 |
model = load_model(model_path)
|
19 |
|