jbilcke-hf HF staff commited on
Commit
85d2530
1 Parent(s): d0216d7

made progress on the video exporter

Browse files
src/app/main.tsx CHANGED
@@ -14,6 +14,7 @@ import 'react-device-frameset/styles/marvel-devices.min.css'
14
  import { generateClap } from './server/aitube/generateClap'
15
  import { ClapOutputType, ClapProject } from '@/lib/clap/types'
16
  import { extendClap } from './server/aitube/extendClap'
 
17
 
18
  export function Main() {
19
  const [_isPending, startTransition] = useTransition()
@@ -80,6 +81,22 @@ export function Main() {
80
  return
81
  }
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  setStatus("finished")
84
  })
85
  }
 
14
  import { generateClap } from './server/aitube/generateClap'
15
  import { ClapOutputType, ClapProject } from '@/lib/clap/types'
16
  import { extendClap } from './server/aitube/extendClap'
17
+ import { exportClap } from './server/aitube/exportClap'
18
 
19
  export function Main() {
20
  const [_isPending, startTransition] = useTransition()
 
81
  return
82
  }
83
 
84
+ let assetUrl = ""
85
+ try {
86
+ setVideoGenerationStatus("generating")
87
+ assetUrl = await exportClap({ clap })
88
+
89
+ console.log(`handleSubmit(): received a video:`, assetUrl)
90
+ setVideoGenerationStatus("finished")
91
+ } catch (err) {
92
+ setVideoGenerationStatus("error")
93
+ setStatus("error")
94
+ return
95
+ }
96
+ if (!assetUrl) {
97
+ return
98
+ }
99
+
100
  setStatus("finished")
101
  })
102
  }
src/app/server/aitube/exportClap.ts ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use server"
2
+
3
+ import { ClapProject } from "@/lib/clap/types"
4
+ import { serializeClap } from "@/lib/clap/serializeClap"
5
+ import { blobToDataUri } from "@/lib/base64/blobToDataUri"
6
+
7
+ import { aitubeApiUrl } from "../config"
8
+
9
+ export async function exportClap({
10
+ clap,
11
+ }: {
12
+ clap: ClapProject
13
+ }): Promise<string> {
14
+ if (!clap) { throw new Error(`please provide a clap`) }
15
+
16
+ // remember: a space needs to be public for the classic fetch() to work
17
+ const res = await fetch(`${aitubeApiUrl}generate/video`, {
18
+ method: "POST",
19
+ headers: {
20
+ "Content-Type": "application/json",
21
+ // TODO pass the JWT so that only the AI Stories Factory can call the API
22
+ // Authorization: `Bearer ${hfApiToken}`,
23
+ },
24
+ body: await serializeClap(clap),
25
+ cache: "no-store",
26
+ // we can also use this (see https://vercel.com/blog/vercel-cache-api-nextjs-cache)
27
+ // next: { revalidate: 1 }
28
+ })
29
+
30
+ const blob = await res.blob()
31
+
32
+ const dataURL = await blobToDataUri(blob)
33
+
34
+ return dataURL
35
+ }