File size: 1,756 Bytes
7448744 1cf03f7 7448744 1b18d48 7448744 ee5bd94 8bc9511 80175c8 8bc9511 ee5bd94 7448744 8bc9511 7448744 8bc9511 7448744 ee5bd94 7448744 ee5bd94 7448744 8bc9511 7448744 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import { generateSeed } from "@/lib/generateSeed"
import { VideoOptions } from "@/types"
const gradioApi = `${process.env.VIDEO_HOTSHOT_XL_API_GRADIO || ""}`
const accessToken = `${process.env.AUTH_HOTSHOT_XL_API_GRADIO_ACCESS_TOKEN || ""}`
export async function generateGradio({
positivePrompt = "",
negativePrompt = "",
size = "512x512",
huggingFaceLora,
// replicateLora, // not supported yet
nbFrames = 8,
duration = 1000,
steps = 35,
}: VideoOptions): Promise<string> {
/*
console.log(`SEND TO ${gradioApi + (gradioApi.endsWith("/") ? "" : "/") + "api/predict"}:`, [
// accessToken,
positivePrompt,
negativePrompt,
huggingFaceLora,
size,
generateSeed(),
steps,
nbFrames,
duration,
])
*/
const res = await fetch(gradioApi + (gradioApi.endsWith("/") ? "" : "/") + "api/predict", {
method: "POST",
headers: {
"Content-Type": "application/json",
// Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
fn_index: 1, // <- important!
data: [
accessToken,
positivePrompt,
negativePrompt,
huggingFaceLora,
size,
generateSeed(),
steps,
nbFrames,
duration,
],
}),
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()
// console.log("data:", data)
// Recommendation: handle errors
if (res.status !== 200 || !Array.isArray(data)) {
// This will activate the closest `error.js` Error Boundary
throw new Error(`Failed to fetch data (status: ${res.status})`)
}
// console.log("data:", data.slice(0, 50))
return data[0]
} |