Spaces:
Paused
Paused
Julian Bilcke
commited on
Commit
·
7139c79
1
Parent(s):
977a154
update
Browse files- src/index.mts +42 -11
- src/production/generateVideo.mts +3 -3
- src/production/renderScene.mts +47 -0
src/index.mts
CHANGED
|
@@ -3,7 +3,6 @@ import path from "node:path"
|
|
| 3 |
|
| 4 |
import { validate as uuidValidate } from "uuid"
|
| 5 |
import express from "express"
|
| 6 |
-
import querystring from "node:querystring"
|
| 7 |
|
| 8 |
import { Video, VideoStatus, VideoAPIRequest } from "./types.mts"
|
| 9 |
import { parseVideoRequest } from "./utils/parseVideoRequest.mts"
|
|
@@ -22,6 +21,7 @@ import { initFolders } from "./initFolders.mts"
|
|
| 22 |
import { sortVideosByYoungestFirst } from "./utils/sortVideosByYoungestFirst.mts"
|
| 23 |
import { generateVideo } from "./production/generateVideo.mts"
|
| 24 |
import { generateSeed } from "./utils/generateSeed.mts"
|
|
|
|
| 25 |
|
| 26 |
initFolders()
|
| 27 |
// to disable all processing (eg. to debug)
|
|
@@ -33,17 +33,48 @@ const port = 7860
|
|
| 33 |
|
| 34 |
app.use(express.json())
|
| 35 |
|
|
|
|
|
|
|
| 36 |
// a "fast track" pipeline
|
| 37 |
-
app.post("/render", async (req, res) => {
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
})
|
| 48 |
|
| 49 |
app.post("/:ownerId", async (req, res) => {
|
|
|
|
| 3 |
|
| 4 |
import { validate as uuidValidate } from "uuid"
|
| 5 |
import express from "express"
|
|
|
|
| 6 |
|
| 7 |
import { Video, VideoStatus, VideoAPIRequest } from "./types.mts"
|
| 8 |
import { parseVideoRequest } from "./utils/parseVideoRequest.mts"
|
|
|
|
| 21 |
import { sortVideosByYoungestFirst } from "./utils/sortVideosByYoungestFirst.mts"
|
| 22 |
import { generateVideo } from "./production/generateVideo.mts"
|
| 23 |
import { generateSeed } from "./utils/generateSeed.mts"
|
| 24 |
+
import { renderScene } from "./production/renderScene.mts"
|
| 25 |
|
| 26 |
initFolders()
|
| 27 |
// to disable all processing (eg. to debug)
|
|
|
|
| 33 |
|
| 34 |
app.use(express.json())
|
| 35 |
|
| 36 |
+
let isRendering = false
|
| 37 |
+
|
| 38 |
// a "fast track" pipeline
|
| 39 |
+
app.post("/render", async (req, res) => {
|
| 40 |
+
|
| 41 |
+
const prompt = req.body.prompt as string
|
| 42 |
+
console.log(`/render: "${prompt}"`)
|
| 43 |
+
if (!prompt) {
|
| 44 |
+
console.log("Invalid prompt")
|
| 45 |
+
res.status(400)
|
| 46 |
+
res.write(JSON.stringify({ url: "", error: "invalid prompt" }))
|
| 47 |
+
res.end()
|
| 48 |
+
return
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
let result = { url: "", error: "" }
|
| 52 |
+
try {
|
| 53 |
+
result = await renderScene(prompt)
|
| 54 |
+
} catch (err) {
|
| 55 |
+
// console.log("failed to render scene!")
|
| 56 |
+
result.error = `failed to render scene: ${err}`
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if (result.error === "already rendering") {
|
| 60 |
+
console.log("server busy")
|
| 61 |
+
res.status(200)
|
| 62 |
+
res.write(JSON.stringify({ url: "", error: result.error }))
|
| 63 |
+
res.end()
|
| 64 |
+
return
|
| 65 |
+
} else if (result.error.length > 0) {
|
| 66 |
+
// console.log("server error")
|
| 67 |
+
res.status(500)
|
| 68 |
+
res.write(JSON.stringify({ url: "", error: result.error }))
|
| 69 |
+
res.end()
|
| 70 |
+
return
|
| 71 |
+
} else {
|
| 72 |
+
// console.log("all good")
|
| 73 |
+
res.status(200)
|
| 74 |
+
res.write(JSON.stringify(result))
|
| 75 |
+
res.end()
|
| 76 |
+
return
|
| 77 |
+
}
|
| 78 |
})
|
| 79 |
|
| 80 |
app.post("/:ownerId", async (req, res) => {
|
src/production/generateVideo.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import { client } from "@gradio/client"
|
| 2 |
|
| 3 |
-
|
| 4 |
import { generateSeed } from "../utils/generateSeed.mts"
|
| 5 |
|
| 6 |
const instances: string[] = [
|
| 7 |
-
process.env.VC_VIDEO_GENERATION_SPACE_API_URL
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
export const generateVideo = async (prompt: string, options?: {
|
| 11 |
seed: number;
|
|
|
|
| 1 |
import { client } from "@gradio/client"
|
| 2 |
|
|
|
|
| 3 |
import { generateSeed } from "../utils/generateSeed.mts"
|
| 4 |
|
| 5 |
const instances: string[] = [
|
| 6 |
+
`${process.env.VC_VIDEO_GENERATION_SPACE_API_URL || ""}`,
|
| 7 |
+
`${process.env.VC_RENDERING_ENGINE_SPACE_API_URL || ""}`,
|
| 8 |
+
].filter(instance => instance?.length > 0)
|
| 9 |
|
| 10 |
export const generateVideo = async (prompt: string, options?: {
|
| 11 |
seed: number;
|
src/production/renderScene.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { generateSeed } from "../utils/generateSeed.mts"
|
| 2 |
+
import { generateVideo } from "./generateVideo.mts"
|
| 3 |
+
|
| 4 |
+
const state = {
|
| 5 |
+
isRendering: false
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
const seed = generateSeed()
|
| 9 |
+
|
| 10 |
+
export async function renderScene(prompt: string) {
|
| 11 |
+
// console.log("renderScene")
|
| 12 |
+
if (state.isRendering) {
|
| 13 |
+
// console.log("renderScene: isRendering")
|
| 14 |
+
return {
|
| 15 |
+
url: "",
|
| 16 |
+
error: "already rendering"
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
// onsole.log("marking as isRendering")
|
| 21 |
+
state.isRendering = true
|
| 22 |
+
|
| 23 |
+
let url = ""
|
| 24 |
+
let error = ""
|
| 25 |
+
|
| 26 |
+
try {
|
| 27 |
+
url = await generateVideo(prompt, {
|
| 28 |
+
seed: generateSeed(),
|
| 29 |
+
// seed,
|
| 30 |
+
nbFrames: 16,
|
| 31 |
+
nbSteps: 7,
|
| 32 |
+
})
|
| 33 |
+
// console.log("successfull generation")
|
| 34 |
+
error = ""
|
| 35 |
+
} catch (err) {
|
| 36 |
+
error = `failed to render scene: ${err}`
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// console.log("marking as not rendering anymore")
|
| 40 |
+
state.isRendering = false
|
| 41 |
+
error = ""
|
| 42 |
+
|
| 43 |
+
return {
|
| 44 |
+
url,
|
| 45 |
+
error
|
| 46 |
+
}
|
| 47 |
+
}
|