Spaces:
Sleeping
Sleeping
Julian Bilcke
commited on
Commit
·
0bf0c48
1
Parent(s):
ce559ed
work in progress for AI Stories Factory
Browse files- src/app/api/generate/story/route.ts +10 -0
- src/app/api/generate/storyboards/route.ts +19 -5
- src/components/interface/latent-engine/core/config.ts +2 -0
- src/components/interface/latent-engine/resolvers/image/generateImage.ts +3 -1
- src/components/interface/latent-engine/resolvers/interface/generateHtml.ts +3 -1
- src/components/interface/latent-engine/resolvers/video/generateVideo.ts +3 -1
src/app/api/generate/story/route.ts
CHANGED
|
@@ -132,6 +132,16 @@ export async function POST(req: NextRequest) {
|
|
| 132 |
outputType: "audio"
|
| 133 |
}))
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
currentSegmentDurationInMs += defaultSegmentDurationInMs
|
| 136 |
}
|
| 137 |
|
|
|
|
| 132 |
outputType: "audio"
|
| 133 |
}))
|
| 134 |
|
| 135 |
+
// the presence of a camera is mandatory
|
| 136 |
+
clap.segments.push(newSegment({
|
| 137 |
+
track: 4,
|
| 138 |
+
startTimeInMs: currentSegmentDurationInMs,
|
| 139 |
+
assetDurationInMs: defaultSegmentDurationInMs,
|
| 140 |
+
category: "camera",
|
| 141 |
+
prompt: "vertical video",
|
| 142 |
+
outputType: "text"
|
| 143 |
+
}))
|
| 144 |
+
|
| 145 |
currentSegmentDurationInMs += defaultSegmentDurationInMs
|
| 146 |
}
|
| 147 |
|
src/app/api/generate/storyboards/route.ts
CHANGED
|
@@ -20,12 +20,16 @@ export async function POST(req: NextRequest) {
|
|
| 20 |
const jwtToken = await getToken({ user: "anonymous" })
|
| 21 |
|
| 22 |
const blob = await req.blob()
|
| 23 |
-
const clap = await parseClap(blob)
|
| 24 |
|
| 25 |
-
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
const shotsSegments = clap.segments.filter(s => s.category === "camera")
|
| 28 |
-
|
|
|
|
| 29 |
if (shotsSegments.length > 32) {
|
| 30 |
throw new Error(`Error, this endpoint being synchronous, it is designed for short stories only (max 32 shots).`)
|
| 31 |
}
|
|
@@ -41,7 +45,9 @@ export async function POST(req: NextRequest) {
|
|
| 41 |
)
|
| 42 |
|
| 43 |
let shotStoryboardSegment = shotStoryboardSegments.at(0)
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
// TASK 1: GENERATE MISSING STORYBOARD SEGMENT
|
| 46 |
if (!shotStoryboardSegment) {
|
| 47 |
shotStoryboardSegment = newSegment({
|
|
@@ -54,16 +60,19 @@ export async function POST(req: NextRequest) {
|
|
| 54 |
assetUrl: "",
|
| 55 |
outputType: "image"
|
| 56 |
})
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
// TASK 2: GENERATE MISSING STORYBOARD PROMPT
|
| 60 |
if (!shotStoryboardSegment.prompt) {
|
| 61 |
// storyboard is missing, let's generate it
|
| 62 |
shotStoryboardSegment.prompt = getVideoPrompt(shotSegments, {}, [])
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
// TASK 3: GENERATE MISSING STORYBOARD BITMAP
|
| 66 |
if (!shotStoryboardSegment.assetUrl) {
|
|
|
|
| 67 |
// note this will do a fetch to AiTube API
|
| 68 |
// which is a bit weird since we are already inside the API, but it works
|
| 69 |
//TODO Julian: maybe we could use an internal function call instead?
|
|
@@ -73,9 +82,14 @@ export async function POST(req: NextRequest) {
|
|
| 73 |
height: clap.meta.height,
|
| 74 |
token: jwtToken,
|
| 75 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
}
|
| 77 |
}
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
return new NextResponse(await serializeClap(clap), {
|
| 81 |
status: 200,
|
|
|
|
| 20 |
const jwtToken = await getToken({ user: "anonymous" })
|
| 21 |
|
| 22 |
const blob = await req.blob()
|
|
|
|
| 23 |
|
| 24 |
+
const clap = await parseClap(blob)
|
| 25 |
|
| 26 |
+
if (!clap?.segments) { throw new Error(`no segment found in the provided clap!`) }
|
| 27 |
+
|
| 28 |
+
console.log(`[api/generate/storyboards] detected ${clap.segments} segments`)
|
| 29 |
+
|
| 30 |
const shotsSegments = clap.segments.filter(s => s.category === "camera")
|
| 31 |
+
console.log(`[api/generate/storyboards] detected ${shotsSegments.length} shots`)
|
| 32 |
+
|
| 33 |
if (shotsSegments.length > 32) {
|
| 34 |
throw new Error(`Error, this endpoint being synchronous, it is designed for short stories only (max 32 shots).`)
|
| 35 |
}
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
let shotStoryboardSegment = shotStoryboardSegments.at(0)
|
| 48 |
+
|
| 49 |
+
console.log(`[api/generate/storyboards] shot [${shotSegment.startTimeInMs}:${shotSegment.endTimeInMs}] has ${shotSegments.length} segments (${shotStoryboardSegments.length} storyboards)`)
|
| 50 |
+
|
| 51 |
// TASK 1: GENERATE MISSING STORYBOARD SEGMENT
|
| 52 |
if (!shotStoryboardSegment) {
|
| 53 |
shotStoryboardSegment = newSegment({
|
|
|
|
| 60 |
assetUrl: "",
|
| 61 |
outputType: "image"
|
| 62 |
})
|
| 63 |
+
console.log(`[api/generate/storyboards] generated storyboard segment [${shotSegment.startTimeInMs}:${shotSegment.endTimeInMs}]`)
|
| 64 |
}
|
| 65 |
|
| 66 |
// TASK 2: GENERATE MISSING STORYBOARD PROMPT
|
| 67 |
if (!shotStoryboardSegment.prompt) {
|
| 68 |
// storyboard is missing, let's generate it
|
| 69 |
shotStoryboardSegment.prompt = getVideoPrompt(shotSegments, {}, [])
|
| 70 |
+
console.log(`[api/generate/storyboards] generating storyboard prompt: ${shotStoryboardSegment.prompt}`)
|
| 71 |
}
|
| 72 |
|
| 73 |
// TASK 3: GENERATE MISSING STORYBOARD BITMAP
|
| 74 |
if (!shotStoryboardSegment.assetUrl) {
|
| 75 |
+
console.log(`[api/generate/storyboards] generating image..`)
|
| 76 |
// note this will do a fetch to AiTube API
|
| 77 |
// which is a bit weird since we are already inside the API, but it works
|
| 78 |
//TODO Julian: maybe we could use an internal function call instead?
|
|
|
|
| 82 |
height: clap.meta.height,
|
| 83 |
token: jwtToken,
|
| 84 |
})
|
| 85 |
+
|
| 86 |
+
console.log(`[api/generate/storyboards] generated storyboard image: ${shotStoryboardSegment.assetUrl.slice(0, 50)}...`)
|
| 87 |
+
} else {
|
| 88 |
+
console.log(`[api/generate/storyboards] there is already a storyboard image: ${shotStoryboardSegment.assetUrl.slice(0, 50)}...`)
|
| 89 |
}
|
| 90 |
}
|
| 91 |
+
|
| 92 |
+
console.log(`[api/generate/storyboards] returning the clap augmented with storyboards`)
|
| 93 |
|
| 94 |
return new NextResponse(await serializeClap(clap), {
|
| 95 |
status: 200,
|
src/components/interface/latent-engine/core/config.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const aitubeUrl = `${process.env.NEXT_PUBLIC_DOMAIN || "" }`
|
| 2 |
+
export const aitubeApiUrl = aitubeUrl + (aitubeUrl.endsWith("/") ? "" : "/") + "api/"
|
src/components/interface/latent-engine/resolvers/image/generateImage.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
export async function generateImage({
|
| 2 |
prompt,
|
| 3 |
width,
|
|
@@ -9,7 +11,7 @@ export async function generateImage({
|
|
| 9 |
height: number
|
| 10 |
token: string
|
| 11 |
}): Promise<string> {
|
| 12 |
-
const requestUri =
|
| 13 |
token
|
| 14 |
}&w=${
|
| 15 |
width
|
|
|
|
| 1 |
+
import { aitubeApiUrl } from "../../core/config"
|
| 2 |
+
|
| 3 |
export async function generateImage({
|
| 4 |
prompt,
|
| 5 |
width,
|
|
|
|
| 11 |
height: number
|
| 12 |
token: string
|
| 13 |
}): Promise<string> {
|
| 14 |
+
const requestUri = `${aitubeApiUrl}/api/resolvers/image?t=${
|
| 15 |
token
|
| 16 |
}&w=${
|
| 17 |
width
|
src/components/interface/latent-engine/resolvers/interface/generateHtml.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
|
|
|
|
|
| 1 |
export async function generateHtml(prompt: string): Promise<string> {
|
| 2 |
-
const requestUri =
|
| 3 |
|
| 4 |
// console.log(`generateHtml: calling ${requestUri}`)
|
| 5 |
|
|
|
|
| 1 |
+
import { aitubeApiUrl } from "../../core/config"
|
| 2 |
+
|
| 3 |
export async function generateHtml(prompt: string): Promise<string> {
|
| 4 |
+
const requestUri = `${aitubeApiUrl}/api/resolvers/interface?p=${encodeURIComponent(prompt)}`
|
| 5 |
|
| 6 |
// console.log(`generateHtml: calling ${requestUri}`)
|
| 7 |
|
src/components/interface/latent-engine/resolvers/video/generateVideo.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
export async function generateVideo({
|
| 2 |
prompt,
|
| 3 |
width,
|
|
@@ -9,7 +11,7 @@ export async function generateVideo({
|
|
| 9 |
height: number
|
| 10 |
token: string
|
| 11 |
}): Promise<string> {
|
| 12 |
-
const requestUri =
|
| 13 |
token
|
| 14 |
}&w=${
|
| 15 |
width
|
|
|
|
| 1 |
+
import { aitubeApiUrl } from "../../core/config"
|
| 2 |
+
|
| 3 |
export async function generateVideo({
|
| 4 |
prompt,
|
| 5 |
width,
|
|
|
|
| 11 |
height: number
|
| 12 |
token: string
|
| 13 |
}): Promise<string> {
|
| 14 |
+
const requestUri = `${aitubeApiUrl}/api/resolvers/video?t=${
|
| 15 |
token
|
| 16 |
}&w=${
|
| 17 |
width
|