Spaces:
Running
Running
File size: 48,919 Bytes
8939d51 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hugging Face Model Explorer</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.gradient-bg {
background: linear-gradient(135deg, #6e8efb, #a777e3);
}
.model-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
.chat-message-user {
border-radius: 18px 18px 4px 18px;
}
.chat-message-ai {
border-radius: 18px 18px 18px 4px;
}
.loading-dots::after {
content: '.';
animation: dots 1.5s steps(5, end) infinite;
}
@keyframes dots {
0%, 20% { content: '.'; }
40% { content: '..'; }
60% { content: '...'; }
80%, 100% { content: ''; }
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="gradient-bg text-white py-6 shadow-lg">
<div class="container mx-auto px-4">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-3">
<i class="fas fa-robot text-3xl"></i>
<h1 class="text-2xl md:text-3xl font-bold">Hugging Face Model Explorer</h1>
</div>
<div class="flex items-center space-x-4">
<button id="darkModeToggle" class="p-2 rounded-full hover:bg-white/10 transition">
<i class="fas fa-moon"></i>
</button>
<a href="https://huggingface.co" target="_blank" class="bg-white/20 hover:bg-white/30 px-4 py-2 rounded-full text-sm font-medium transition flex items-center space-x-2">
<i class="fab fa-hubspot"></i>
<span>Hugging Face</span>
</a>
</div>
</div>
<p class="mt-3 text-white/90 max-w-2xl">Explore, interact with, and generate content using thousands of AI models from Hugging Face</p>
</div>
</div>
<div class="container mx-auto px-4 py-8">
<!-- Auth Section -->
<div class="bg-white rounded-xl shadow-md p-6 mb-8">
<h2 class="text-xl font-semibold mb-4 flex items-center">
<i class="fas fa-key mr-2 text-purple-600"></i>
Authentication
</h2>
<div class="grid md:grid-cols-3 gap-6">
<div class="md:col-span-2">
<label for="accessToken" class="block text-sm font-medium text-gray-700 mb-1">Hugging Face Access Token</label>
<div class="flex">
<input type="password" id="accessToken" placeholder="hf_xxxxxxxxxxxxxxxx" class="flex-1 px-4 py-2 border border-gray-300 rounded-l-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500">
<button id="toggleTokenVisibility" class="px-3 bg-gray-100 border border-l-0 border-gray-300 rounded-r-lg text-gray-600 hover:bg-gray-200">
<i class="fas fa-eye"></i>
</button>
</div>
<p class="mt-2 text-sm text-gray-500">Get your token from <a href="https://huggingface.co/settings/tokens" target="_blank" class="text-purple-600 hover:underline">Hugging Face settings</a></p>
</div>
<div class="flex items-end">
<button id="saveTokenBtn" class="w-full bg-purple-600 hover:bg-purple-700 text-white py-2 px-4 rounded-lg transition flex items-center justify-center space-x-2">
<i class="fas fa-save"></i>
<span>Save Token</span>
</button>
</div>
</div>
</div>
<!-- Model Selection Section -->
<div class="bg-white rounded-xl shadow-md p-6 mb-8">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold flex items-center">
<i class="fas fa-cube mr-2 text-blue-600"></i>
Model Selection
</h2>
<div class="flex space-x-3">
<div class="relative">
<select id="modelTypeFilter" class="appearance-none bg-gray-100 border border-gray-300 rounded-lg px-4 py-2 pr-8 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="all">All Types</option>
<option value="text">Text</option>
<option value="image">Image</option>
<option value="audio">Audio</option>
<option value="multimodal">Multimodal</option>
</select>
<i class="fas fa-chevron-down absolute right-3 top-2.5 text-gray-500 text-xs"></i>
</div>
<div class="relative">
<input type="text" id="modelSearch" placeholder="Search models..." class="bg-gray-100 border border-gray-300 rounded-lg px-4 py-2 pl-10 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-48">
<i class="fas fa-search absolute left-3 top-2.5 text-gray-500"></i>
</div>
</div>
</div>
<div id="modelLoading" class="flex justify-center items-center py-12">
<div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-500"></div>
</div>
<div id="modelsContainer" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 hidden">
<!-- Models will be populated here -->
</div>
<div id="pagination" class="flex justify-center mt-6 space-x-2 hidden">
<button id="prevPage" class="px-4 py-2 bg-gray-100 rounded-lg hover:bg-gray-200 disabled:opacity-50">
<i class="fas fa-chevron-left"></i>
</button>
<div id="pageNumbers" class="flex space-x-1"></div>
<button id="nextPage" class="px-4 py-2 bg-gray-100 rounded-lg hover:bg-gray-200 disabled:opacity-50">
<i class="fas fa-chevron-right"></i>
</button>
</div>
</div>
<!-- Interaction Section -->
<div id="interactionSection" class="hidden">
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Model Info Card -->
<div class="bg-white rounded-xl shadow-md p-6 h-fit">
<div class="flex justify-between items-start mb-4">
<h2 class="text-xl font-semibold flex items-center">
<i class="fas fa-info-circle mr-2 text-green-600"></i>
Selected Model
</h2>
<button id="clearModelBtn" class="text-sm text-red-500 hover:text-red-700 flex items-center">
<i class="fas fa-times mr-1"></i> Clear
</button>
</div>
<div id="selectedModelInfo">
<div class="flex items-center mb-4">
<div id="modelAvatar" class="w-16 h-16 rounded-lg bg-gray-200 flex items-center justify-center mr-4">
<i class="fas fa-cube text-2xl text-gray-500"></i>
</div>
<div>
<h3 id="modelName" class="font-bold text-lg">No model selected</h3>
<p id="modelAuthor" class="text-sm text-gray-500">Select a model to begin</p>
</div>
</div>
<div class="space-y-3">
<div>
<span class="text-sm font-medium text-gray-500">Type:</span>
<span id="modelType" class="ml-2 text-sm">-</span>
</div>
<div>
<span class="text-sm font-medium text-gray-500">Tasks:</span>
<div id="modelTasks" class="flex flex-wrap gap-2 mt-1">
<span class="text-xs px-2 py-1 bg-gray-100 rounded-full">Select a model</span>
</div>
</div>
<div>
<span class="text-sm font-medium text-gray-500">Downloads:</span>
<span id="modelDownloads" class="ml-2 text-sm">-</span>
</div>
<div>
<span class="text-sm font-medium text-gray-500">Last Updated:</span>
<span id="modelUpdated" class="ml-2 text-sm">-</span>
</div>
</div>
</div>
</div>
<!-- Chat Interface -->
<div class="lg:col-span-2">
<div class="bg-white rounded-xl shadow-md overflow-hidden">
<!-- Chat Header -->
<div class="bg-gray-50 px-6 py-4 border-b flex justify-between items-center">
<h2 class="font-semibold flex items-center">
<i class="fas fa-comments mr-2 text-indigo-600"></i>
Model Interaction
</h2>
<div id="modelStatus" class="flex items-center text-sm">
<span class="w-2 h-2 rounded-full bg-gray-400 mr-2"></span>
<span>Disconnected</span>
</div>
</div>
<!-- Chat Messages -->
<div id="chatContainer" class="h-96 overflow-y-auto p-4 space-y-4 bg-gray-50">
<div class="text-center py-10 text-gray-500">
<i class="fas fa-comment-dots text-3xl mb-2"></i>
<p>Select a model and start chatting or generating content</p>
</div>
</div>
<!-- Input Area -->
<div class="p-4 border-t bg-white">
<div id="textInputSection">
<div class="flex space-x-2 mb-2">
<button id="clearChatBtn" class="px-3 py-1 bg-gray-100 rounded-lg text-sm hover:bg-gray-200">
<i class="fas fa-trash-alt mr-1"></i> Clear
</button>
<button id="examplePromptBtn" class="px-3 py-1 bg-gray-100 rounded-lg text-sm hover:bg-gray-200">
<i class="fas fa-lightbulb mr-1"></i> Examples
</button>
</div>
<div class="flex">
<textarea id="userInput" rows="2" placeholder="Type your message or prompt here..." class="flex-1 px-4 py-3 border border-gray-300 rounded-l-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 resize-none"></textarea>
<button id="sendMessageBtn" class="px-6 bg-indigo-600 hover:bg-indigo-700 text-white rounded-r-lg transition">
<i class="fas fa-paper-plane"></i>
</button>
</div>
</div>
<div id="imageInputSection" class="hidden">
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-2">Prompt for Image Generation</label>
<textarea id="imagePrompt" rows="2" placeholder="Describe the image you want to generate..." class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 resize-none"></textarea>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Number of Images</label>
<select id="imageCount" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500">
<option value="1">1</option>
<option value="2">2</option>
<option value="4">4</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Image Size</label>
<select id="imageSize" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500">
<option value="256x256">256x256</option>
<option value="512x512">512x512</option>
<option value="1024x1024">1024x1024</option>
</select>
</div>
</div>
<button id="generateImageBtn" class="w-full mt-4 bg-indigo-600 hover:bg-indigo-700 text-white py-3 px-4 rounded-lg transition flex items-center justify-center space-x-2">
<i class="fas fa-magic"></i>
<span>Generate Image</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Example Prompts Modal -->
<div id="examplePromptsModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-xl shadow-xl w-full max-w-2xl max-h-[80vh] overflow-hidden">
<div class="flex justify-between items-center px-6 py-4 border-b">
<h3 class="text-lg font-semibold">Example Prompts</h3>
<button id="closeExampleModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="p-6 overflow-y-auto">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-blue-50 p-4 rounded-lg">
<h4 class="font-medium text-blue-800 mb-2">Text Generation</h4>
<ul class="space-y-2 text-sm">
<li class="cursor-pointer hover:bg-blue-100 p-2 rounded" onclick="useExamplePrompt(this)">Write a short story about a robot discovering emotions</li>
<li class="cursor-pointer hover:bg-blue-100 p-2 rounded" onclick="useExamplePrompt(this)">Explain quantum computing in simple terms</li>
<li class="cursor-pointer hover:bg-blue-100 p-2 rounded" onclick="useExamplePrompt(this)">Generate a poem about the changing seasons</li>
</ul>
</div>
<div class="bg-purple-50 p-4 rounded-lg">
<h4 class="font-medium text-purple-800 mb-2">Image Generation</h4>
<ul class="space-y-2 text-sm">
<li class="cursor-pointer hover:bg-purple-100 p-2 rounded" onclick="useExamplePrompt(this)">A futuristic cityscape at sunset, digital art</li>
<li class="cursor-pointer hover:bg-purple-100 p-2 rounded" onclick="useExamplePrompt(this)">A cute corgi puppy wearing sunglasses on a beach</li>
<li class="cursor-pointer hover:bg-purple-100 p-2 rounded" onclick="useExamplePrompt(this)">An astronaut riding a horse in space, surreal art</li>
</ul>
</div>
<div class="bg-green-50 p-4 rounded-lg">
<h4 class="font-medium text-green-800 mb-2">Code Generation</h4>
<ul class="space-y-2 text-sm">
<li class="cursor-pointer hover:bg-green-100 p-2 rounded" onclick="useExamplePrompt(this)">Write a Python function to calculate Fibonacci sequence</li>
<li class="cursor-pointer hover:bg-green-100 p-2 rounded" onclick="useExamplePrompt(this)">Create a React component for a login form</li>
<li class="cursor-pointer hover:bg-green-100 p-2 rounded" onclick="useExamplePrompt(this)">Generate SQL query to find customers with most orders</li>
</ul>
</div>
<div class="bg-yellow-50 p-4 rounded-lg">
<h4 class="font-medium text-yellow-800 mb-2">Translation</h4>
<ul class="space-y-2 text-sm">
<li class="cursor-pointer hover:bg-yellow-100 p-2 rounded" onclick="useExamplePrompt(this)">Translate 'Hello, how are you?' to French</li>
<li class="cursor-pointer hover:bg-yellow-100 p-2 rounded" onclick="useExamplePrompt(this)">Convert this text to Spanish: 'The weather is nice today'</li>
<li class="cursor-pointer hover:bg-yellow-100 p-2 rounded" onclick="useExamplePrompt(this)">What does 'こんにちは' mean in English?</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<script>
// DOM Elements
const darkModeToggle = document.getElementById('darkModeToggle');
const accessTokenInput = document.getElementById('accessToken');
const toggleTokenVisibility = document.getElementById('toggleTokenVisibility');
const saveTokenBtn = document.getElementById('saveTokenBtn');
const modelTypeFilter = document.getElementById('modelTypeFilter');
const modelSearch = document.getElementById('modelSearch');
const modelsContainer = document.getElementById('modelsContainer');
const modelLoading = document.getElementById('modelLoading');
const pagination = document.getElementById('pagination');
const prevPageBtn = document.getElementById('prevPage');
const nextPageBtn = document.getElementById('nextPage');
const pageNumbers = document.getElementById('pageNumbers');
const interactionSection = document.getElementById('interactionSection');
const clearModelBtn = document.getElementById('clearModelBtn');
const modelName = document.getElementById('modelName');
const modelAuthor = document.getElementById('modelAuthor');
const modelType = document.getElementById('modelType');
const modelTasks = document.getElementById('modelTasks');
const modelDownloads = document.getElementById('modelDownloads');
const modelUpdated = document.getElementById('modelUpdated');
const modelAvatar = document.getElementById('modelAvatar');
const modelStatus = document.getElementById('modelStatus');
const chatContainer = document.getElementById('chatContainer');
const userInput = document.getElementById('userInput');
const sendMessageBtn = document.getElementById('sendMessageBtn');
const clearChatBtn = document.getElementById('clearChatBtn');
const examplePromptBtn = document.getElementById('examplePromptBtn');
const textInputSection = document.getElementById('textInputSection');
const imageInputSection = document.getElementById('imageInputSection');
const imagePrompt = document.getElementById('imagePrompt');
const imageCount = document.getElementById('imageCount');
const imageSize = document.getElementById('imageSize');
const generateImageBtn = document.getElementById('generateImageBtn');
const examplePromptsModal = document.getElementById('examplePromptsModal');
const closeExampleModal = document.getElementById('closeExampleModal');
// State
let currentPage = 1;
let totalPages = 1;
let modelsPerPage = 9;
let allModels = [];
let filteredModels = [];
let selectedModel = null;
let accessToken = localStorage.getItem('hfAccessToken') || '';
let isDarkMode = localStorage.getItem('darkMode') === 'true';
let chatHistory = [];
// Initialize
document.addEventListener('DOMContentLoaded', () => {
// Set dark mode if enabled
if (isDarkMode) {
enableDarkMode();
}
// Set saved token if exists
if (accessToken) {
accessTokenInput.value = accessToken;
}
// Load models
loadModels();
});
// Event Listeners
darkModeToggle.addEventListener('click', toggleDarkMode);
toggleTokenVisibility.addEventListener('click', toggleTokenVisibilityHandler);
saveTokenBtn.addEventListener('click', saveAccessToken);
modelTypeFilter.addEventListener('change', filterModels);
modelSearch.addEventListener('input', filterModels);
prevPageBtn.addEventListener('click', () => changePage(-1));
nextPageBtn.addEventListener('click', () => changePage(1));
clearModelBtn.addEventListener('click', clearSelectedModel);
sendMessageBtn.addEventListener('click', sendMessage);
userInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
clearChatBtn.addEventListener('click', clearChat);
examplePromptBtn.addEventListener('click', showExamplePrompts);
closeExampleModal.addEventListener('click', () => {
examplePromptsModal.classList.add('hidden');
});
generateImageBtn.addEventListener('click', generateImage);
// Functions
function toggleDarkMode() {
isDarkMode = !isDarkMode;
localStorage.setItem('darkMode', isDarkMode);
if (isDarkMode) {
enableDarkMode();
} else {
disableDarkMode();
}
}
function enableDarkMode() {
document.documentElement.classList.add('dark');
darkModeToggle.innerHTML = '<i class="fas fa-sun"></i>';
document.body.classList.add('bg-gray-900');
document.body.classList.remove('bg-gray-50');
}
function disableDarkMode() {
document.documentElement.classList.remove('dark');
darkModeToggle.innerHTML = '<i class="fas fa-moon"></i>';
document.body.classList.remove('bg-gray-900');
document.body.classList.add('bg-gray-50');
}
function toggleTokenVisibilityHandler() {
const icon = toggleTokenVisibility.querySelector('i');
if (accessTokenInput.type === 'password') {
accessTokenInput.type = 'text';
icon.classList.replace('fa-eye', 'fa-eye-slash');
} else {
accessTokenInput.type = 'password';
icon.classList.replace('fa-eye-slash', 'fa-eye');
}
}
function saveAccessToken() {
accessToken = accessTokenInput.value.trim();
if (accessToken) {
localStorage.setItem('hfAccessToken', accessToken);
showToast('Access token saved successfully!', 'success');
loadModels(); // Reload models with new token
} else {
showToast('Please enter a valid access token', 'error');
}
}
async function loadModels() {
if (!accessToken) {
showToast('Please enter your Hugging Face access token first', 'error');
return;
}
try {
modelLoading.classList.remove('hidden');
modelsContainer.classList.add('hidden');
pagination.classList.add('hidden');
// In a real app, you would fetch from Hugging Face API
// const response = await fetch('https://huggingface.co/api/models', {
// headers: {
// 'Authorization': `Bearer ${accessToken}`
// }
// });
// allModels = await response.json();
// For demo purposes, we'll use mock data
allModels = getMockModels();
filterModels();
modelLoading.classList.add('hidden');
} catch (error) {
console.error('Error loading models:', error);
showToast('Failed to load models. Check your token and try again.', 'error');
modelLoading.classList.add('hidden');
}
}
function filterModels() {
const searchTerm = modelSearch.value.toLowerCase();
const typeFilter = modelTypeFilter.value;
filteredModels = allModels.filter(model => {
const matchesSearch = model.name.toLowerCase().includes(searchTerm) ||
model.author.toLowerCase().includes(searchTerm) ||
model.tags.some(tag => tag.toLowerCase().includes(searchTerm));
const matchesType = typeFilter === 'all' ||
(typeFilter === 'text' && model.type === 'text') ||
(typeFilter === 'image' && model.type === 'image') ||
(typeFilter === 'audio' && model.type === 'audio') ||
(typeFilter === 'multimodal' && model.type === 'multimodal');
return matchesSearch && matchesType;
});
totalPages = Math.ceil(filteredModels.length / modelsPerPage);
renderModels();
renderPagination();
}
function renderModels() {
modelsContainer.innerHTML = '';
const startIndex = (currentPage - 1) * modelsPerPage;
const endIndex = Math.min(startIndex + modelsPerPage, filteredModels.length);
for (let i = startIndex; i < endIndex; i++) {
const model = filteredModels[i];
const modelCard = document.createElement('div');
modelCard.className = 'model-card bg-white rounded-xl shadow-sm p-4 border border-gray-200 hover:border-purple-300 transition cursor-pointer';
modelCard.innerHTML = `
<div class="flex items-start space-x-3">
<div class="flex-shrink-0 w-12 h-12 rounded-lg ${getModelColorClass(model.type)} flex items-center justify-center">
${getModelIcon(model.type)}
</div>
<div class="flex-1 min-w-0">
<h3 class="font-medium text-gray-900 truncate">${model.name}</h3>
<p class="text-sm text-gray-500 truncate">by ${model.author}</p>
<div class="flex flex-wrap gap-1 mt-2">
${model.tags.slice(0, 3).map(tag => `<span class="text-xs px-2 py-1 ${getTagColorClass(tag)} rounded-full">${tag}</span>`).join('')}
${model.tags.length > 3 ? `<span class="text-xs px-2 py-1 bg-gray-100 rounded-full">+${model.tags.length - 3}</span>` : ''}
</div>
</div>
</div>
`;
modelCard.addEventListener('click', () => selectModel(model));
modelsContainer.appendChild(modelCard);
}
modelsContainer.classList.remove('hidden');
}
function renderPagination() {
pageNumbers.innerHTML = '';
// Always show first page
addPageNumber(1);
// Show ellipsis if needed
if (currentPage > 3) {
const ellipsis = document.createElement('span');
ellipsis.className = 'px-4 py-2';
ellipsis.textContent = '...';
pageNumbers.appendChild(ellipsis);
}
// Show current page and neighbors
for (let i = Math.max(2, currentPage - 1); i <= Math.min(totalPages - 1, currentPage + 1); i++) {
addPageNumber(i);
}
// Show ellipsis if needed
if (currentPage < totalPages - 2) {
const ellipsis = document.createElement('span');
ellipsis.className = 'px-4 py-2';
ellipsis.textContent = '...';
pageNumbers.appendChild(ellipsis);
}
// Always show last page if different from first
if (totalPages > 1) {
addPageNumber(totalPages);
}
prevPageBtn.disabled = currentPage === 1;
nextPageBtn.disabled = currentPage === totalPages;
pagination.classList.remove('hidden');
}
function addPageNumber(page) {
const pageBtn = document.createElement('button');
pageBtn.className = `px-4 py-2 rounded-lg ${currentPage === page ? 'bg-purple-600 text-white' : 'bg-gray-100 hover:bg-gray-200'}`;
pageBtn.textContent = page;
pageBtn.addEventListener('click', () => {
currentPage = page;
renderModels();
renderPagination();
});
pageNumbers.appendChild(pageBtn);
}
function changePage(delta) {
const newPage = currentPage + delta;
if (newPage > 0 && newPage <= totalPages) {
currentPage = newPage;
renderModels();
renderPagination();
}
}
function selectModel(model) {
selectedModel = model;
interactionSection.classList.remove('hidden');
// Update model info
modelName.textContent = model.name;
modelAuthor.textContent = `by ${model.author}`;
modelType.textContent = model.type.charAt(0).toUpperCase() + model.type.slice(1);
modelDownloads.textContent = model.downloads.toLocaleString();
modelUpdated.textContent = new Date(model.lastUpdated).toLocaleDateString();
// Update model tasks
modelTasks.innerHTML = '';
model.tasks.forEach(task => {
const taskEl = document.createElement('span');
taskEl.className = 'text-xs px-2 py-1 bg-blue-100 text-blue-800 rounded-full';
taskEl.textContent = task;
modelTasks.appendChild(taskEl);
});
// Update model avatar
modelAvatar.className = `w-16 h-16 rounded-lg ${getModelColorClass(model.type)} flex items-center justify-center mr-4`;
modelAvatar.innerHTML = getModelIcon(model.type, 'text-2xl');
// Update status
updateModelStatus('connected');
// Show appropriate input section
if (model.type === 'image') {
textInputSection.classList.add('hidden');
imageInputSection.classList.remove('hidden');
clearChat();
} else {
textInputSection.classList.remove('hidden');
imageInputSection.classList.add('hidden');
addSystemMessage(`You are now interacting with the ${model.name} model. What would you like to do?`);
}
// Scroll to interaction section
interactionSection.scrollIntoView({ behavior: 'smooth' });
}
function clearSelectedModel() {
selectedModel = null;
interactionSection.classList.add('hidden');
updateModelStatus('disconnected');
clearChat();
}
function updateModelStatus(status) {
const statusDot = modelStatus.querySelector('span');
const statusText = modelStatus.querySelector('span:last-child');
if (status === 'connected') {
statusDot.className = 'w-2 h-2 rounded-full bg-green-500 mr-2';
statusText.textContent = 'Connected';
} else if (status === 'connecting') {
statusDot.className = 'w-2 h-2 rounded-full bg-yellow-500 mr-2';
statusText.textContent = 'Connecting...';
} else {
statusDot.className = 'w-2 h-2 rounded-full bg-gray-400 mr-2';
statusText.textContent = 'Disconnected';
}
}
function addSystemMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.className = 'flex justify-center';
const contentDiv = document.createElement('div');
contentDiv.className = 'bg-gray-200 text-gray-700 px-4 py-2 rounded-lg text-sm';
contentDiv.textContent = message;
messageDiv.appendChild(contentDiv);
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
function addUserMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.className = 'flex justify-end';
const contentDiv = document.createElement('div');
contentDiv.className = 'bg-blue-600 text-white px-4 py-2 chat-message-user max-w-xs md:max-w-md';
contentDiv.textContent = message;
messageDiv.appendChild(contentDiv);
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
// Add to chat history
chatHistory.push({ role: 'user', content: message });
}
function addAIMessage(message, isImage = false) {
const messageDiv = document.createElement('div');
messageDiv.className = 'flex justify-start';
const contentDiv = document.createElement('div');
contentDiv.className = 'bg-gray-100 text-gray-800 px-4 py-2 chat-message-ai max-w-xs md:max-w-md';
if (isImage) {
// For images, we'd typically get a URL from the API
// Here we'll just show a placeholder
const img = document.createElement('img');
img.src = 'https://via.placeholder.com/512/7c3aed/ffffff?text=Generated+Image';
img.alt = 'Generated image';
img.className = 'w-full h-auto rounded-lg';
contentDiv.appendChild(img);
contentDiv.appendChild(document.createElement('br'));
const caption = document.createElement('p');
caption.className = 'text-sm mt-2';
caption.textContent = 'Generated image based on your prompt';
contentDiv.appendChild(caption);
} else {
contentDiv.textContent = message;
}
messageDiv.appendChild(contentDiv);
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
// Add to chat history
chatHistory.push({ role: 'assistant', content: message });
}
function addLoadingMessage() {
const messageDiv = document.createElement('div');
messageDiv.className = 'flex justify-start';
const contentDiv = document.createElement('div');
contentDiv.className = 'bg-gray-100 text-gray-800 px-4 py-2 chat-message-ai max-w-xs md:max-w-md';
contentDiv.innerHTML = '<div class="loading-dots">Generating response</div>';
messageDiv.appendChild(contentDiv);
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
return contentDiv;
}
function clearChat() {
chatContainer.innerHTML = `
<div class="text-center py-10 text-gray-500">
<i class="fas fa-comment-dots text-3xl mb-2"></i>
<p>Select a model and start chatting or generating content</p>
</div>
`;
chatHistory = [];
}
function sendMessage() {
const message = userInput.value.trim();
if (!message) return;
if (!selectedModel) {
showToast('Please select a model first', 'error');
return;
}
addUserMessage(message);
userInput.value = '';
// Show loading message
const loadingElement = addLoadingMessage();
// Simulate API call
setTimeout(() => {
// Replace loading message with response
loadingElement.classList.remove('loading-dots');
loadingElement.textContent = '';
// Generate a mock response based on model type
let response;
if (selectedModel.type === 'text') {
response = `This is a mock response from the ${selectedModel.name} model. In a real implementation, this would be the actual response from the Hugging Face API.`;
} else if (selectedModel.type === 'image') {
response = `I'm an image generation model. Please use the image generation panel below to create images.`;
} else {
response = `I'm a ${selectedModel.type} model. Here's a sample response based on your input.`;
}
loadingElement.textContent = response;
// Add to chat history
chatHistory.push({ role: 'assistant', content: response });
}, 1500);
}
function generateImage() {
const prompt = imagePrompt.value.trim();
if (!prompt) {
showToast('Please enter an image prompt', 'error');
return;
}
if (!selectedModel || selectedModel.type !== 'image') {
showToast('Please select an image generation model first', 'error');
return;
}
// Clear previous chat and add user prompt
clearChat();
addUserMessage(`Generate image: ${prompt}`);
// Show loading message
const loadingElement = addLoadingMessage();
// Simulate API call to generate image
setTimeout(() => {
// Replace loading message with image
loadingElement.classList.remove('loading-dots');
loadingElement.textContent = '';
// Add mock generated image
addAIMessage('', true);
showToast('Image generated successfully!', 'success');
}, 2500);
}
function showExamplePrompts() {
examplePromptsModal.classList.remove('hidden');
}
function useExamplePrompt(element) {
const prompt = element.textContent;
if (selectedModel?.type === 'image') {
imagePrompt.value = prompt;
examplePromptsModal.classList.add('hidden');
} else {
userInput.value = prompt;
examplePromptsModal.classList.add('hidden');
userInput.focus();
}
}
function showToast(message, type = 'info') {
const toast = document.createElement('div');
toast.className = `fixed bottom-4 right-4 px-6 py-3 rounded-lg shadow-lg text-white ${
type === 'success' ? 'bg-green-500' :
type === 'error' ? 'bg-red-500' :
'bg-blue-500'
} flex items-center space-x-2 z-50`;
toast.innerHTML = `
<i class="fas ${
type === 'success' ? 'fa-check-circle' :
type === 'error' ? 'fa-exclamation-circle' :
'fa-info-circle'
}"></i>
<span>${message}</span>
`;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
setTimeout(() => toast.remove(), 300);
}, 3000);
}
function getModelColorClass(type) {
switch(type) {
case 'text': return 'bg-blue-100 text-blue-800';
case 'image': return 'bg-purple-100 text-purple-800';
case 'audio': return 'bg-green-100 text-green-800';
case 'multimodal': return 'bg-indigo-100 text-indigo-800';
default: return 'bg-gray-100 text-gray-800';
}
}
function getModelIcon(type, size = 'text-xl') {
switch(type) {
case 'text': return `<i class="fas fa-font ${size}"></i>`;
case 'image': return `<i class="fas fa-image ${size}"></i>`;
case 'audio': return `<i class="fas fa-music ${size}"></i>`;
case 'multimodal': return `<i class="fas fa-shapes ${size}"></i>`;
default: return `<i class="fas fa-cube ${size}"></i>`;
}
}
function getTagColorClass(tag) {
// Simple hash function to get consistent colors for tags
let hash = 0;
for (let i = 0; i < tag.length; i++) {
hash = tag.charCodeAt(i) + ((hash << 5) - hash);
}
const colors = [
'bg-blue-100 text-blue-800',
'bg-green-100 text-green-800',
'bg-yellow-100 text-yellow-800',
'bg-red-100 text-red-800',
'bg-purple-100 text-purple-800',
'bg-pink-100 text-pink-800',
'bg-indigo-100 text-indigo-800'
];
return colors[Math.abs(hash) % colors.length];
}
// Mock data for demonstration
function getMockModels() {
return [
{
id: 'gpt2',
name: 'gpt2',
author: 'openai',
type: 'text',
tags: ['text-generation', 'gpt', 'transformers'],
downloads: 15000000,
lastUpdated: '2023-05-15',
tasks: ['text-generation', 'text-completion']
},
{
id: 'stable-diffusion-v1-5',
name: 'stable-diffusion-v1-5',
author: 'CompVis',
type: 'image',
tags: ['text-to-image', 'diffusion', 'stable-diffusion'],
downloads: 8500000,
lastUpdated: '2023-04-20',
tasks: ['text-to-image']
},
{
id: 'bert-base-uncased',
name: 'bert-base-uncased',
author: 'google',
type: 'text',
tags: ['fill-mask', 'bert', 'transformers'],
downloads: 12000000,
lastUpdated: '2023-03-10',
tasks: ['fill-mask', 'feature-extraction']
},
{
id: 'whisper-large',
name: 'whisper-large',
author: 'openai',
type: 'audio',
tags: ['automatic-speech-recognition', 'whisper'],
downloads: 5000000,
lastUpdated: '2023-06-01',
tasks: ['automatic-speech-recognition']
},
{
id: 'blip-image-captioning-base',
name: 'blip-image-captioning-base',
author: 'Salesforce',
type: 'multimodal',
tags: ['image-to-text', 'captioning', 'blip'],
downloads: 3200000,
lastUpdated: '2023-02-18',
tasks: ['image-to-text']
},
{
id: 't5-base',
name: 't5-base',
author: 'google',
type: 'text',
tags: ['text2text-generation', 't5', 'transformers'],
downloads: 9000000,
lastUpdated: '2023-01-30',
tasks: ['summarization', 'translation', 'text-generation']
},
{
id: 'clip-vit-base-patch32',
name: 'clip-vit-base-patch32',
author: 'openai',
type: 'multimodal',
tags: ['zero-shot-image-classification', 'clip'],
downloads: 2800000,
lastUpdated: '2023-05-22',
tasks: ['zero-shot-image-classification']
},
{
id: 'distilbert-base-uncased',
name: 'distilbert-base-uncased',
author: 'huggingface',
type: 'text',
tags: ['distilled', 'bert', 'transformers'],
downloads: 11000000,
lastUpdated: '2023-04-05',
tasks: ['fill-mask', 'text-classification']
},
{
id: 'vilt-b32-finetuned-vqa',
name: 'vilt-b32-finetuned-vqa',
author: 'dandelin',
type: 'multimodal',
tags: ['visual-question-answering', 'vilt'],
downloads: 1500000,
lastUpdated: '2023-03-15',
tasks: ['visual-question-answering']
}
];
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=CJHauser/tryhfmodelswithatoken" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |