|
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 generateVideoWithGradioAPI({ |
|
positivePrompt = "", |
|
negativePrompt = "", |
|
size = "512x512", |
|
huggingFaceLora, |
|
// replicateLora, // not supported yet |
|
nbFrames = 8, |
|
duration = 1000, |
|
steps = 30, |
|
}: VideoOptions): Promise<string> { |
|
console.log(`SEND TO ${gradioApi + (gradioApi.endsWith("/") ? "" : "/") + "api/predict"}:`, [ |
|
|
|
positivePrompt, |
|
negativePrompt, |
|
huggingFaceLora, |
|
size, |
|
generateSeed(), |
|
steps, |
|
nbFrames, |
|
duration, |
|
]) |
|
const res = await fetch(gradioApi + (gradioApi.endsWith("/") ? "" : "/") + "api/predict", { |
|
method: "POST", |
|
headers: { |
|
"Content-Type": "application/json", |
|
|
|
}, |
|
body: JSON.stringify({ |
|
fn_index: 1, |
|
data: [ |
|
accessToken, |
|
positivePrompt, |
|
negativePrompt, |
|
huggingFaceLora, |
|
size, |
|
generateSeed(), |
|
steps, |
|
nbFrames, |
|
duration, |
|
], |
|
}), |
|
cache: "no-store", |
|
|
|
|
|
}) |
|
|
|
const { data } = await res.json() |
|
|
|
|
|
|
|
if (res.status !== 200) { |
|
|
|
throw new Error('Failed to fetch data') |
|
} |
|
|
|
|
|
return data[0] |
|
} |