Instructions to use Finisha-LLM/Colora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use Finisha-LLM/Colora with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('image-to-image', 'Finisha-LLM/Colora');
| // On définit la classe de ton modèle Colara | |
| class ColaraModel { | |
| // Cette méthode est requise par Hugging Face, mais ne fait rien | |
| static async getInstance(progress_callback = null) { | |
| return new ColaraModel(); | |
| } | |
| // La méthode 'generate' qui va prendre une image en entrée | |
| async generate(imageBlob) { | |
| // On va charger l'image | |
| const img = await new Promise((resolve) => { | |
| const reader = new FileReader(); | |
| reader.onload = (e) => { | |
| const image = new Image(); | |
| image.onload = () => resolve(image); | |
| image.src = e.target.result; | |
| }; | |
| reader.readAsDataURL(imageBlob); | |
| }); | |
| // Créer un canvas temporaire pour manipuler les pixels de l'image | |
| const tempCanvas = document.createElement('canvas'); | |
| tempCanvas.width = img.width; | |
| tempCanvas.height = img.height; | |
| const tempCtx = tempCanvas.getContext('2d'); | |
| tempCtx.drawImage(img, 0, 0); | |
| const imageData = tempCtx.getImageData(0, 0, img.width, img.height); | |
| const data = imageData.data; | |
| // --- Le cœur de la logique de Colara --- | |
| // L'IA choisit une couleur de filtre aléatoire | |
| const randomRed = Math.floor(Math.random() * 256); | |
| const randomGreen = Math.floor(Math.random() * 256); | |
| const randomBlue = Math.floor(Math.random() * 256); | |
| // Boucler sur chaque pixel pour appliquer le filtre | |
| for (let i = 0; i < data.length; i += 4) { | |
| const originalRed = data[i]; | |
| const originalGreen = data[i + 1]; | |
| const originalBlue = data[i + 2]; | |
| const brightness = 0.2126 * originalRed + 0.7152 * originalGreen + 0.0722 * originalBlue; | |
| data[i] = randomRed * (brightness / 255); | |
| data[i + 1] = randomGreen * (brightness / 255); | |
| data[i + 2] = randomBlue * (brightness / 255); | |
| } | |
| // Mettre à jour les données de pixels | |
| tempCtx.putImageData(imageData, 0, 0); | |
| // Convertir le canvas en un blob pour le résultat | |
| const resultBlob = await new Promise(resolve => tempCanvas.toBlob(resolve, 'image/png')); | |
| // Le format de sortie pour une image est différent du texte | |
| return { | |
| image: resultBlob, | |
| generated_text: "Image générée par Colara" | |
| }; | |
| } | |
| } | |
| // On exporte la classe pour qu'elle puisse être utilisée | |
| export default ColaraModel; |