jbilcke commited on
Commit
96f407e
·
1 Parent(s): ce62d44

small fix for blocking requests

Browse files
src/production/renderScene.mts CHANGED
@@ -29,9 +29,13 @@ export async function renderScene(request: RenderRequest): Promise<RenderedScene
29
  delete cache[toRemove]
30
  }
31
 
32
- // this is a fire-and-forget asynchronous pipeline:
33
- // we start it, but we do not await for the response
34
- renderPipeline(request, response)
 
 
 
 
35
 
36
  // console.log("renderScene: yielding the scene", response)
37
  return response
 
29
  delete cache[toRemove]
30
  }
31
 
32
+ if (request.wait) {
33
+ await renderPipeline(request, response)
34
+ } else {
35
+ // this is a fire-and-forget asynchronous pipeline:
36
+ // we start it, but we do not await for the response
37
+ renderPipeline(request, response)
38
+ }
39
 
40
  // console.log("renderScene: yielding the scene", response)
41
  return response
src/providers/video-transformation/transformVideoWithLatentImageAnimator.txt ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use server"
2
+
3
+ import Replicate from "replicate"
4
+
5
+ import { generateSeed } from "../../utils/misc/generateSeed.mts"
6
+ import { sleep } from "../../utils/misc/sleep.mts"
7
+
8
+ const replicateToken = `${process.env.VC_REPLICATE_API_TOKEN || ""}`
9
+ const replicateModel = `wyhsirius/lia`
10
+ const replicateModelVersion = "4ce4e4aff5bd28c6958b1e3e7628ea80718be56672d92ea8039039a3a152e67d"
11
+
12
+ if (!replicateToken) {
13
+ throw new Error(`you need to configure your VC_REPLICATE_API_TOKEN`)
14
+ }
15
+
16
+ const replicate = new Replicate({ auth: replicateToken })
17
+
18
+ /**
19
+ * Generate a video with hotshot through Replicate
20
+ *
21
+ * Note that if nbFrames == 1, then it will generate a jpg
22
+ *
23
+ */
24
+ export async function generateVideoWithHotshotReplicate({
25
+
26
+ }): Promise<string> {
27
+
28
+ if (!replicateModel) {
29
+ throw new Error(`you need to configure the replicateModel`)
30
+ }
31
+
32
+ if (!replicateModelVersion) {
33
+ throw new Error(`you need to configure the replicateModelVersion`)
34
+ }
35
+
36
+ const prediction = await replicate.predictions.create({
37
+ version: replicateModelVersion,
38
+ input: {
39
+ img_source: ,
40
+ negative_prompt: negativePrompt,
41
+
42
+ // this is not a URL but a model name
43
+ hf_lora_url: replicateLora?.length ? undefined : huggingFaceLora,
44
+
45
+ // this is a URL to the .tar (we can get it from the "trainings" page)
46
+ replicate_weights_url: huggingFaceLora?.length ? undefined : replicateLora,
47
+
48
+ width,
49
+ height,
50
+
51
+ // those are used to create an upsampling or downsampling
52
+ // original_width: width,
53
+ // original_height: height,
54
+ // target_width: width,
55
+ // target_height: height,
56
+
57
+ steps: nbSteps,
58
+
59
+
60
+ // note: right now it only makes sense to use either 1 (a jpg)
61
+ video_length: nbFrames, // nb frames
62
+
63
+ video_duration: videoDuration, // video duration in ms
64
+
65
+ seed: !isNaN(seed) && isFinite(seed) ? seed : generateSeed()
66
+ }
67
+ })
68
+
69
+ // console.log("prediction:", prediction)
70
+
71
+ // Replicate requires at least 30 seconds of mandatory delay
72
+ await sleep(30000)
73
+
74
+ let res: Response
75
+ let pollingCount = 0
76
+ do {
77
+ // Check every 5 seconds
78
+ await sleep(5000)
79
+
80
+ res = await fetch(`https://api.replicate.com/v1/predictions/${prediction.id}`, {
81
+ method: "GET",
82
+ headers: {
83
+ Authorization: `Token ${replicateToken}`,
84
+ },
85
+ cache: 'no-store',
86
+ })
87
+
88
+ if (res.status === 200) {
89
+ const response = (await res.json()) as any
90
+ const error = `${response?.error || ""}`
91
+ if (error) {
92
+ throw new Error(error)
93
+ }
94
+ }
95
+
96
+ pollingCount++
97
+
98
+ // To prevent indefinite polling, we can stop after a certain number, here 30 (i.e. about 2 and half minutes)
99
+ if (pollingCount >= 30) {
100
+ throw new Error('Request time out.')
101
+ }
102
+ } while (true)
103
+ }
src/utils/requests/parseRenderRequest.mts CHANGED
@@ -35,7 +35,8 @@ export function parseRenderRequest(request: RenderRequest) {
35
 
36
  request.turbo = getValidBoolean(request.turbo, false)
37
 
38
- request.wait = request?.wait || false
 
39
  request.cache = request?.cache || "ignore"
40
  } catch (err) {
41
  console.error(`failed to parse the render request: ${err}`)
 
35
 
36
  request.turbo = getValidBoolean(request.turbo, false)
37
 
38
+ request.wait = getValidBoolean(request?.wait, false)
39
+
40
  request.cache = request?.cache || "ignore"
41
  } catch (err) {
42
  console.error(`failed to parse the render request: ${err}`)