Spaces:
Sleeping
Sleeping
File size: 42,866 Bytes
5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 d4334be 5df66b9 |
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 267 268 269 270 271 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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 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 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>International Trade Flow Predictor</title>
<link rel="stylesheet" href="/static/css/style.css">
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<!-- Leaflet for maps -->
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<!-- Custom trade flow map -->
<script src="/static/js/tradeflowmap.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap">
<style>
/* Custom inline styles */
:root {
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}
body {
font-family: var(--font-sans);
}
.advanced-chart-container {
width: 100%;
height: 400px;
position: relative;
border-radius: var(--radius-md);
overflow: hidden;
border: 1px solid var(--border-color);
}
.treemap-container {
width: 100%;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
}
.treemap-title {
font-weight: 600;
padding: 12px 16px;
background: var(--background-grey);
border-bottom: 1px solid var(--border-color);
}
.treemap-item:hover {
opacity: 0.9;
transform: scale(1.02);
transition: all 0.2s ease;
z-index: 5;
}
/* Chart controls */
.chart-controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 16px;
}
.chart-type-btn {
display: inline-flex;
align-items: center;
padding: 6px 12px;
background-color: var(--background-light);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
font-size: 13px;
cursor: pointer;
transition: all 0.2s ease;
}
.chart-type-btn:hover {
background-color: var(--primary-light);
color: var(--primary-color);
}
.chart-type-btn.active {
background-color: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
/* Cached data styling */
.cached-data-panel {
margin-top: 24px;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
overflow: hidden;
background-color: var(--background-light);
}
.cached-data-header {
padding: 12px 16px;
background-color: var(--background-grey);
font-weight: 600;
border-bottom: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
}
.cached-data-list {
max-height: 320px;
overflow-y: auto;
padding: 0;
margin: 0;
}
.cached-data-item {
padding: 12px 16px;
border-bottom: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
transition: background-color 0.2s ease;
}
.cached-data-item:hover {
background-color: var(--background-grey);
}
.cached-data-item:hover {
background: #f9f9fa;
}
.cached-data-actions {
display: flex;
gap: 5px;
}
.cached-data-info {
font-size: 13px;
color: #666;
}
.action-btn {
background: none;
border: none;
color: #1976d2;
cursor: pointer;
padding: 3px 8px;
border-radius: 3px;
}
.action-btn:hover {
background: #e3e9f6;
}
.action-btn.delete {
color: #e53935;
}
.action-btn.delete:hover {
background: #ffebee;
}
/* AI Assistant styles */
.chat-container {
display: flex;
flex-direction: column;
max-height: 350px;
overflow-y: auto;
padding: 16px;
background-color: var(--background-light);
border-radius: var(--radius-md);
margin-bottom: 16px;
border: 1px solid var(--border-color);
}
.chat-message {
padding: 12px 16px;
margin-bottom: 12px;
border-radius: var(--radius-md);
max-width: 80%;
word-wrap: break-word;
}
.user-message {
background-color: var(--primary-light);
color: var(--text-color);
margin-left: auto;
border-radius: 12px 12px 2px 12px;
}
.assistant-message {
background-color: var(--background-grey);
color: var(--text-color);
margin-right: auto;
border-radius: 12px 12px 12px 2px;
}
.chat-input-container {
padding: 16px;
background-color: var(--background-light);
border-top: 1px solid var(--border-color);
display: flex;
align-items: center;
gap: 12px;
}
.chat-input {
flex: 1;
padding: 10px 12px;
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
font-size: 14px;
color: var(--text-color);
transition: all 0.2s ease;
}
.chat-input:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(0, 103, 223, 0.15);
}
.chat-submit {
padding: 10px 16px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--radius-sm);
cursor: pointer;
font-weight: 500;
display: inline-flex;
align-items: center;
transition: all 0.2s ease;
}
.chat-submit:hover {
background-color: #0055c4;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.message {
margin-bottom: 15px;
max-width: 80%;
}
.message-user {
align-self: flex-end;
margin-left: auto;
background: #e3f2fd;
border-radius: 18px 18px 0 18px;
padding: 10px 15px;
}
.message-assistant {
align-self: flex-start;
background: #fff;
border-radius: 18px 18px 18px 0;
padding: 10px 15px;
border: 1px solid #e0e0e0;
}
.message-loading {
display: flex;
align-items: center;
padding: 10px 15px;
}
.loading-dots span {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #1976d2;
margin-right: 3px;
animation: loading-bounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes loading-bounce {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
.quick-questions {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 10px;
}
.quick-question-btn {
background: #f0f4f8;
border: 1px solid #ddd;
border-radius: 16px;
padding: 6px 12px;
font-size: 13px;
cursor: pointer;
transition: all 0.2s;
}
.quick-question-btn:hover {
background: #e3e9f6;
}
.badge {
display: inline-block;
padding: 2px 6px;
border-radius: 10px;
background-color: #E53935;
color: white;
font-size: 10px;
font-weight: bold;
margin-left: 5px;
vertical-align: top;
}
</style>
</head>
<body class="app-container">
<!-- Header with logo and navigation -->
<header class="header">
<div class="header-container">
<a href="/" class="app-logo">
<i class="fas fa-globe-americas"></i>
<span>Trade Flow Predictor</span>
</a>
<div class="header-actions">
<a href="https://huggingface.co/spaces/jomasego/trade-flow-predictor" target="_blank" class="huggingface-link">
<img src="https://huggingface.co/front/assets/huggingface_logo.svg" alt="Hugging Face">
<span>View on Hugging Face</span>
</a>
</div>
</div>
</header>
<!-- Info banner for sources and rate-limit info -->
<div class="info-banner">
<div class="info-sources">
<span class="source-label">Sources:</span> UN COMTRADE, WTO, World Bank
<span class="info-divider">|</span>
<span class="limit-label">API Limit:</span> 1 request/sec, 100 requests/hour
</div>
<div class="powered-by">
<span>Powered by</span>
<a href="https://huggingface.co" target="_blank" class="huggingface-badge">
<img src="https://huggingface.co/front/assets/huggingface_logo.svg" alt="Hugging Face">
</a>
</div>
</div>
<!-- Main content container -->
<div class="main-content">
<!-- Tab Navigation -->
<nav class="tab-navigation">
<ul id="main-tabs" class="tab-bar">
<li class="tab active" data-tab="basics" tabindex="0" aria-selected="true">Basics</li>
<li class="tab" data-tab="exports-country" tabindex="0" aria-selected="false">Exports by Country</li>
<li class="tab" data-tab="imports-country" tabindex="0" aria-selected="false">Imports by Country</li>
<li class="tab" data-tab="exports-product" tabindex="0" aria-selected="false">Exports by Product</li>
<li class="tab" data-tab="imports-product" tabindex="0" aria-selected="false">Imports by Product</li>
<li class="tab" data-tab="rankings" tabindex="0" aria-selected="false">Rankings</li>
<li class="tab" data-tab="bilateral" tabindex="0" aria-selected="false">Bilateral Trade</li>
<li class="tab" data-tab="data-download" tabindex="0" aria-selected="false">Data Download</li>
<li class="tab" data-tab="prediction" tabindex="0" aria-selected="false">Prediction (ML)</li>
<li class="tab" data-tab="data-cache" tabindex="0" aria-selected="false">Data Cache</li>
<li class="tab" data-tab="assistant" tabindex="0" aria-selected="false">AI Assistant <span class="badge">New</span></li>
</ul>
</nav>
<!-- Tab content begins here -->
<!-- Tab Content Panels -->
<div id="tab-content-basics" class="tab-content" style="display:block;">
<div class="card">
<div class="section-heading">
<h2>Trade Data Analysis</h2>
</div>
<form id="tradeForm">
<div style="display:flex;flex-wrap:wrap;gap:16px;">
<div style="flex:1;min-width:240px;">
<label for="reporterCode">Reporter Country</label>
<select id="reporterCode" name="reporterCode"></select>
</div>
<div style="flex:1;min-width:240px;">
<label for="partnerCode">Partner Country</label>
<select id="partnerCode" name="partnerCode"></select>
</div>
</div>
<div style="display:flex;flex-wrap:wrap;gap:16px;margin-top:8px;">
<div style="flex:1;min-width:240px;">
<label for="year">Year</label>
<input type="number" id="year" name="year" value="2022" min="2000" max="2100">
</div>
<div style="flex:1;min-width:240px;">
<label for="cmdCode">Commodity Code</label>
<input type="text" id="cmdCode" name="cmdCode" value="TOTAL" placeholder="e.g., TOTAL or specific HS code">
</div>
</div>
<div style="margin-top:16px;">
<button type="submit" class="btn-primary">Generate Trade Report</button>
</div>
</form>
<div id="results" class="results-section"></div>
</div>
<!-- Visualization Container -->
<div class="chart-container" style="display:none;margin-top:24px;" id="visualizationContainer">
<div class="section-heading">
<h3>Trade Data Visualization</h3>
</div>
<div class="chart-controls">
<button class="chart-type-btn active" data-type="bar">
<i class="fas fa-chart-bar"></i> Bar Chart
</button>
<button class="chart-type-btn" data-type="pie">
<i class="fas fa-chart-pie"></i> Pie Chart
</button>
<button class="chart-type-btn" data-type="line">
<i class="fas fa-chart-line"></i> Line Chart
</button>
<button class="chart-type-btn" data-type="treemap">
<i class="fas fa-th-large"></i> Treemap
</button>
</div>
<canvas id="tradeChart" height="350"></canvas>
</div>
</div>
<!-- Select2 for searchable dropdowns -->
<!-- JavaScript modules -->
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="/static/js/country_codes.js"></script>
<script src="/static/js/data_manager.js"></script>
<script src="/static/js/charts_module.js"></script>
<script src="/static/js/main.js"></script>
<script src="/static/js/enhanced_visualizations.js"></script>
<script src="/static/js/assistant.js"></script>
<div id="extraVisualizations" style="margin-top:2em;"></div>
<script>
// Populate country dropdowns from COUNTRY_CODES
document.addEventListener('DOMContentLoaded', function() {
function populateCountrySelect(selectId, defaultCode) {
const select = document.getElementById(selectId);
if (!select || typeof COUNTRY_CODES === 'undefined') return;
select.innerHTML = '';
COUNTRY_CODES.forEach(c => {
const opt = document.createElement('option');
opt.value = c.code;
opt.textContent = c.name + ' (' + c.code + ')';
if (c.code === defaultCode) opt.selected = true;
select.appendChild(opt);
});
// Make dropdown searchable with Select2
window.$ && window.$(select).select2 && window.$(select).select2();
}
populateCountrySelect('reporterCode', '842');
populateCountrySelect('partnerCode', '156');
});
</script>
<!-- jQuery for select2 -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</div>
<div id="tab-content-exports-country" class="tab-content" style="display:none;">
<div class="card">
<div class="section-heading">
<h2>Exports by Country</h2>
<p class="section-description">Analyze international export flows by country and year</p>
</div>
<form id="exportsCountryForm">
<div class="form-row">
<div class="form-group col-md-4">
<label for="exportsCountryYear">Year</label>
<input type="number" id="exportsCountryYear" name="exportsCountryYear" value="2022" min="2000" max="2100" class="input-field">
</div>
<div class="form-group col-md-4">
<label for="exportsCountryCommodity">Commodity Code</label>
<input type="text" id="exportsCountryCommodity" name="exportsCountryCommodity" value="TOTAL" placeholder="e.g., TOTAL or HS code" class="input-field">
</div>
<div class="form-group col-md-4">
<label for="exportsCountryFlow">Flow Type</label>
<select id="exportsCountryFlow" name="exportsCountryFlow" class="select-field">
<option value="X">Export</option>
<option value="M">Import</option>
<option value="">All</option>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn-primary">Show Trade Data</button>
<button id="exportsCountryDownloadBtn" class="btn-secondary" style="display:none;">Download CSV</button>
</div>
</form>
<div id="exportsCountryResults" class="results-section"></div>
</div>
<!-- Trade Flow Visualization Card -->
<div class="card" id="exportsCountryChartCard" style="margin-top:24px;">
<div class="section-heading">
<h3>Exports Flow Visualization</h3>
</div>
<div class="visualization-tabs">
<div class="chart-controls">
<button class="chart-type-btn active" data-type="bar">
<i class="fas fa-chart-bar"></i> Bar Chart
</button>
<button class="chart-type-btn" data-type="map">
<i class="fas fa-globe"></i> Trade Flow Map
</button>
</div>
</div>
<div id="exportsCountryChart" class="chart-area"></div>
<!-- Trade Flow Map -->
<div id="exportsCountryFlowMap" class="trade-flow-map" data-height="350" data-show-labels="true" style="display:none;margin-top:16px;"></div>
</div>
</div>
<div id="tab-content-imports-country" class="tab-content" style="display:none;">
<div class="card">
<div class="section-heading">
<h2>Imports by Country</h2>
<p class="section-description">Analyze international import flows by country and year</p>
</div>
<form id="importsCountryForm">
<div class="form-row">
<div class="form-group col-md-4">
<label for="importsCountryYear">Year</label>
<input type="number" id="importsCountryYear" name="importsCountryYear" value="2022" min="2000" max="2100" class="input-field">
</div>
<div class="form-group col-md-4">
<label for="importsCountryCommodity">Commodity Code</label>
<input type="text" id="importsCountryCommodity" name="importsCountryCommodity" value="TOTAL" placeholder="e.g., TOTAL or HS code" class="input-field">
</div>
<div class="form-group col-md-4">
<label for="importsCountryFlow">Flow Type</label>
<select id="importsCountryFlow" name="importsCountryFlow" class="select-field">
<option value="M">Import</option>
<option value="X">Export</option>
<option value="">All</option>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn-primary">Show Trade Data</button>
<button id="importsCountryDownloadBtn" class="btn-secondary" style="display:none;">Download CSV</button>
</div>
</form>
<div id="importsCountryResults" class="results-section"></div>
</div>
<!-- Trade Flow Visualization Card -->
<div class="card" id="importsCountryChartCard" style="margin-top:24px;">
<div class="section-heading">
<h3>Imports Flow Visualization</h3>
</div>
<div class="visualization-tabs">
<div class="chart-controls">
<button class="chart-type-btn active" data-type="bar">
<i class="fas fa-chart-bar"></i> Bar Chart
</button>
<button class="chart-type-btn" data-type="map">
<i class="fas fa-globe"></i> Trade Flow Map
</button>
</div>
</div>
<div id="importsCountryChart" class="chart-area"></div>
<!-- Trade Flow Map -->
<div id="importsCountryFlowMap" class="trade-flow-map" data-height="350" data-show-labels="true" style="display:none;margin-top:16px;"></div>
</div>
</div>
<div id="tab-content-exports-product" class="tab-content" style="display:none;">
<h3>Exports by Product</h3>
<form id="exportsProductForm" style="margin-bottom:1em;">
<label for="exportsProductCountry">Country:</label>
<select id="exportsProductCountry" name="exportsProductCountry"></select>
<label for="exportsProductYear">Year:</label>
<input type="number" id="exportsProductYear" name="exportsProductYear" value="2022" min="2000" max="2100" style="width:90px;">
<button type="submit">Show Table</button>
</form>
<button id="exportsProductDownloadBtn" style="display:none;margin-bottom:1em;">Download CSV</button>
<div id="exportsProductResults"></div>
<div id="exportsProductChart" style="margin-top:2em;"></div>
</div>
<div id="tab-content-imports-product" class="tab-content" style="display:none;">
<h3>Imports by Product</h3>
<form id="importsProductForm" style="margin-bottom:1em;">
<label for="importsProductCountry">Country:</label>
<select id="importsProductCountry" name="importsProductCountry"></select>
<label for="importsProductYear">Year:</label>
<input type="number" id="importsProductYear" name="importsProductYear" value="2022" min="2000" max="2100" style="width:90px;">
<button type="submit">Show Table</button>
</form>
<button id="importsProductDownloadBtn" style="display:none;margin-bottom:1em;">Download CSV</button>
<div id="importsProductResults"></div>
<div id="importsProductChart" style="margin-top:2em;"></div>
</div>
<div id="tab-content-rankings" class="tab-content" style="display:none;">
<h3>Ranking of Countries</h3>
<form id="rankingsForm" style="margin-bottom:1em;">
<label for="rankingsYear">Year:</label>
<input type="number" id="rankingsYear" name="rankingsYear" value="2022" min="2000" max="2100" style="width:90px;">
<label for="rankingsCommodity">Commodity Code (HS or TOTAL):</label>
<input type="text" id="rankingsCommodity" name="rankingsCommodity" value="TOTAL" style="width:110px;">
<label for="rankingsFlow">Flow:</label>
<select id="rankingsFlow" name="rankingsFlow">
<option value="X">Exporters</option>
<option value="M">Importers</option>
</select>
<button type="submit">Show Rankings</button>
</form>
<button id="rankingsDownloadBtn" style="display:none;margin-bottom:1em;">Download CSV</button>
<div id="rankingsResults"></div>
<div id="rankingsChart" style="margin-top:2em;"></div>
</div>
<div id="tab-content-bilateral" class="tab-content" style="display:none;">
<div class="card">
<div class="section-heading">
<h2>Bilateral Trade Analysis</h2>
<p class="section-description">Analyze trade flows between two specific countries</p>
</div>
<form id="bilateralForm">
<div class="form-row">
<div class="form-group col-md-6">
<label for="bilateralReporter">Reporter Country</label>
<select id="bilateralReporter" name="bilateralReporter" class="select-field"></select>
</div>
<div class="form-group col-md-6">
<label for="bilateralPartner">Partner Country</label>
<select id="bilateralPartner" name="bilateralPartner" class="select-field"></select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="bilateralYear">Year</label>
<input type="number" id="bilateralYear" name="bilateralYear" value="2022" min="2000" max="2100" class="input-field">
</div>
<div class="form-group col-md-6">
<label for="bilateralCommodity">Commodity Code</label>
<input type="text" id="bilateralCommodity" name="bilateralCommodity" value="TOTAL" placeholder="e.g., TOTAL or HS code" class="input-field">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn-primary">Show Bilateral Trade</button>
<button id="bilateralDownloadBtn" class="btn-secondary" style="display:none;">Download CSV</button>
</div>
</form>
<div id="bilateralResults" class="results-section"></div>
</div>
<!-- Bilateral Trade Flow Visualization Card -->
<div class="card" id="bilateralChartCard" style="margin-top:24px;">
<div class="section-heading">
<h3>Bilateral Trade Flow Visualization</h3>
</div>
<div class="visualization-tabs">
<div class="chart-controls">
<button class="chart-type-btn" data-type="bar">
<i class="fas fa-chart-bar"></i> Bar Chart
</button>
<button class="chart-type-btn active" data-type="map">
<i class="fas fa-globe"></i> Trade Flow Map
</button>
</div>
</div>
<div id="bilateralChart" class="chart-area"></div>
<!-- Trade Flow Map (Active by default for bilateral) -->
<div id="bilateralFlowMap" class="trade-flow-map" data-height="400" data-show-labels="true" data-demo="true"></div>
</div>
</div>
<div id="tab-content-data-download" class="tab-content" style="display:none;">
<h3>Data Download</h3>
<form id="dataDownloadForm" style="margin-bottom:1em;">
<label for="dataDownloadReporter">Reporter Country:</label>
<select id="dataDownloadReporter" name="dataDownloadReporter">
<option value="">All</option>
</select>
<label for="dataDownloadPartner">Partner Country:</label>
<select id="dataDownloadPartner" name="dataDownloadPartner">
<option value="">All</option>
</select>
<label for="dataDownloadYear">Year:</label>
<input type="number" id="dataDownloadYear" name="dataDownloadYear" min="2000" max="2100" style="width:90px;">
<label for="dataDownloadCommodity">Commodity Code (HS or TOTAL):</label>
<input type="text" id="dataDownloadCommodity" name="dataDownloadCommodity" style="width:110px;">
<label for="dataDownloadFlow">Flow:</label>
<select id="dataDownloadFlow" name="dataDownloadFlow">
<option value="">All</option>
<option value="X">Export</option>
<option value="M">Import</option>
</select>
<button type="submit">Download CSV</button>
</form>
<div id="dataDownloadStatus"></div>
</div>
<div id="tab-content-prediction" class="tab-content" style="display:none;">
<div class="card">
<div class="section-heading">
<h2>Trade Flow Prediction (ML)</h2>
</div>
<form id="predictionForm">
<div class="form-row">
<div class="form-group col-md-6">
<label for="predictionReporter">Reporter Country</label>
<select id="predictionReporter" name="predictionReporter" class="select-field"></select>
</div>
<div class="form-group col-md-6">
<label for="predictionPartner">Partner Country</label>
<select id="predictionPartner" name="predictionPartner" class="select-field"></select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="predictionYear">Year to Predict</label>
<input type="number" id="predictionYear" name="predictionYear" value="2023" min="2000" max="2100" class="input-field">
</div>
<div class="form-group col-md-4">
<label for="predictionCommodity">Commodity Code</label>
<input type="text" id="predictionCommodity" name="predictionCommodity" value="TOTAL" placeholder="e.g., TOTAL or HS code" class="input-field">
</div>
<div class="form-group col-md-4">
<label for="predictionModel">Model</label>
<select id="predictionModel" name="predictionModel" class="select-field">
<option value="linear">Linear Regression</option>
<option value="xgboost">XGBoost</option>
<option value="lstm">LSTM</option>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn-primary">Generate Prediction</button>
<button id="predictionDownloadBtn" class="btn-secondary" style="display:none;">Download CSV</button>
</div>
</form>
<div id="predictionResults" class="results-container"></div>
</div>
<div class="card" id="predictionChartCard" style="display:none;margin-top:24px;">
<div class="section-heading">
<h3>Prediction Visualization</h3>
</div>
<div id="predictionChart" class="chart-area"></div>
</div>
</div>
<!-- Data Cache Management Panel -->
<div id="tab-content-data-cache" class="tab-content" style="display:none;">
<div class="card">
<div class="section-heading">
<h2>Data Cache Management</h2>
<p class="section-description">Manage previously cached trade data to reduce API calls and work offline</p>
</div>
<div class="cache-control-header">
<h3 class="panel-title">Cached Datasets</h3>
<div class="action-buttons">
<button id="refreshCacheBtn" class="btn-secondary btn-icon">
<i class="fas fa-sync-alt"></i> Refresh
</button>
<button id="clearAllCacheBtn" class="btn-danger btn-icon">
<i class="fas fa-trash"></i> Clear All
</button>
</div>
</div>
<div id="cachedDataList" class="cached-data-container">
<!-- Cache items will be populated here -->
<div class="loading-indicator">
<i class="fas fa-spinner fa-spin"></i>
<span>Loading cached data...</span>
</div>
</div>
</div>
<div class="card" id="cacheVisualizationCard" style="margin-top:24px;">
<div class="section-heading">
<h3>Visualization Options</h3>
</div>
<div class="chart-control-buttons">
<button class="chart-type-btn" data-type="bar">
<i class="fas fa-chart-bar"></i> Bar Chart
</button>
<button class="chart-type-btn" data-type="pie">
<i class="fas fa-chart-pie"></i> Pie Chart
</button>
<button class="chart-type-btn" data-type="line">
<i class="fas fa-chart-line"></i> Line Chart
</button>
<button class="chart-type-btn" data-type="treemap">
<i class="fas fa-th-large"></i> Treemap
</button>
<button class="chart-type-btn" data-type="map">
<i class="fas fa-globe"></i> World Map
</button>
</div>
<div id="cacheVisualization" class="visualization-container">
<!-- Visualizations will be rendered here -->
</div>
</div>
</div>
</div>
<div id="tab-content-assistant" class="tab-content" style="display:none;">
<div class="card">
<div class="section-heading">
<h2>AI Trade Assistant</h2>
<div class="model-badge">
<img src="https://huggingface.co/front/assets/huggingface_logo.svg" alt="Hugging Face" class="hf-logo">
<span>Powered by Google Gemma-2b</span>
</div>
</div>
<div class="chat-container">
<div id="chat-messages" class="chat-messages">
<!-- Welcome message -->
<div class="message message-assistant">
<div class="message-content">
<p>π Hello! I'm your Trade Data Assistant powered by Google Gemma-2b.</p>
<p>I can help you with:</p>
<ul>
<li>Understanding trade terminology and HS codes</li>
<li>Exploring interesting trade patterns</li>
<li>Finding specific trade data</li>
<li>Interpreting visualization results</li>
<li>Providing insights about international trade</li>
</ul>
<p>How can I assist you today?</p>
</div>
</div>
</div>
<div class="chat-input-container">
<input type="text" id="chat-input" class="chat-input" placeholder="Ask me about trade data, HS codes, or how to use this application...">
<button id="chat-send-btn" class="btn-primary">Send</button>
</div>
</div>
<div class="quick-questions-container">
<h3 class="section-title">Try asking</h3>
<div class="quick-question-chips">
<button class="quick-question-chip">What are HS codes?</button>
<button class="quick-question-chip">Explain imports vs exports</button>
<button class="quick-question-chip">What does HS code 8471 represent?</button>
<button class="quick-question-chip">How to interpret trade data?</button>
<button class="quick-question-chip">Recommend trade patterns to explore</button>
</div>
</div>
<div class="assistant-tools">
<h3 class="section-title">Specialized Tools</h3>
<div class="tools-grid">
<div class="tool-card">
<div class="tool-header">
<i class="fas fa-search"></i>
<h4>HS Code Lookup</h4>
</div>
<div class="tool-content">
<div class="input-with-button">
<input type="text" id="hs-code-input" placeholder="Enter HS code (e.g. 8471)">
<button id="explain-hs-btn" class="btn-success">Explain</button>
</div>
</div>
</div>
<div class="tool-card">
<div class="tool-header">
<i class="fas fa-lightbulb"></i>
<h4>Trade Insights</h4>
</div>
<div class="tool-content">
<div class="form-group">
<select id="recommendation-country">
<option value="">Select a country (optional)</option>
<!-- Will be populated from COUNTRY_CODES -->
</select>
</div>
<div class="input-with-button">
<input type="text" id="recommendation-product" placeholder="Product (optional)">
<button id="get-recommendation-btn" class="btn-info">Get Insights</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Specialized Assistance Panel -->
<div id="tab-content-specialized" class="tab-content" style="display:none;">
<div class="container">
<h4>Specialized Assistance: <span style="font-size:14px;color:#666;font-weight:normal;display:inline-flex;align-items:center;">
<img src="https://huggingface.co/front/assets/huggingface_logo.svg" alt="Hugging Face" style="height:16px;margin:0 4px;"> Powered by Hugging Face
</span></h4>
<div style="display:flex;gap:10px;flex-wrap:wrap;">
<div style="flex:1;min-width:300px;">
<h5>HS Code Lookup</h5>
<div class="input-group">
<input type="text" id="hs-code-input" placeholder="Enter HS code (e.g. 8471)" class="chat-input" style="width:70%" />
<button id="explain-hs-btn" class="chat-send-btn" style="width:25%">Explain</button>
</div>
</div>
<div style="flex:1;min-width:300px;">
<h5>Trade Recommendation</h5>
<div class="input-group" style="margin-bottom:10px;">
<select id="recommendation-country" class="chat-input" style="width:100%">
<option value="">Select a country (optional)</option>
<!-- Will be populated from COUNTRY_CODES -->
</select>
</div>
<div class="input-group">
<input type="text" id="recommendation-product" placeholder="Product (optional)" class="chat-input" style="width:70%" />
<button id="get-recommendation-btn" class="chat-send-btn" style="width:25%">Get Insights</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Animation styles -->
<style>
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
<!-- Direct tab navigation script -->
<script>
document.addEventListener('DOMContentLoaded', function() {
// Handle iframe loading
const iframe = document.getElementById('hf-assistant-iframe');
const loadingIndicator = document.getElementById('assistant-loading');
if (iframe && loadingIndicator) {
iframe.onload = function() {
loadingIndicator.style.display = 'none';
};
// Set a timeout in case the iframe fails to trigger onload
setTimeout(function() {
loadingIndicator.style.display = 'none';
}, 8000); // Hide after 8 seconds regardless
}
// Direct tab navigation logic
const tabs = document.querySelectorAll('#main-tabs .tab');
const tabContents = document.querySelectorAll('.tab-content');
tabs.forEach(tab => {
tab.addEventListener('click', function() {
const tabName = tab.getAttribute('data-tab');
// Check if this is the AI Assistant tab
if (tabName === 'assistant') {
// Option to redirect directly to Hugging Face Space
// Uncomment the next line if you want direct redirect
// window.open('https://huggingface.co/spaces/jomasego/ai-trade-assistant', '_blank');
}
// Hide any visible spinners
document.querySelectorAll('.spinner').forEach(spinner => {
spinner.style.display = 'none';
});
// Update active tab
tabs.forEach(t => {
t.classList.remove('active');
t.setAttribute('aria-selected', 'false');
});
tab.classList.add('active');
tab.setAttribute('aria-selected', 'true');
// Show corresponding tab content
tabContents.forEach(panel => {
if (panel.id === 'tab-content-' + tabName) {
panel.style.display = 'block';
} else {
panel.style.display = 'none';
}
});
// Focus the active tab
tab.focus();
});
// Keyboard navigation
tab.addEventListener('keydown', function(e) {
if (e.key === 'ArrowRight') {
e.preventDefault();
tabs[(idx + 1) % tabs.length].focus();
} else if (e.key === 'ArrowLeft') {
e.preventDefault();
tabs[(idx - 1 + tabs.length) % tabs.length].focus();
} else if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
tab.click();
}
});
});
// Initial load - make sure the active tab content is visible
const activeTab = document.querySelector('#main-tabs .tab.active');
if (activeTab) {
const tabName = activeTab.getAttribute('data-tab');
const activePanel = document.getElementById('tab-content-' + tabName);
if (activePanel) {
activePanel.style.display = 'block';
}
}
});
</script>
</body>
</html>
|