File size: 1,209 Bytes
1cf03f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

const gradioApi = `${process.env.INTERPOLATION_API_GRADIO_URL || ""}`
const accessToken = `${process.env.AUTH_INTERPOLATION_API_GRADIO_TOKEN || ""}`

export async function interpolateGradio(assetUrl: string): Promise<string> {
  // we need to remove this header perhaps
  const videoInBase64 = assetUrl.split("data:video/mp4;base64,").pop()

  const interpolationSteps = 2
  const nbFramesPerSecond = 32

  const res = await fetch(gradioApi + (gradioApi.endsWith("/") ? "" : "/") + "api/predict", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      // Authorization: `Bearer ${token}`,
    },
    body: JSON.stringify({
      fn_index: 0, // <- important!
      data: [
        accessToken,
        videoInBase64,
        interpolationSteps,
        nbFramesPerSecond
      ],
    }),
    cache: "no-store",
    // we can also use this (see https://vercel.com/blog/vercel-cache-api-nextjs-cache)
    // next: { revalidate: 1 }
  })

  const { data } = await res.json()

  if (res.status !== 200 || !data[0]?.length) {
    // This will activate the closest `error.js` Error Boundary
    throw new Error(`Failed to fetch data (status: ${res.status})`)
  }

  return data[0]
}