File size: 1,896 Bytes
a65e95e
 
955ce73
ec194c9
 
cd0e411
ceb44b0
9658ad9
07d10ce
ceb44b0
702b7b3
e56af9e
7139c79
bda5f6b
9b3e078
 
ec194c9
 
 
 
 
 
cd0e411
 
 
 
 
 
 
 
 
ec194c9
 
 
 
 
 
9b3e078
cd0e411
 
 
 
 
 
 
 
 
 
bda5f6b
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 { client } from "@gradio/client"

import { generateSeed } from "../../utils/misc/generateSeed.mts"
import { VideoGenerationOptions } from "./types.mts"
import { getPositivePrompt } from "./defaultPrompts.mts"

// we don't use replicas yet, because it ain't easy to get their hostname
const instances: string[] = [
  `${process.env.VC_ZEROSCOPE_SPACE_API_URL_1 || ""}`,
  `${process.env.VC_ZEROSCOPE_SPACE_API_URL_2 || ""}`,
  `${process.env.VC_ZEROSCOPE_SPACE_API_URL_3 || ""}`,
  `${process.env.VC_ZEROSCOPE_SPACE_API_URL_4 || ""}`,
].filter(instance => instance?.length > 0)

const secretToken = `${process.env.VC_MICROSERVICE_SECRET_TOKEN || ""}`

export const generateVideo = async ({
  positivePrompt,
  seed,
  nbFrames = 8, // for now the only values that make sense are 1 (for a jpg) or 8 (for a video)
  nbSteps = 30, // when rendering a final video, we want a value like 50 or 70 here
}: VideoGenerationOptions) => {
  try {
    const instance = instances.shift()
    instances.push(instance)

    const api = await client(instance, {
      hf_token: `${process.env.VC_HF_API_TOKEN}` as any
    })

    const rawResponse = await api.predict('/run', [		
      getPositivePrompt(positivePrompt), // string  in 'Prompt' Textbox component	
      
      // we treat 0 as meaning "random seed"
      !isNaN(seed) && isFinite(seed) && seed > 0 ? seed : generateSeed(), // number (numeric value between 0 and 2147483647) in 'Seed' Slider component		
      nbFrames || 24, // 24 // it is the nb of frames per seconds I think?
      nbSteps || 35, // 10, (numeric value between 10 and 50) in 'Number of inference steps' Slider component
      secretToken,
    ]) as any
    
    // console.log("rawResponse:", rawResponse)

    const { name } = rawResponse?.data?.[0]?.[0] as { name: string, orig_name: string }

    return `${instance}/file=${name}`
  } catch (err) {
    throw err
  }
}