Spaces:
Running
Running
<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> |