File size: 5,995 Bytes
b1f7310 |
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 |
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🩷Colara🩷</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f2f5;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px;
text-align: center;
}
.container {
width: 100%;
max-width: 800px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
padding: 30px;
}
h1 {
color: #333;
}
.file-upload-section {
margin: 20px 0;
}
.file-upload-section label {
background-color: #007bff;
color: #fff;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.3s;
}
.file-upload-section label:hover {
background-color: #0056b3;
}
#upload-input {
display: none;
}
.image-display {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
margin-top: 20px;
gap: 20px;
}
.image-box {
display: flex;
flex-direction: column;
align-items: center;
}
.image-box canvas, .image-box img {
max-width: 350px;
border: 2px dashed #ccc;
border-radius: 5px;
}
.image-box h3 {
margin-top: 10px;
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>🩷Colara🩷</h1>
<p>L'IA qui change les couleurs de vos images.</p>
<div class="file-upload-section">
<label for="upload-input">Télécharger une image</label>
<input type="file" id="upload-input" accept="image/*">
</div>
<div class="image-display">
<div class="image-box">
<h3>Original</h3>
<canvas id="original-canvas"></canvas>
</div>
<div class="image-box">
<h3>Colara</h3>
<canvas id="colara-canvas"></canvas>
</div>
</div>
<p id="status-message"></p>
</div>
<script type="module">
const modelName = 'Clemylia/Colora-model';
const originalCanvas = document.getElementById('original-canvas');
const colaraCanvas = document.getElementById('colara-canvas');
const originalCtx = originalCanvas.getContext('2d');
const colaraCtx = colaraCanvas.getContext('2d');
const uploadInput = document.getElementById('upload-input');
const statusMessage = document.getElementById('status-message');
let colaraModel = null;
let isModelReady = false;
async function initializeModel() {
statusMessage.textContent = 'Chargement du modèle...';
try {
const response = await fetch(`https://huggingface.co/${modelName}/raw/main/colora.js`);
if (!response.ok) {
throw new Error(`Erreur de téléchargement : ${response.statusText}`);
}
const scriptText = await response.text();
const scriptBlob = new Blob([scriptText], { type: 'application/javascript' });
const scriptUrl = URL.createObjectURL(scriptBlob);
const module = await import(scriptUrl);
colaraModel = new module.default();
isModelReady = true;
statusMessage.textContent = 'Modèle Colara prêt ! Téléchargez une image.';
} catch (error) {
statusMessage.textContent = `Erreur de chargement : ${error.message}`;
console.error(error);
}
}
uploadInput.addEventListener('change', async (event) => {
if (!isModelReady) {
alert("Le modèle n'est pas prêt. Veuillez patienter.");
return;
}
const file = event.target.files[0];
if (file) {
statusMessage.textContent = 'Analyse de l\'image en cours...';
const reader = new FileReader();
reader.onload = async (e) => {
const img = new Image();
img.onload = async () => {
// Afficher l'image originale
originalCanvas.width = img.width;
originalCanvas.height = img.height;
originalCtx.drawImage(img, 0, 0);
// Appeler le modèle pour générer l'image modifiée
const processedResult = await colaraModel.generate(file);
// Afficher l'image générée
const processedImgUrl = URL.createObjectURL(processedResult.image);
const processedImg = new Image();
processedImg.onload = () => {
colaraCanvas.width = processedImg.width;
colaraCanvas.height = processedImg.height;
colaraCtx.drawImage(processedImg, 0, 0);
statusMessage.textContent = 'Image traitée !';
};
processedImg.src = processedImgUrl;
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
});
initializeModel();
</script>
</body>
</html> |