catmorpher / index.html
throwawaydoug666's picture
can the huggingface api actually do image to image or controlnet? - Initial Deployment
5521869 verified
Raw History Blame Contribute Delete
22.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hugging Face Image Processing</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>
.dropzone {
border: 2px dashed #ccc;
transition: all 0.3s ease;
}
.dropzone.active {
border-color: #4f46e5;
background-color: #eef2ff;
}
.preview-image {
max-height: 300px;
object-fit: contain;
}
.loading-spinner {
display: none;
}
.processing .loading-spinner {
display: block;
}
.processing .processing-text {
display: none;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="mb-8 text-center">
<h1 class="text-3xl font-bold text-indigo-700 mb-2">Hugging Face Image Processing</h1>
<p class="text-gray-600">Explore image-to-image transformations and ControlNet capabilities</p>
</header>
<div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
<div class="p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">API Information</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="bg-indigo-50 p-4 rounded-lg">
<h3 class="font-medium text-indigo-700 mb-2">Image-to-Image</h3>
<p class="text-gray-700 mb-3">Hugging Face provides several models for image-to-image transformations including:</p>
<ul class="list-disc pl-5 text-gray-700 space-y-1">
<li>Stable Diffusion Image Variations</li>
<li>Stable Diffusion Inpainting</li>
<li>Super-resolution models</li>
<li>Style transfer models</li>
</ul>
</div>
<div class="bg-purple-50 p-4 rounded-lg">
<h3 class="font-medium text-purple-700 mb-2">ControlNet</h3>
<p class="text-gray-700 mb-3">ControlNet models allow for precise control over image generation:</p>
<ul class="list-disc pl-5 text-gray-700 space-y-1">
<li>Canny edge detection</li>
<li>Depth estimation</li>
<li>Human pose detection</li>
<li>Semantic segmentation</li>
</ul>
</div>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Image Upload Section -->
<div class="bg-white rounded-xl shadow-md overflow-hidden">
<div class="p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Upload Your Image</h2>
<div id="dropzone" class="dropzone rounded-lg p-8 text-center cursor-pointer mb-4">
<div class="flex flex-col items-center justify-center">
<i class="fas fa-cloud-upload-alt text-4xl text-indigo-500 mb-2"></i>
<p class="text-gray-600 mb-1">Drag & drop your image here</p>
<p class="text-sm text-gray-500">or click to browse</p>
</div>
<input type="file" id="fileInput" class="hidden" accept="image/*">
</div>
<div id="imagePreviewContainer" class="hidden mb-4">
<h3 class="font-medium text-gray-700 mb-2">Preview</h3>
<div class="flex justify-center">
<img id="imagePreview" src="#" alt="Preview" class="preview-image rounded-lg border border-gray-200">
</div>
</div>
<div class="flex justify-between items-center">
<button id="clearBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition hidden">
<i class="fas fa-trash-alt mr-2"></i>Clear
</button>
<button id="useSampleBtn" class="px-4 py-2 bg-indigo-100 text-indigo-700 rounded-lg hover:bg-indigo-200 transition">
<i class="fas fa-magic mr-2"></i>Use Sample Image
</button>
</div>
</div>
</div>
<!-- Processing Options -->
<div class="bg-white rounded-xl shadow-md overflow-hidden">
<div class="p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Processing Options</h2>
<div class="mb-6">
<label class="block text-gray-700 font-medium mb-2">Processing Type</label>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<input type="radio" id="img2img" name="processType" value="img2img" class="hidden peer" checked>
<label for="img2img" class="flex items-center p-4 border border-gray-200 rounded-lg cursor-pointer peer-checked:border-indigo-500 peer-checked:bg-indigo-50">
<i class="fas fa-exchange-alt text-indigo-500 mr-3"></i>
<div>
<h4 class="font-medium">Image-to-Image</h4>
<p class="text-sm text-gray-600">Transform your image</p>
</div>
</label>
</div>
<div>
<input type="radio" id="controlnet" name="processType" value="controlnet" class="hidden peer">
<label for="controlnet" class="flex items-center p-4 border border-gray-200 rounded-lg cursor-pointer peer-checked:border-purple-500 peer-checked:bg-purple-50">
<i class="fas fa-project-diagram text-purple-500 mr-3"></i>
<div>
<h4 class="font-medium">ControlNet</h4>
<p class="text-sm text-gray-600">Precise control over generation</p>
</div>
</label>
</div>
</div>
</div>
<!-- Image-to-Image Options -->
<div id="img2imgOptions">
<div class="mb-4">
<label for="prompt" class="block text-gray-700 font-medium mb-2">Prompt</label>
<input type="text" id="prompt" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-indigo-500 focus:border-indigo-500" placeholder="Describe how you want to transform the image">
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
<div>
<label for="strength" class="block text-gray-700 font-medium mb-2">Transformation Strength</label>
<input type="range" id="strength" min="0" max="1" step="0.1" value="0.5" class="w-full">
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span>Subtle</span>
<span>Strong</span>
</div>
</div>
<div>
<label for="guidance" class="block text-gray-700 font-medium mb-2">Guidance Scale</label>
<input type="range" id="guidance" min="1" max="20" step="1" value="7" class="w-full">
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span>1</span>
<span>20</span>
</div>
</div>
</div>
</div>
<!-- ControlNet Options -->
<div id="controlnetOptions" class="hidden">
<div class="mb-4">
<label for="controlType" class="block text-gray-700 font-medium mb-2">Control Type</label>
<select id="controlType" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500">
<option value="canny">Canny Edge</option>
<option value="depth">Depth Map</option>
<option value="pose">Human Pose</option>
<option value="segmentation">Semantic Segmentation</option>
</select>
</div>
<div class="mb-4">
<label for="controlPrompt" class="block text-gray-700 font-medium mb-2">Generation Prompt</label>
<input type="text" id="controlPrompt" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500" placeholder="Describe what you want to generate">
</div>
<div class="mb-4">
<label for="controlStrength" class="block text-gray-700 font-medium mb-2">Control Strength</label>
<input type="range" id="controlStrength" min="0" max="1" step="0.1" value="0.8" class="w-full">
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span>Low</span>
<span>High</span>
</div>
</div>
</div>
<button id="processBtn" class="w-full py-3 px-4 bg-indigo-600 text-white font-medium rounded-lg hover:bg-indigo-700 transition flex items-center justify-center">
<span class="processing-text">Process Image</span>
<div class="loading-spinner">
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
Processing...
</div>
</button>
</div>
</div>
</div>
<!-- Results Section -->
<div id="resultsSection" class="hidden mt-8 bg-white rounded-xl shadow-md overflow-hidden">
<div class="p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Results</h2>
<div id="resultsContainer" class="grid grid-cols-1 md:grid-cols-2 gap-6">
<!-- Results will be displayed here -->
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM elements
const dropzone = document.getElementById('dropzone');
const fileInput = document.getElementById('fileInput');
const imagePreview = document.getElementById('imagePreview');
const imagePreviewContainer = document.getElementById('imagePreviewContainer');
const clearBtn = document.getElementById('clearBtn');
const useSampleBtn = document.getElementById('useSampleBtn');
const processBtn = document.getElementById('processBtn');
const img2imgOptions = document.getElementById('img2imgOptions');
const controlnetOptions = document.getElementById('controlnetOptions');
const resultsSection = document.getElementById('resultsSection');
const resultsContainer = document.getElementById('resultsContainer');
// Radio buttons for processing type
const processTypeRadios = document.querySelectorAll('input[name="processType"]');
// Drag and drop functionality
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropzone.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropzone.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropzone.classList.add('active');
}
function unhighlight() {
dropzone.classList.remove('active');
}
dropzone.addEventListener('drop', handleDrop, false);
dropzone.addEventListener('click', () => fileInput.click());
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
handleFiles(files);
}
fileInput.addEventListener('change', function() {
handleFiles(this.files);
});
function handleFiles(files) {
if (files.length === 0) return;
const file = files[0];
if (!file.type.match('image.*')) {
alert('Please select an image file.');
return;
}
const reader = new FileReader();
reader.onload = function(e) {
imagePreview.src = e.target.result;
imagePreviewContainer.classList.remove('hidden');
clearBtn.classList.remove('hidden');
};
reader.readAsDataURL(file);
}
// Clear button
clearBtn.addEventListener('click', function() {
imagePreview.src = '#';
imagePreviewContainer.classList.add('hidden');
clearBtn.classList.add('hidden');
fileInput.value = '';
});
// Use sample image
useSampleBtn.addEventListener('click', function() {
imagePreview.src = 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/compel-neg.png';
imagePreviewContainer.classList.remove('hidden');
clearBtn.classList.remove('hidden');
});
// Toggle between img2img and controlnet options
processTypeRadios.forEach(radio => {
radio.addEventListener('change', function() {
if (this.value === 'img2img') {
img2imgOptions.classList.remove('hidden');
controlnetOptions.classList.add('hidden');
} else {
img2imgOptions.classList.add('hidden');
controlnetOptions.classList.remove('hidden');
}
});
});
// Process button
processBtn.addEventListener('click', function() {
if (imagePreview.src === '#') {
alert('Please upload or select an image first.');
return;
}
// Show loading state
processBtn.classList.add('processing');
// Simulate API call (in a real app, you would call Hugging Face API here)
setTimeout(() => {
// Hide loading state
processBtn.classList.remove('processing');
// Show results
resultsSection.classList.remove('hidden');
// Clear previous results
resultsContainer.innerHTML = '';
// Get selected processing type
const processType = document.querySelector('input[name="processType"]:checked').value;
// Create result cards
if (processType === 'img2img') {
const prompt = document.getElementById('prompt').value || 'No prompt provided';
resultsContainer.innerHTML = `
<div class="bg-white border border-gray-200 rounded-lg overflow-hidden">
<div class="p-4 bg-indigo-50">
<h3 class="font-medium text-indigo-700">Original Image</h3>
</div>
<div class="p-4">
<img src="${imagePreview.src}" alt="Original" class="w-full h-48 object-contain">
</div>
</div>
<div class="bg-white border border-gray-200 rounded-lg overflow-hidden">
<div class="p-4 bg-indigo-50">
<h3 class="font-medium text-indigo-700">Transformed Image</h3>
<p class="text-sm text-gray-600 mt-1">Prompt: "${prompt}"</p>
</div>
<div class="p-4">
<div class="bg-gray-100 w-full h-48 flex items-center justify-center text-gray-500">
<div class="text-center">
<i class="fas fa-image text-4xl mb-2"></i>
<p>Generated result would appear here</p>
</div>
</div>
</div>
</div>
`;
} else {
const controlType = document.getElementById('controlType').value;
const controlPrompt = document.getElementById('controlPrompt').value || 'No prompt provided';
resultsContainer.innerHTML = `
<div class="bg-white border border-gray-200 rounded-lg overflow-hidden">
<div class="p-4 bg-purple-50">
<h3 class="font-medium text-purple-700">Original Image</h3>
</div>
<div class="p-4">
<img src="${imagePreview.src}" alt="Original" class="w-full h-48 object-contain">
</div>
</div>
<div class="bg-white border border-gray-200 rounded-lg overflow-hidden">
<div class="p-4 bg-purple-50">
<h3 class="font-medium text-purple-700">ControlNet: ${controlType}</h3>
<p class="text-sm text-gray-600 mt-1">Prompt: "${controlPrompt}"</p>
</div>
<div class="p-4">
<div class="bg-gray-100 w-full h-48 flex items-center justify-center text-gray-500">
<div class="text-center">
<i class="fas fa-project-diagram text-4xl mb-2"></i>
<p>ControlNet result would appear here</p>
</div>
</div>
</div>
</div>
`;
}
}, 1500);
});
// Note: In a real application, you would need to:
// 1. Get a Hugging Face API token
// 2. Implement actual API calls to their inference endpoints
// 3. Handle the responses properly
// This is just a UI demonstration
});
</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=throwawaydoug666/catmorpher" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>