Commit
·
d0216d7
1
Parent(s):
c78f7b4
work in progress AI Stories Factory
Browse files- src/app/main.tsx +31 -4
- src/app/server/aitube/extendClap.ts +35 -0
src/app/main.tsx
CHANGED
@@ -12,6 +12,8 @@ import { TextareaField } from '@/components/form/textarea-field'
|
|
12 |
import { DeviceFrameset } from 'react-device-frameset'
|
13 |
import 'react-device-frameset/styles/marvel-devices.min.css'
|
14 |
import { generateClap } from './server/aitube/generateClap'
|
|
|
|
|
15 |
|
16 |
export function Main() {
|
17 |
const [_isPending, startTransition] = useTransition()
|
@@ -42,19 +44,43 @@ export function Main() {
|
|
42 |
const prompt = storyPromptDraft
|
43 |
|
44 |
setStatus("generating")
|
|
|
45 |
setStoryPrompt(prompt)
|
46 |
|
47 |
startTransition(async () => {
|
48 |
console.log(`handleSubmit(): generating a clap using prompt = "${prompt}" `)
|
49 |
|
|
|
50 |
try {
|
51 |
-
|
52 |
|
53 |
console.log(`handleSubmit(): received a clap = `, clap)
|
54 |
-
|
55 |
} catch (err) {
|
|
|
56 |
setStatus("error")
|
|
|
57 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
})
|
59 |
}
|
60 |
|
@@ -65,12 +91,13 @@ export function Main() {
|
|
65 |
`bg-gradient-to-br from-amber-600 to-yellow-500`,
|
66 |
// `bg-gradient-to-br from-sky-400 to-sky-300/30`,
|
67 |
`w-screen h-screen overflow-y-scroll md:overflow-hidden`,
|
68 |
-
)}
|
|
|
69 |
<div className="flex flex-col w-full">
|
70 |
<div className="
|
71 |
flex flex-col md:flex-row w-full
|
72 |
"
|
73 |
-
|
74 |
<div className={cn(
|
75 |
`flex flex-col w-full md:w-[512px]`,
|
76 |
`transition-all duration-300 ease-in-out`,
|
|
|
12 |
import { DeviceFrameset } from 'react-device-frameset'
|
13 |
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()
|
|
|
44 |
const prompt = storyPromptDraft
|
45 |
|
46 |
setStatus("generating")
|
47 |
+
setStoryGenerationStatus("generating")
|
48 |
setStoryPrompt(prompt)
|
49 |
|
50 |
startTransition(async () => {
|
51 |
console.log(`handleSubmit(): generating a clap using prompt = "${prompt}" `)
|
52 |
|
53 |
+
let clap: ClapProject | undefined = undefined
|
54 |
try {
|
55 |
+
clap = await generateClap({ prompt })
|
56 |
|
57 |
console.log(`handleSubmit(): received a clap = `, clap)
|
58 |
+
setStoryGenerationStatus("finished")
|
59 |
} catch (err) {
|
60 |
+
setStoryGenerationStatus("error")
|
61 |
setStatus("error")
|
62 |
+
return
|
63 |
}
|
64 |
+
if (!clap) {
|
65 |
+
return
|
66 |
+
}
|
67 |
+
|
68 |
+
try {
|
69 |
+
setImageGenerationStatus("generating")
|
70 |
+
clap = await extendClap({ clap })
|
71 |
+
|
72 |
+
console.log(`handleSubmit(): received a clap with images = `, clap)
|
73 |
+
setImageGenerationStatus("finished")
|
74 |
+
} catch (err) {
|
75 |
+
setImageGenerationStatus("error")
|
76 |
+
setStatus("error")
|
77 |
+
return
|
78 |
+
}
|
79 |
+
if (!clap) {
|
80 |
+
return
|
81 |
+
}
|
82 |
+
|
83 |
+
setStatus("finished")
|
84 |
})
|
85 |
}
|
86 |
|
|
|
91 |
`bg-gradient-to-br from-amber-600 to-yellow-500`,
|
92 |
// `bg-gradient-to-br from-sky-400 to-sky-300/30`,
|
93 |
`w-screen h-screen overflow-y-scroll md:overflow-hidden`,
|
94 |
+
)}
|
95 |
+
style={{ boxShadow: "inset 0 0px 250px 0 rgb(0 0 0 / 60%)" }}>
|
96 |
<div className="flex flex-col w-full">
|
97 |
<div className="
|
98 |
flex flex-col md:flex-row w-full
|
99 |
"
|
100 |
+
>
|
101 |
<div className={cn(
|
102 |
`flex flex-col w-full md:w-[512px]`,
|
103 |
`transition-all duration-300 ease-in-out`,
|
src/app/server/aitube/extendClap.ts
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"use server"
|
2 |
+
|
3 |
+
import { parseClap } from "@/lib/clap/parseClap"
|
4 |
+
import { ClapProject } from "@/lib/clap/types"
|
5 |
+
|
6 |
+
import { aitubeApiUrl } from "../config"
|
7 |
+
import { serializeClap } from "@/lib/clap/serializeClap"
|
8 |
+
|
9 |
+
export async function extendClap({
|
10 |
+
clap,
|
11 |
+
}: {
|
12 |
+
clap: ClapProject
|
13 |
+
}): Promise<ClapProject> {
|
14 |
+
if (!clap) { throw new Error(`please provide a prompt`) }
|
15 |
+
|
16 |
+
// remember: a space needs to be public for the classic fetch() to work
|
17 |
+
const res = await fetch(`${aitubeApiUrl}generate/storyboards`, {
|
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 extendedClap = await parseClap(blob)
|
33 |
+
|
34 |
+
return extendedClap
|
35 |
+
}
|