Created
October 9, 2024 04:26
-
-
Save fzn0x/a2a17727e0368c9879c9147e837f81eb to your computer and use it in GitHub Desktop.
Example code for Generating images with hugging face stabilityai/stable-diffusion-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HfInference } from "@huggingface/inference"; | |
import fs from "fs"; | |
const inference = new HfInference("HF_TOKEN"); | |
async function saveBlobToFile(blob, filePath) { | |
// Convert the blob to a buffer | |
const arrayBuffer = await blob.arrayBuffer(); | |
// Write the buffer to a file | |
fs.writeFile(filePath, Buffer.from(arrayBuffer), (err) => { | |
if (err) { | |
console.error("Error writing the file:", err); | |
} else { | |
console.log("File saved successfully at", filePath); | |
} | |
}); | |
} | |
(async () => { | |
console.log("Generating.."); | |
const res = await inference.textToImage({ | |
model: "stabilityai/stable-diffusion-2", | |
inputs: | |
"award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]", | |
parameters: { | |
negative_prompt: "blurry", | |
}, | |
}); | |
await saveBlobToFile(res, "output.png"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment