File size: 1,204 Bytes
a65e95e
 
 
 
 
 
12506f0
a65e95e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { promises as fs } from "node:fs"
import path from "node:path"
import tmpDir from "temp-dir"

import { HfInference } from "@huggingface/inference"

const hf = new HfInference(process.env.VC_HF_API_TOKEN)

export const generateActor = async (prompt: string, fileName: string, seed: number) => {
  const positivePrompt = [
    `profile photo of ${prompt || ""}`,
    "id picture",
    "photoshoot",
    "portrait photography",
    "neutral expression",
    "neutral background",
    "studio photo",
    "award winning",
    "high resolution",
    "photo realistic",
    "intricate details",
    "beautiful",
  ]
  const negativePrompt = [
    "anime",
    "drawing",
    "painting",
    "lowres",
    "blurry",
    "artificial"
  ]

  console.log(`generating actor: ${positivePrompt.join(", ")}`)

  const blob = await hf.textToImage({
    inputs: positivePrompt.join(", "),
    model: "stabilityai/stable-diffusion-2-1",
    parameters: {
      negative_prompt: negativePrompt.join(", "),
      // seed, no seed?
    }
  })

  const filePath = path.resolve(tmpDir, fileName)

  const buffer = Buffer.from(await blob.arrayBuffer())
  await fs.writeFile(filePath, buffer, "utf8")

  return filePath
}