Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
c5b0dde
1
Parent(s):
278d122
making some changes to support basic text prompts
Browse files- src/index.mts +5 -6
- src/types.mts +4 -4
- src/utils/parseVideoRequest.mts +15 -2
src/index.mts
CHANGED
@@ -3,7 +3,7 @@ import path from "node:path"
|
|
3 |
|
4 |
import express from "express"
|
5 |
|
6 |
-
import { VideoTask,
|
7 |
import { parseVideoRequest } from "./utils/parseVideoRequest.mts"
|
8 |
import { savePendingTask } from "./scheduler/savePendingTask.mts"
|
9 |
import { getTask } from "./scheduler/getTask.mts"
|
@@ -21,8 +21,8 @@ const port = 7860
|
|
21 |
app.use(express.json())
|
22 |
|
23 |
app.post("/", async (req, res) => {
|
24 |
-
const request = req.body as
|
25 |
-
|
26 |
if (!hasValidAuthorization(req.headers)) {
|
27 |
console.log("Invalid authorization")
|
28 |
res.status(401)
|
@@ -30,8 +30,7 @@ app.post("/", async (req, res) => {
|
|
30 |
res.end()
|
31 |
return
|
32 |
}
|
33 |
-
|
34 |
-
|
35 |
let task: VideoTask = null
|
36 |
|
37 |
console.log(`creating task from request..`)
|
@@ -150,7 +149,7 @@ app.get("/video/:id\.mp4", async (req, res) => {
|
|
150 |
return
|
151 |
}
|
152 |
|
153 |
-
|
154 |
if (!req.params.id) {
|
155 |
res.status(400)
|
156 |
res.write(JSON.stringify({ error: "please provide a valid video id" }))
|
|
|
3 |
|
4 |
import express from "express"
|
5 |
|
6 |
+
import { VideoTask, VideoTaskRequest } from "./types.mts"
|
7 |
import { parseVideoRequest } from "./utils/parseVideoRequest.mts"
|
8 |
import { savePendingTask } from "./scheduler/savePendingTask.mts"
|
9 |
import { getTask } from "./scheduler/getTask.mts"
|
|
|
21 |
app.use(express.json())
|
22 |
|
23 |
app.post("/", async (req, res) => {
|
24 |
+
const request = req.body as VideoTaskRequest
|
25 |
+
|
26 |
if (!hasValidAuthorization(req.headers)) {
|
27 |
console.log("Invalid authorization")
|
28 |
res.status(401)
|
|
|
30 |
res.end()
|
31 |
return
|
32 |
}
|
33 |
+
|
|
|
34 |
let task: VideoTask = null
|
35 |
|
36 |
console.log(`creating task from request..`)
|
|
|
149 |
return
|
150 |
}
|
151 |
|
152 |
+
|
153 |
if (!req.params.id) {
|
154 |
res.status(400)
|
155 |
res.write(JSON.stringify({ error: "please provide a valid video id" }))
|
src/types.mts
CHANGED
@@ -219,10 +219,10 @@ export interface VideoSequenceData {
|
|
219 |
|
220 |
export type VideoSequence = VideoSequenceMeta & VideoSequenceData
|
221 |
|
222 |
-
export type
|
223 |
-
|
224 |
-
sequence: VideoSequenceMeta
|
225 |
-
shots: VideoShotMeta
|
226 |
}
|
227 |
|
228 |
export type VideoTask = VideoSequence & {
|
|
|
219 |
|
220 |
export type VideoSequence = VideoSequenceMeta & VideoSequenceData
|
221 |
|
222 |
+
export type VideoTaskRequest = {
|
223 |
+
prompt: string
|
224 |
+
sequence: Partial<VideoSequenceMeta>
|
225 |
+
shots: Array<Partial<VideoShotMeta>>
|
226 |
}
|
227 |
|
228 |
export type VideoTask = VideoSequence & {
|
src/utils/parseVideoRequest.mts
CHANGED
@@ -1,20 +1,33 @@
|
|
1 |
import { v4 as uuidv4 } from "uuid"
|
|
|
2 |
|
3 |
// convert a request (which might be invalid)
|
4 |
|
5 |
-
import {
|
6 |
import { getValidNumber } from "./getValidNumber.mts"
|
7 |
import { getValidResolution } from "./getValidResolution.mts"
|
8 |
import { parseShotRequest } from "./parseShotRequest.mts"
|
9 |
import { generateSeed } from "./generateSeed.mts"
|
10 |
import { sequenceFormatVersion } from "../config.mts"
|
11 |
|
|
|
|
|
12 |
|
13 |
-
export const parseVideoRequest = async (request:
|
14 |
// we don't want people to input their own ID or we might have trouble,
|
15 |
// such as people attempting to use a non-UUID, a file path (to hack us), etc
|
16 |
const id = uuidv4()
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
const task: VideoTask = {
|
19 |
// ------------ VideoSequenceMeta -------------
|
20 |
id,
|
|
|
1 |
import { v4 as uuidv4 } from "uuid"
|
2 |
+
import { HfInference } from "@huggingface/inference"
|
3 |
|
4 |
// convert a request (which might be invalid)
|
5 |
|
6 |
+
import { VideoTaskRequest, VideoTask, VideoShotMeta } from "../types.mts"
|
7 |
import { getValidNumber } from "./getValidNumber.mts"
|
8 |
import { getValidResolution } from "./getValidResolution.mts"
|
9 |
import { parseShotRequest } from "./parseShotRequest.mts"
|
10 |
import { generateSeed } from "./generateSeed.mts"
|
11 |
import { sequenceFormatVersion } from "../config.mts"
|
12 |
|
13 |
+
// const hfi = new HfInference(process.env._VC_HF_API_TOKEN)
|
14 |
+
// const hf = hfi.endpoint(process.env.VC_INFERENCE_ENDPOINT_URL)
|
15 |
|
16 |
+
export const parseVideoRequest = async (request: VideoTaskRequest): Promise<VideoTask> => {
|
17 |
// we don't want people to input their own ID or we might have trouble,
|
18 |
// such as people attempting to use a non-UUID, a file path (to hack us), etc
|
19 |
const id = uuidv4()
|
20 |
|
21 |
+
if (typeof request.prompt === "string" && request.prompt.length > 0) {
|
22 |
+
// TODO: use llama2 to populate this!
|
23 |
+
request.sequence = {
|
24 |
+
videoPrompt: request.prompt,
|
25 |
+
}
|
26 |
+
request.shots = [{
|
27 |
+
shotPrompt: request.prompt,
|
28 |
+
}]
|
29 |
+
}
|
30 |
+
|
31 |
const task: VideoTask = {
|
32 |
// ------------ VideoSequenceMeta -------------
|
33 |
id,
|