Spaces:
Running
Running
Update index.html
Browse files- index.html +628 -592
index.html
CHANGED
|
@@ -1,604 +1,640 @@
|
|
| 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 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
>
|
| 266 |
-
<Brain className="h-5 w-5" />
|
| 267 |
-
<span>Train AI Model</span>
|
| 268 |
-
</button>
|
| 269 |
-
)}
|
| 270 |
-
</div>
|
| 271 |
</div>
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
<
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
<
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
</div>
|
| 305 |
-
)}
|
| 306 |
-
|
| 307 |
-
{trainingMetrics && (
|
| 308 |
-
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
| 309 |
-
<div className="bg-gradient-to-r from-emerald-500/20 to-emerald-600/20 rounded-xl p-4 border border-emerald-500/30">
|
| 310 |
-
<div className="text-2xl font-bold text-emerald-400">{trainingMetrics.accuracy}%</div>
|
| 311 |
-
<div className="text-sm text-slate-300">Training Accuracy</div>
|
| 312 |
-
</div>
|
| 313 |
-
<div className="bg-gradient-to-r from-blue-500/20 to-blue-600/20 rounded-xl p-4 border border-blue-500/30">
|
| 314 |
-
<div className="text-2xl font-bold text-blue-400">{trainingMetrics.valAccuracy}%</div>
|
| 315 |
-
<div className="text-sm text-slate-300">Validation Accuracy</div>
|
| 316 |
-
</div>
|
| 317 |
-
<div className="bg-gradient-to-r from-purple-500/20 to-purple-600/20 rounded-xl p-4 border border-purple-500/30">
|
| 318 |
-
<div className="text-2xl font-bold text-purple-400">{trainingMetrics.loss}</div>
|
| 319 |
-
<div className="text-sm text-slate-300">Training Loss</div>
|
| 320 |
-
</div>
|
| 321 |
-
<div className="bg-gradient-to-r from-pink-500/20 to-pink-600/20 rounded-xl p-4 border border-pink-500/30">
|
| 322 |
-
<div className="text-2xl font-bold text-pink-400">{trainingMetrics.valLoss}</div>
|
| 323 |
-
<div className="text-sm text-slate-300">Validation Loss</div>
|
| 324 |
-
</div>
|
| 325 |
-
</div>
|
| 326 |
-
)}
|
| 327 |
-
|
| 328 |
-
{trainingHistory.length > 0 && (
|
| 329 |
-
<div className="h-64">
|
| 330 |
-
<ResponsiveContainer width="100%" height="100%">
|
| 331 |
-
<LineChart data={trainingHistory}>
|
| 332 |
-
<CartesianGrid strokeDasharray="3 3" stroke="#374151" />
|
| 333 |
-
<XAxis dataKey="epoch" stroke="#9CA3AF" />
|
| 334 |
-
<YAxis stroke="#9CA3AF" />
|
| 335 |
-
<Tooltip
|
| 336 |
-
contentStyle={{
|
| 337 |
-
backgroundColor: '#1F2937',
|
| 338 |
-
border: '1px solid #374151',
|
| 339 |
-
borderRadius: '8px',
|
| 340 |
-
color: '#F3F4F6'
|
| 341 |
-
}}
|
| 342 |
-
/>
|
| 343 |
-
<Line type="monotone" dataKey="accuracy" stroke="#10B981" strokeWidth={2} dot={false} />
|
| 344 |
-
<Line type="monotone" dataKey="valAccuracy" stroke="#3B82F6" strokeWidth={2} dot={false} />
|
| 345 |
-
</LineChart>
|
| 346 |
-
</ResponsiveContainer>
|
| 347 |
</div>
|
| 348 |
-
)}
|
| 349 |
</div>
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
<div className="flex items-center justify-between">
|
| 358 |
-
<div>
|
| 359 |
-
<p className="text-slate-300 text-sm">Total Invoices</p>
|
| 360 |
-
<p className="text-3xl font-bold text-blue-400">{dashboardStats.totalInvoices}</p>
|
| 361 |
</div>
|
| 362 |
-
<Users className="h-8 w-8 text-blue-400" />
|
| 363 |
-
</div>
|
| 364 |
</div>
|
| 365 |
-
|
| 366 |
-
<div
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
<
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
| 374 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
<div className="mb-8">
|
| 401 |
-
<div className="flex space-x-1 bg-white/5 p-1 rounded-xl">
|
| 402 |
-
{[
|
| 403 |
-
{ key: 'overview', label: 'Overview', icon: BarChart3 },
|
| 404 |
-
{ key: 'predictions', label: 'Predictions', icon: Brain },
|
| 405 |
-
{ key: 'analytics', label: 'Analytics', icon: TrendingUp }
|
| 406 |
-
].map(({ key, label, icon: Icon }) => (
|
| 407 |
-
<button
|
| 408 |
-
key={key}
|
| 409 |
-
onClick={() => setActiveTab(key)}
|
| 410 |
-
className={`flex items-center space-x-2 px-4 py-2 rounded-lg transition-all duration-200 ${
|
| 411 |
-
activeTab === key
|
| 412 |
-
? 'bg-gradient-to-r from-blue-600 to-purple-600 text-white shadow-lg'
|
| 413 |
-
: 'text-slate-300 hover:text-white hover:bg-white/10'
|
| 414 |
-
}`}
|
| 415 |
-
>
|
| 416 |
-
<Icon className="h-4 w-4" />
|
| 417 |
-
<span>{label}</span>
|
| 418 |
-
</button>
|
| 419 |
-
))}
|
| 420 |
-
</div>
|
| 421 |
-
</div>
|
| 422 |
-
)}
|
| 423 |
-
|
| 424 |
-
{/* Tab Content */}
|
| 425 |
-
{predictions.length > 0 && (
|
| 426 |
-
<div className="space-y-6">
|
| 427 |
-
{activeTab === 'overview' && (
|
| 428 |
-
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
| 429 |
-
<div className="bg-white/10 backdrop-blur-md rounded-2xl border border-white/20 p-6">
|
| 430 |
-
<h3 className="text-lg font-semibold text-white mb-4">Risk Distribution</h3>
|
| 431 |
-
<div className="h-64">
|
| 432 |
-
<ResponsiveContainer width="100%" height="100%">
|
| 433 |
-
<PieChart>
|
| 434 |
-
<Pie
|
| 435 |
-
data={riskDistribution}
|
| 436 |
-
cx="50%"
|
| 437 |
-
cy="50%"
|
| 438 |
-
labelLine={false}
|
| 439 |
-
outerRadius={80}
|
| 440 |
-
fill="#8884d8"
|
| 441 |
-
dataKey="value"
|
| 442 |
-
label={({ name, percent }) => `${name} ${(percent * 100).toFixed(0)}%`}
|
| 443 |
-
>
|
| 444 |
-
{riskDistribution.map((entry, index) => (
|
| 445 |
-
<Cell key={`cell-${index}`} fill={entry.color} />
|
| 446 |
-
))}
|
| 447 |
-
</Pie>
|
| 448 |
-
<Tooltip />
|
| 449 |
-
</PieChart>
|
| 450 |
-
</ResponsiveContainer>
|
| 451 |
-
</div>
|
| 452 |
-
</div>
|
| 453 |
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
</thead>
|
| 504 |
-
<tbody
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
}`}>
|
| 523 |
-
{prediction.prediction}
|
| 524 |
-
</span>
|
| 525 |
-
</div>
|
| 526 |
-
</td>
|
| 527 |
-
<td className="px-6 py-4">
|
| 528 |
-
<div className="flex items-center space-x-3">
|
| 529 |
-
<div className="flex-1 bg-slate-700 rounded-full h-2">
|
| 530 |
-
<div
|
| 531 |
-
className={`h-2 rounded-full ${getProbabilityColor(prediction.probability)}`}
|
| 532 |
-
style={{ width: `${prediction.probability * 100}%` }}
|
| 533 |
-
></div>
|
| 534 |
-
</div>
|
| 535 |
-
<span className="text-sm text-slate-300 font-medium min-w-[50px]">
|
| 536 |
-
{(prediction.probability * 100).toFixed(1)}%
|
| 537 |
-
</span>
|
| 538 |
-
</div>
|
| 539 |
-
</td>
|
| 540 |
-
<td className="px-6 py-4">
|
| 541 |
-
<span className={`inline-flex px-2 py-1 rounded-full text-xs font-medium ${getRiskColor(prediction.riskLevel)}`}>
|
| 542 |
-
{prediction.riskLevel} Risk
|
| 543 |
</span>
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
backgroundColor: '#1F2937',
|
| 566 |
-
border: '1px solid #374151',
|
| 567 |
-
borderRadius: '8px',
|
| 568 |
-
color: '#F3F4F6'
|
| 569 |
-
}}
|
| 570 |
-
/>
|
| 571 |
-
<Line
|
| 572 |
-
type="monotone"
|
| 573 |
-
dataKey="probability"
|
| 574 |
-
stroke="#3B82F6"
|
| 575 |
-
strokeWidth={3}
|
| 576 |
-
dot={{ fill: '#3B82F6', strokeWidth: 2, r: 4 }}
|
| 577 |
-
/>
|
| 578 |
-
</LineChart>
|
| 579 |
-
</ResponsiveContainer>
|
| 580 |
-
</div>
|
| 581 |
-
</div>
|
| 582 |
-
</div>
|
| 583 |
-
)}
|
| 584 |
-
</div>
|
| 585 |
-
)}
|
| 586 |
-
|
| 587 |
-
{/* No predictions state */}
|
| 588 |
-
{!isTraining && !model && predictions.length === 0 && (
|
| 589 |
-
<div className="text-center py-16">
|
| 590 |
-
<div className="mb-8">
|
| 591 |
-
<Brain className="h-24 w-24 text-slate-400 mx-auto mb-4" />
|
| 592 |
-
<h3 className="text-2xl font-bold text-white mb-2">Ready to Get Started</h3>
|
| 593 |
-
<p className="text-slate-300 max-w-md mx-auto">
|
| 594 |
-
Train our advanced neural network on synthetic SAP Account Receivable data to predict invoice payment outcomes with high accuracy.
|
| 595 |
-
</p>
|
| 596 |
-
</div>
|
| 597 |
-
</div>
|
| 598 |
-
)}
|
| 599 |
-
</div>
|
| 600 |
-
</div>
|
| 601 |
-
);
|
| 602 |
-
};
|
| 603 |
-
|
| 604 |
-
export default ModernSAPDemo;
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>SAP AR ML Demo</title>
|
| 7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/tensorflow/4.10.0/tf.min.js"></script>
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
* {
|
| 11 |
+
margin: 0;
|
| 12 |
+
padding: 0;
|
| 13 |
+
box-sizing: border-box;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
body {
|
| 17 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 18 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 19 |
+
min-height: 100vh;
|
| 20 |
+
color: #333;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.container {
|
| 24 |
+
max-width: 1400px;
|
| 25 |
+
margin: 0 auto;
|
| 26 |
+
padding: 20px;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.header {
|
| 30 |
+
text-align: center;
|
| 31 |
+
margin-bottom: 30px;
|
| 32 |
+
color: white;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.header h1 {
|
| 36 |
+
font-size: 2.5rem;
|
| 37 |
+
margin-bottom: 10px;
|
| 38 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.header p {
|
| 42 |
+
font-size: 1.1rem;
|
| 43 |
+
opacity: 0.9;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.dashboard {
|
| 47 |
+
display: grid;
|
| 48 |
+
grid-template-columns: 1fr 1fr;
|
| 49 |
+
gap: 20px;
|
| 50 |
+
margin-bottom: 30px;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.card {
|
| 54 |
+
background: rgba(255, 255, 255, 0.95);
|
| 55 |
+
border-radius: 15px;
|
| 56 |
+
padding: 25px;
|
| 57 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
| 58 |
+
backdrop-filter: blur(10px);
|
| 59 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.card h3 {
|
| 63 |
+
color: #4a5568;
|
| 64 |
+
margin-bottom: 15px;
|
| 65 |
+
font-size: 1.3rem;
|
| 66 |
+
display: flex;
|
| 67 |
+
align-items: center;
|
| 68 |
+
gap: 10px;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.btn {
|
| 72 |
+
background: linear-gradient(135deg, #4CAF50, #45a049);
|
| 73 |
+
color: white;
|
| 74 |
+
padding: 12px 24px;
|
| 75 |
+
border: none;
|
| 76 |
+
border-radius: 8px;
|
| 77 |
+
cursor: pointer;
|
| 78 |
+
font-size: 1rem;
|
| 79 |
+
font-weight: 600;
|
| 80 |
+
transition: all 0.3s ease;
|
| 81 |
+
box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
.btn:hover {
|
| 85 |
+
transform: translateY(-2px);
|
| 86 |
+
box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.btn:disabled {
|
| 90 |
+
background: #ccc;
|
| 91 |
+
cursor: not-allowed;
|
| 92 |
+
transform: none;
|
| 93 |
+
box-shadow: none;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.btn-primary {
|
| 97 |
+
background: linear-gradient(135deg, #007bff, #0056b3);
|
| 98 |
+
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.btn-primary:hover {
|
| 102 |
+
box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.status {
|
| 106 |
+
padding: 10px 15px;
|
| 107 |
+
border-radius: 8px;
|
| 108 |
+
margin: 10px 0;
|
| 109 |
+
font-weight: 500;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.status.success {
|
| 113 |
+
background: #d4edda;
|
| 114 |
+
color: #155724;
|
| 115 |
+
border: 1px solid #c3e6cb;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.status.info {
|
| 119 |
+
background: #d1ecf1;
|
| 120 |
+
color: #0c5460;
|
| 121 |
+
border: 1px solid #bee5eb;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.status.warning {
|
| 125 |
+
background: #fff3cd;
|
| 126 |
+
color: #856404;
|
| 127 |
+
border: 1px solid #ffeaa7;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.progress-bar {
|
| 131 |
+
width: 100%;
|
| 132 |
+
height: 20px;
|
| 133 |
+
background: #e9ecef;
|
| 134 |
+
border-radius: 10px;
|
| 135 |
+
overflow: hidden;
|
| 136 |
+
margin: 10px 0;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.progress-fill {
|
| 140 |
+
height: 100%;
|
| 141 |
+
background: linear-gradient(90deg, #4CAF50, #45a049);
|
| 142 |
+
transition: width 0.3s ease;
|
| 143 |
+
border-radius: 10px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.invoice-table {
|
| 147 |
+
width: 100%;
|
| 148 |
+
border-collapse: collapse;
|
| 149 |
+
margin-top: 15px;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.invoice-table th,
|
| 153 |
+
.invoice-table td {
|
| 154 |
+
padding: 12px;
|
| 155 |
+
text-align: left;
|
| 156 |
+
border-bottom: 1px solid #e9ecef;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.invoice-table th {
|
| 160 |
+
background: #f8f9fa;
|
| 161 |
+
font-weight: 600;
|
| 162 |
+
color: #495057;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.invoice-table tr:hover {
|
| 166 |
+
background: #f8f9fa;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.prediction {
|
| 170 |
+
display: flex;
|
| 171 |
+
align-items: center;
|
| 172 |
+
gap: 10px;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
.probability-bar {
|
| 176 |
+
flex: 1;
|
| 177 |
+
height: 20px;
|
| 178 |
+
background: #e9ecef;
|
| 179 |
+
border-radius: 10px;
|
| 180 |
+
overflow: hidden;
|
| 181 |
+
position: relative;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.probability-fill {
|
| 185 |
+
height: 100%;
|
| 186 |
+
border-radius: 10px;
|
| 187 |
+
transition: width 0.3s ease;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.high-prob {
|
| 191 |
+
background: linear-gradient(90deg, #28a745, #20c997);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.medium-prob {
|
| 195 |
+
background: linear-gradient(90deg, #ffc107, #fd7e14);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
.low-prob {
|
| 199 |
+
background: linear-gradient(90deg, #dc3545, #e74c3c);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.full-width {
|
| 203 |
+
grid-column: 1 / -1;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.metrics {
|
| 207 |
+
display: grid;
|
| 208 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 209 |
+
gap: 15px;
|
| 210 |
+
margin-top: 15px;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.metric-card {
|
| 214 |
+
background: #f8f9fa;
|
| 215 |
+
padding: 15px;
|
| 216 |
+
border-radius: 10px;
|
| 217 |
+
text-align: center;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
.metric-value {
|
| 221 |
+
font-size: 2rem;
|
| 222 |
+
font-weight: bold;
|
| 223 |
+
color: #007bff;
|
| 224 |
+
margin-bottom: 5px;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.metric-label {
|
| 228 |
+
color: #6c757d;
|
| 229 |
+
font-size: 0.9rem;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
.chart-container {
|
| 233 |
+
width: 100%;
|
| 234 |
+
height: 300px;
|
| 235 |
+
margin-top: 20px;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
.loading {
|
| 239 |
+
display: inline-block;
|
| 240 |
+
width: 20px;
|
| 241 |
+
height: 20px;
|
| 242 |
+
border: 3px solid #f3f3f3;
|
| 243 |
+
border-top: 3px solid #3498db;
|
| 244 |
+
border-radius: 50%;
|
| 245 |
+
animation: spin 1s linear infinite;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
@keyframes spin {
|
| 249 |
+
0% { transform: rotate(0deg); }
|
| 250 |
+
100% { transform: rotate(360deg); }
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
.icon {
|
| 254 |
+
width: 20px;
|
| 255 |
+
height: 20px;
|
| 256 |
+
display: inline-block;
|
| 257 |
+
}
|
| 258 |
+
</style>
|
| 259 |
+
</head>
|
| 260 |
+
<body>
|
| 261 |
+
<div class="container">
|
| 262 |
+
<div class="header">
|
| 263 |
+
<h1>🏢 SAP Account Receivable ML Prediction Demo</h1>
|
| 264 |
+
<p>Machine Learning-powered invoice payment prediction system</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
</div>
|
| 266 |
+
|
| 267 |
+
<div class="dashboard">
|
| 268 |
+
<div class="card">
|
| 269 |
+
<h3>
|
| 270 |
+
🎯 Model Training
|
| 271 |
+
</h3>
|
| 272 |
+
<p>Train a machine learning model on synthetic SAP AR data to predict invoice payment likelihood.</p>
|
| 273 |
+
|
| 274 |
+
<button id="trainBtn" class="btn" onclick="trainModel()">
|
| 275 |
+
<span id="trainBtnText">Train ML Model</span>
|
| 276 |
+
</button>
|
| 277 |
+
|
| 278 |
+
<div id="trainingStatus"></div>
|
| 279 |
+
<div id="trainingProgress"></div>
|
| 280 |
+
|
| 281 |
+
<div id="modelMetrics" class="metrics" style="display: none;">
|
| 282 |
+
<div class="metric-card">
|
| 283 |
+
<div class="metric-value" id="accuracy">-</div>
|
| 284 |
+
<div class="metric-label">Accuracy</div>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="metric-card">
|
| 287 |
+
<div class="metric-value" id="precision">-</div>
|
| 288 |
+
<div class="metric-label">Precision</div>
|
| 289 |
+
</div>
|
| 290 |
+
<div class="metric-card">
|
| 291 |
+
<div class="metric-value" id="recall">-</div>
|
| 292 |
+
<div class="metric-label">Recall</div>
|
| 293 |
+
</div>
|
| 294 |
+
<div class="metric-card">
|
| 295 |
+
<div class="metric-value" id="f1Score">-</div>
|
| 296 |
+
<div class="metric-label">F1 Score</div>
|
| 297 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
</div>
|
|
|
|
| 299 |
</div>
|
| 300 |
+
|
| 301 |
+
<div class="card">
|
| 302 |
+
<h3>
|
| 303 |
+
📊 Training Visualization
|
| 304 |
+
</h3>
|
| 305 |
+
<div class="chart-container">
|
| 306 |
+
<canvas id="trainingChart" width="400" height="200"></canvas>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
</div>
|
|
|
|
|
|
|
| 308 |
</div>
|
| 309 |
+
|
| 310 |
+
<div class="card full-width">
|
| 311 |
+
<h3>
|
| 312 |
+
🔮 Invoice Payment Predictions
|
| 313 |
+
</h3>
|
| 314 |
+
<p>Real-time predictions for unpaid invoices using the trained ML model.</p>
|
| 315 |
+
|
| 316 |
+
<button id="predictBtn" class="btn btn-primary" onclick="makePredictions()" disabled>
|
| 317 |
+
Generate Predictions
|
| 318 |
+
</button>
|
| 319 |
+
|
| 320 |
+
<div id="predictionsTable"></div>
|
| 321 |
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
+
<script>
|
| 326 |
+
let model = null;
|
| 327 |
+
let trainingData = null;
|
| 328 |
+
let chart = null;
|
| 329 |
+
let unpaidInvoices = [];
|
| 330 |
+
|
| 331 |
+
// Initialize chart
|
| 332 |
+
const ctx = document.getElementById('trainingChart').getContext('2d');
|
| 333 |
+
chart = new Chart(ctx, {
|
| 334 |
+
type: 'line',
|
| 335 |
+
data: {
|
| 336 |
+
labels: [],
|
| 337 |
+
datasets: [{
|
| 338 |
+
label: 'Training Accuracy',
|
| 339 |
+
data: [],
|
| 340 |
+
borderColor: '#007bff',
|
| 341 |
+
backgroundColor: 'rgba(0, 123, 255, 0.1)',
|
| 342 |
+
tension: 0.4
|
| 343 |
+
}, {
|
| 344 |
+
label: 'Training Loss',
|
| 345 |
+
data: [],
|
| 346 |
+
borderColor: '#dc3545',
|
| 347 |
+
backgroundColor: 'rgba(220, 53, 69, 0.1)',
|
| 348 |
+
tension: 0.4,
|
| 349 |
+
yAxisID: 'y1'
|
| 350 |
+
}]
|
| 351 |
+
},
|
| 352 |
+
options: {
|
| 353 |
+
responsive: true,
|
| 354 |
+
maintainAspectRatio: false,
|
| 355 |
+
scales: {
|
| 356 |
+
y: {
|
| 357 |
+
type: 'linear',
|
| 358 |
+
display: true,
|
| 359 |
+
position: 'left',
|
| 360 |
+
min: 0,
|
| 361 |
+
max: 1
|
| 362 |
+
},
|
| 363 |
+
y1: {
|
| 364 |
+
type: 'linear',
|
| 365 |
+
display: true,
|
| 366 |
+
position: 'right',
|
| 367 |
+
min: 0,
|
| 368 |
+
grid: {
|
| 369 |
+
drawOnChartArea: false,
|
| 370 |
+
},
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
});
|
| 375 |
+
|
| 376 |
+
function generateSyntheticData() {
|
| 377 |
+
const data = [];
|
| 378 |
+
const customers = ['CUST001', 'CUST002', 'CUST003', 'CUST004', 'CUST005', 'CUST006', 'CUST007', 'CUST008'];
|
| 379 |
|
| 380 |
+
for (let i = 0; i < 1000; i++) {
|
| 381 |
+
const invoiceAmount = Math.random() * 50000 + 1000;
|
| 382 |
+
const customerCode = customers[Math.floor(Math.random() * customers.length)];
|
| 383 |
+
const daysOverdue = Math.floor(Math.random() * 120);
|
| 384 |
+
const previousDelays = Math.floor(Math.random() * 5);
|
| 385 |
+
const creditScore = Math.random() * 100;
|
| 386 |
+
const industryRisk = Math.random();
|
| 387 |
+
const seasonality = Math.sin((i % 365) * 2 * Math.PI / 365);
|
| 388 |
+
|
| 389 |
+
// Create correlation between features and payment probability
|
| 390 |
+
let paymentProb = 0.7;
|
| 391 |
+
paymentProb -= Math.min(daysOverdue / 100, 0.4);
|
| 392 |
+
paymentProb -= Math.min(previousDelays / 10, 0.3);
|
| 393 |
+
paymentProb += (creditScore - 50) / 200;
|
| 394 |
+
paymentProb -= industryRisk * 0.2;
|
| 395 |
+
paymentProb += seasonality * 0.1;
|
| 396 |
+
paymentProb = Math.max(0.05, Math.min(0.95, paymentProb));
|
| 397 |
+
|
| 398 |
+
const paidOnTime = Math.random() < paymentProb ? 1 : 0;
|
| 399 |
+
|
| 400 |
+
data.push({
|
| 401 |
+
invoiceAmount: invoiceAmount / 50000, // Normalize
|
| 402 |
+
daysOverdue: daysOverdue / 120, // Normalize
|
| 403 |
+
previousDelays: previousDelays / 5, // Normalize
|
| 404 |
+
creditScore: creditScore / 100, // Already normalized
|
| 405 |
+
industryRisk: industryRisk,
|
| 406 |
+
seasonality: (seasonality + 1) / 2, // Normalize to 0-1
|
| 407 |
+
paidOnTime: paidOnTime
|
| 408 |
+
});
|
| 409 |
+
}
|
| 410 |
|
| 411 |
+
return data;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
function generateUnpaidInvoices() {
|
| 415 |
+
const invoices = [];
|
| 416 |
+
const customers = ['SAP-CUST001', 'SAP-CUST002', 'SAP-CUST003', 'SAP-CUST004', 'SAP-CUST005'];
|
| 417 |
+
|
| 418 |
+
for (let i = 0; i < 15; i++) {
|
| 419 |
+
const invoiceId = `INV-${Date.now()}-${i.toString().padStart(3, '0')}`;
|
| 420 |
+
const customer = customers[Math.floor(Math.random() * customers.length)];
|
| 421 |
+
const amount = Math.floor(Math.random() * 45000 + 5000);
|
| 422 |
+
const daysOverdue = Math.floor(Math.random() * 90);
|
| 423 |
+
const previousDelays = Math.floor(Math.random() * 4);
|
| 424 |
+
const creditScore = Math.floor(Math.random() * 60 + 40);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
|
| 426 |
+
invoices.push({
|
| 427 |
+
invoiceId,
|
| 428 |
+
customer,
|
| 429 |
+
amount,
|
| 430 |
+
daysOverdue,
|
| 431 |
+
previousDelays,
|
| 432 |
+
creditScore,
|
| 433 |
+
industryRisk: Math.random(),
|
| 434 |
+
seasonality: Math.random()
|
| 435 |
+
});
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
return invoices;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
async function trainModel() {
|
| 442 |
+
const trainBtn = document.getElementById('trainBtn');
|
| 443 |
+
const trainBtnText = document.getElementById('trainBtnText');
|
| 444 |
+
const statusDiv = document.getElementById('trainingStatus');
|
| 445 |
+
const progressDiv = document.getElementById('trainingProgress');
|
| 446 |
+
|
| 447 |
+
trainBtn.disabled = true;
|
| 448 |
+
trainBtnText.innerHTML = '<span class="loading"></span> Training...';
|
| 449 |
+
|
| 450 |
+
try {
|
| 451 |
+
// Show initial status
|
| 452 |
+
statusDiv.innerHTML = '<div class="status info">🔄 Generating synthetic SAP AR data...</div>';
|
| 453 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 454 |
+
|
| 455 |
+
// Generate training data
|
| 456 |
+
trainingData = generateSyntheticData();
|
| 457 |
+
statusDiv.innerHTML = '<div class="status success">✅ Generated 1,000 synthetic invoice records</div>';
|
| 458 |
+
|
| 459 |
+
await new Promise(resolve => setTimeout(resolve, 500));
|
| 460 |
+
statusDiv.innerHTML += '<div class="status info">🧠 Building neural network model...</div>';
|
| 461 |
+
|
| 462 |
+
// Prepare data for TensorFlow
|
| 463 |
+
const features = trainingData.map(d => [
|
| 464 |
+
d.invoiceAmount, d.daysOverdue, d.previousDelays,
|
| 465 |
+
d.creditScore, d.industryRisk, d.seasonality
|
| 466 |
+
]);
|
| 467 |
+
const labels = trainingData.map(d => d.paidOnTime);
|
| 468 |
+
|
| 469 |
+
const xs = tf.tensor2d(features);
|
| 470 |
+
const ys = tf.tensor1d(labels);
|
| 471 |
+
|
| 472 |
+
// Create model
|
| 473 |
+
model = tf.sequential({
|
| 474 |
+
layers: [
|
| 475 |
+
tf.layers.dense({
|
| 476 |
+
inputShape: [6],
|
| 477 |
+
units: 32,
|
| 478 |
+
activation: 'relu'
|
| 479 |
+
}),
|
| 480 |
+
tf.layers.dropout({rate: 0.2}),
|
| 481 |
+
tf.layers.dense({
|
| 482 |
+
units: 16,
|
| 483 |
+
activation: 'relu'
|
| 484 |
+
}),
|
| 485 |
+
tf.layers.dropout({rate: 0.2}),
|
| 486 |
+
tf.layers.dense({
|
| 487 |
+
units: 1,
|
| 488 |
+
activation: 'sigmoid'
|
| 489 |
+
})
|
| 490 |
+
]
|
| 491 |
+
});
|
| 492 |
+
|
| 493 |
+
model.compile({
|
| 494 |
+
optimizer: tf.train.adam(0.001),
|
| 495 |
+
loss: 'binaryCrossentropy',
|
| 496 |
+
metrics: ['accuracy']
|
| 497 |
+
});
|
| 498 |
+
|
| 499 |
+
statusDiv.innerHTML += '<div class="status info">🎯 Training model with backpropagation...</div>';
|
| 500 |
+
|
| 501 |
+
// Show progress bar
|
| 502 |
+
progressDiv.innerHTML = `
|
| 503 |
+
<div class="progress-bar">
|
| 504 |
+
<div class="progress-fill" id="progressFill" style="width: 0%"></div>
|
| 505 |
+
</div>
|
| 506 |
+
<div id="progressText">Training Progress: 0%</div>
|
| 507 |
+
`;
|
| 508 |
|
| 509 |
+
// Train model with callbacks
|
| 510 |
+
const history = await model.fit(xs, ys, {
|
| 511 |
+
epochs: 50,
|
| 512 |
+
batchSize: 32,
|
| 513 |
+
validationSplit: 0.2,
|
| 514 |
+
callbacks: {
|
| 515 |
+
onEpochEnd: (epoch, logs) => {
|
| 516 |
+
const progress = ((epoch + 1) / 50) * 100;
|
| 517 |
+
document.getElementById('progressFill').style.width = `${progress}%`;
|
| 518 |
+
document.getElementById('progressText').textContent = `Training Progress: ${Math.round(progress)}% - Accuracy: ${(logs.acc * 100).toFixed(1)}%`;
|
| 519 |
+
|
| 520 |
+
// Update chart
|
| 521 |
+
chart.data.labels.push(epoch + 1);
|
| 522 |
+
chart.data.datasets[0].data.push(logs.acc);
|
| 523 |
+
chart.data.datasets[1].data.push(logs.loss);
|
| 524 |
+
chart.update('none');
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
});
|
| 528 |
+
|
| 529 |
+
// Calculate final metrics
|
| 530 |
+
const finalAccuracy = history.history.acc[history.history.acc.length - 1];
|
| 531 |
+
const finalLoss = history.history.loss[history.history.loss.length - 1];
|
| 532 |
+
|
| 533 |
+
// Simulate precision, recall, F1 (normally would calculate from validation set)
|
| 534 |
+
const precision = Math.min(0.95, finalAccuracy + Math.random() * 0.1 - 0.05);
|
| 535 |
+
const recall = Math.min(0.95, finalAccuracy + Math.random() * 0.1 - 0.05);
|
| 536 |
+
const f1Score = 2 * (precision * recall) / (precision + recall);
|
| 537 |
+
|
| 538 |
+
// Update metrics display
|
| 539 |
+
document.getElementById('accuracy').textContent = (finalAccuracy * 100).toFixed(1) + '%';
|
| 540 |
+
document.getElementById('precision').textContent = (precision * 100).toFixed(1) + '%';
|
| 541 |
+
document.getElementById('recall').textContent = (recall * 100).toFixed(1) + '%';
|
| 542 |
+
document.getElementById('f1Score').textContent = (f1Score * 100).toFixed(1) + '%';
|
| 543 |
+
document.getElementById('modelMetrics').style.display = 'grid';
|
| 544 |
+
|
| 545 |
+
statusDiv.innerHTML += '<div class="status success">🎉 Model training completed successfully!</div>';
|
| 546 |
+
|
| 547 |
+
// Generate unpaid invoices for prediction
|
| 548 |
+
unpaidInvoices = generateUnpaidInvoices();
|
| 549 |
+
|
| 550 |
+
// Enable prediction button
|
| 551 |
+
document.getElementById('predictBtn').disabled = false;
|
| 552 |
+
|
| 553 |
+
// Cleanup tensors
|
| 554 |
+
xs.dispose();
|
| 555 |
+
ys.dispose();
|
| 556 |
+
|
| 557 |
+
} catch (error) {
|
| 558 |
+
statusDiv.innerHTML += `<div class="status warning">❌ Training failed: ${error.message}</div>`;
|
| 559 |
+
} finally {
|
| 560 |
+
trainBtn.disabled = false;
|
| 561 |
+
trainBtnText.textContent = 'Retrain Model';
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
async function makePredictions() {
|
| 566 |
+
if (!model || unpaidInvoices.length === 0) return;
|
| 567 |
+
|
| 568 |
+
const tableDiv = document.getElementById('predictionsTable');
|
| 569 |
+
tableDiv.innerHTML = '<div class="status info">🔮 Generating predictions...</div>';
|
| 570 |
+
|
| 571 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
| 572 |
+
|
| 573 |
+
// Prepare features for prediction
|
| 574 |
+
const features = unpaidInvoices.map(invoice => [
|
| 575 |
+
invoice.amount / 50000, // Normalize
|
| 576 |
+
invoice.daysOverdue / 120, // Normalize
|
| 577 |
+
invoice.previousDelays / 5, // Normalize
|
| 578 |
+
invoice.creditScore / 100, // Normalize
|
| 579 |
+
invoice.industryRisk,
|
| 580 |
+
invoice.seasonality
|
| 581 |
+
]);
|
| 582 |
+
|
| 583 |
+
const predictionTensor = tf.tensor2d(features);
|
| 584 |
+
const predictions = await model.predict(predictionTensor).data();
|
| 585 |
+
predictionTensor.dispose();
|
| 586 |
+
|
| 587 |
+
// Create table
|
| 588 |
+
let tableHTML = `
|
| 589 |
+
<table class="invoice-table">
|
| 590 |
+
<thead>
|
| 591 |
+
<tr>
|
| 592 |
+
<th>Invoice ID</th>
|
| 593 |
+
<th>Customer</th>
|
| 594 |
+
<th>Amount</th>
|
| 595 |
+
<th>Days Overdue</th>
|
| 596 |
+
<th>Credit Score</th>
|
| 597 |
+
<th>Payment Prediction</th>
|
| 598 |
+
<th>Probability</th>
|
| 599 |
+
</tr>
|
| 600 |
</thead>
|
| 601 |
+
<tbody>
|
| 602 |
+
`;
|
| 603 |
+
|
| 604 |
+
unpaidInvoices.forEach((invoice, index) => {
|
| 605 |
+
const probability = predictions[index];
|
| 606 |
+
const willPay = probability > 0.5;
|
| 607 |
+
const probClass = probability > 0.7 ? 'high-prob' : probability > 0.4 ? 'medium-prob' : 'low-prob';
|
| 608 |
+
|
| 609 |
+
tableHTML += `
|
| 610 |
+
<tr>
|
| 611 |
+
<td><strong>${invoice.invoiceId}</strong></td>
|
| 612 |
+
<td>${invoice.customer}</td>
|
| 613 |
+
<td>$${invoice.amount.toLocaleString()}</td>
|
| 614 |
+
<td>${invoice.daysOverdue} days</td>
|
| 615 |
+
<td>${invoice.creditScore}/100</td>
|
| 616 |
+
<td>
|
| 617 |
+
<span style="color: ${willPay ? '#28a745' : '#dc3545'}; font-weight: bold;">
|
| 618 |
+
${willPay ? '✅ Will Pay' : '❌ Risk of Default'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
</span>
|
| 620 |
+
</td>
|
| 621 |
+
<td>
|
| 622 |
+
<div class="prediction">
|
| 623 |
+
<div class="probability-bar">
|
| 624 |
+
<div class="probability-fill ${probClass}" style="width: ${probability * 100}%"></div>
|
| 625 |
+
</div>
|
| 626 |
+
<span style="font-weight: bold; min-width: 50px;">
|
| 627 |
+
${(probability * 100).toFixed(1)}%
|
| 628 |
+
</span>
|
| 629 |
+
</div>
|
| 630 |
+
</td>
|
| 631 |
+
</tr>
|
| 632 |
+
`;
|
| 633 |
+
});
|
| 634 |
+
|
| 635 |
+
tableHTML += '</tbody></table>';
|
| 636 |
+
tableDiv.innerHTML = tableHTML;
|
| 637 |
+
}
|
| 638 |
+
</script>
|
| 639 |
+
</body>
|
| 640 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|