jbilcke-hf HF staff commited on
Commit
bf6568f
1 Parent(s): 68cf43c

various improvements

Browse files
.env CHANGED
@@ -1,3 +1,3 @@
1
  NEXT_PUBLIC_BASE_URL=https://jbilcke-hf-fishtank.hf.space
2
  # NEXT_PUBLIC_RENDERING_ENGINE_API=https://hysts-zeroscope-v2.hf.space
3
- RENDERING_ENGINE_API=https://jbilcke-hf-videochain-api.hf.space
 
1
  NEXT_PUBLIC_BASE_URL=https://jbilcke-hf-fishtank.hf.space
2
  # NEXT_PUBLIC_RENDERING_ENGINE_API=https://hysts-zeroscope-v2.hf.space
3
+ RENDERING_ENGINE_API=https://jbilcke-hf-videochain-api.hf.space
src/app/agents/ant.ts CHANGED
@@ -18,23 +18,33 @@ const positions = [
18
  "on the ground"
19
  ]
20
 
21
- const times = [
22
  "during the day",
23
  ]
24
 
 
 
 
 
 
 
 
 
 
 
25
  export const agent: Agent = {
26
  title: "Ant",
27
  type: "ant",
28
  simulate: (): Scene => {
29
  const action = pick(actions)
30
  const position = pick(positions)
31
- const time = pick(times)
32
 
33
  const prompt = [
34
  `close-up shot of a couple of ants`,
35
  action,
36
  position,
37
- time,
38
  `high res`,
39
  `documentary`,
40
  ].join(", ")
@@ -42,7 +52,8 @@ export const agent: Agent = {
42
  return {
43
  action,
44
  position,
45
- time,
 
46
  prompt
47
  }
48
  }
 
18
  "on the ground"
19
  ]
20
 
21
+ const lights = [
22
  "during the day",
23
  ]
24
 
25
+ const actionnables = [
26
+ "ant",
27
+ "ground",
28
+ "leaf",
29
+ "rock",
30
+ "wood",
31
+ "water",
32
+ "beetle"
33
+ ]
34
+
35
  export const agent: Agent = {
36
  title: "Ant",
37
  type: "ant",
38
  simulate: (): Scene => {
39
  const action = pick(actions)
40
  const position = pick(positions)
41
+ const light = pick(lights)
42
 
43
  const prompt = [
44
  `close-up shot of a couple of ants`,
45
  action,
46
  position,
47
+ light,
48
  `high res`,
49
  `documentary`,
50
  ].join(", ")
 
52
  return {
53
  action,
54
  position,
55
+ light,
56
+ actionnables,
57
  prompt
58
  }
59
  }
src/app/agents/city.ts CHANGED
@@ -20,24 +20,34 @@ const positions = [
20
  "theme park with one big rollercoaster"
21
  ]
22
 
23
- const times = [
24
  "during the day",
25
  // "during the night",
26
  ]
27
 
 
 
 
 
 
 
 
 
 
 
28
  export const agent: Agent = {
29
  title: "City",
30
  type: "city",
31
  simulate: (): Scene => {
32
  const action = pick(actions)
33
  const position = pick(positions)
34
- const time = pick(times)
35
 
36
  const prompt = [
37
  `static isometrical view of 3D rendered city`,
38
  action,
39
  position,
40
- time,
41
  `isometric`,
42
  `game`,
43
  `high res`,
@@ -46,7 +56,8 @@ export const agent: Agent = {
46
  return {
47
  action,
48
  position,
49
- time,
 
50
  prompt
51
  }
52
  }
 
20
  "theme park with one big rollercoaster"
21
  ]
22
 
23
+ const lights = [
24
  "during the day",
25
  // "during the night",
26
  ]
27
 
28
+ const actionnables = [
29
+ "building",
30
+ "road",
31
+ "car",
32
+ "tower",
33
+ "tree",
34
+ "river",
35
+ "sea"
36
+ ]
37
+
38
  export const agent: Agent = {
39
  title: "City",
40
  type: "city",
41
  simulate: (): Scene => {
42
  const action = pick(actions)
43
  const position = pick(positions)
44
+ const light = pick(lights)
45
 
46
  const prompt = [
47
  `static isometrical view of 3D rendered city`,
48
  action,
49
  position,
50
+ light,
51
  `isometric`,
52
  `game`,
53
  `high res`,
 
56
  return {
57
  action,
58
  position,
59
+ light,
60
+ actionnables,
61
  prompt
62
  }
63
  }
src/app/agents/dungeon.ts CHANGED
@@ -22,25 +22,35 @@ const positions = [
22
  "a damp medieval jail cell with stone walls and wooden floor"
23
  ]
24
 
25
- const times = [
26
  "lit through windows",
27
  "lit through wall-mounted torchs"
28
  // "poorly lit"
29
  ]
30
 
 
 
 
 
 
 
 
 
 
 
31
  export const agent: Agent = {
32
  title: "Dungeon",
33
  type: "dungeon",
34
  simulate: (): Scene => {
35
  const action = pick(actions)
36
  const position = pick(positions)
37
- const time = pick(times)
38
 
39
  const prompt = [
40
  `first-person footage`,
41
  action,
42
  position,
43
- time,
44
  `medieval`,
45
  `photography`,
46
  `documentary`,
@@ -50,7 +60,8 @@ export const agent: Agent = {
50
  return {
51
  action,
52
  position,
53
- time,
 
54
  prompt
55
  }
56
  }
 
22
  "a damp medieval jail cell with stone walls and wooden floor"
23
  ]
24
 
25
+ const lights = [
26
  "lit through windows",
27
  "lit through wall-mounted torchs"
28
  // "poorly lit"
29
  ]
30
 
31
+ const actionnables = [
32
+ "floor",
33
+ "fireplace",
34
+ "door",
35
+ "window",
36
+ "chair",
37
+ "table",
38
+ "torch"
39
+ ]
40
+
41
  export const agent: Agent = {
42
  title: "Dungeon",
43
  type: "dungeon",
44
  simulate: (): Scene => {
45
  const action = pick(actions)
46
  const position = pick(positions)
47
+ const light = pick(lights)
48
 
49
  const prompt = [
50
  `first-person footage`,
51
  action,
52
  position,
53
+ light,
54
  `medieval`,
55
  `photography`,
56
  `documentary`,
 
60
  return {
61
  action,
62
  position,
63
+ light,
64
+ actionnables,
65
  prompt
66
  }
67
  }
src/app/agents/fish.ts CHANGED
@@ -21,23 +21,29 @@ const positions = [
21
  "hiding in the coral"
22
  ]
23
 
24
- const times = [
25
  "during the day",
26
  ]
27
 
 
 
 
 
 
 
28
  export const agent: Agent = {
29
  title: "Fish",
30
  type: "fish",
31
  simulate: (): Scene => {
32
  const action = pick(actions)
33
  const position = pick(positions)
34
- const time = pick(times)
35
 
36
  const prompt = [
37
  `medium shot of a clownfish`,
38
  action,
39
  position,
40
- time,
41
  `in front of yellow coral`,
42
  `high res`,
43
  `underwater footage`,
@@ -46,7 +52,8 @@ export const agent: Agent = {
46
  return {
47
  action,
48
  position,
49
- time,
 
50
  prompt
51
  }
52
  }
 
21
  "hiding in the coral"
22
  ]
23
 
24
+ const lights = [
25
  "during the day",
26
  ]
27
 
28
+ const actionnables = [
29
+ "fish",
30
+ "coral",
31
+ "sand"
32
+ ]
33
+
34
  export const agent: Agent = {
35
  title: "Fish",
36
  type: "fish",
37
  simulate: (): Scene => {
38
  const action = pick(actions)
39
  const position = pick(positions)
40
+ const light = pick(lights)
41
 
42
  const prompt = [
43
  `medium shot of a clownfish`,
44
  action,
45
  position,
46
+ light,
47
  `in front of yellow coral`,
48
  `high res`,
49
  `underwater footage`,
 
52
  return {
53
  action,
54
  position,
55
+ light,
56
+ actionnables,
57
  prompt
58
  }
59
  }
src/app/agents/fox.ts CHANGED
@@ -18,23 +18,32 @@ const positions = [
18
  "in front of a bush"
19
  ]
20
 
21
- const times = [
22
  "during the day",
23
  ]
24
 
 
 
 
 
 
 
 
 
 
25
  export const agent: Agent = {
26
  title: "Fox",
27
  type: "fox",
28
  simulate: (): Scene => {
29
  const action = pick(actions)
30
  const position = pick(positions)
31
- const time = pick(times)
32
 
33
  const prompt = [
34
  `medium shot of a fox`,
35
  action,
36
  position,
37
- time,
38
  `high res`,
39
  `documentary`,
40
  ].join(", ")
@@ -42,7 +51,8 @@ export const agent: Agent = {
42
  return {
43
  action,
44
  position,
45
- time,
 
46
  prompt
47
  }
48
  }
 
18
  "in front of a bush"
19
  ]
20
 
21
+ const lights = [
22
  "during the day",
23
  ]
24
 
25
+ const actionnables = [
26
+ "fox",
27
+ "ground",
28
+ "grass",
29
+ "water",
30
+ "tree",
31
+ "sky",
32
+ ]
33
+
34
  export const agent: Agent = {
35
  title: "Fox",
36
  type: "fox",
37
  simulate: (): Scene => {
38
  const action = pick(actions)
39
  const position = pick(positions)
40
+ const light = pick(lights)
41
 
42
  const prompt = [
43
  `medium shot of a fox`,
44
  action,
45
  position,
46
+ light,
47
  `high res`,
48
  `documentary`,
49
  ].join(", ")
 
51
  return {
52
  action,
53
  position,
54
+ light,
55
+ actionnables,
56
  prompt
57
  }
58
  }
src/app/agents/smith.ts CHANGED
@@ -17,25 +17,33 @@ const positions = [
17
  "on the sidewalk of a street"
18
  ]
19
 
20
- const times = [
21
  "during the day",
22
  "during the night",
23
  ]
24
 
 
 
 
 
 
 
 
 
25
  export const agent: Agent = {
26
  title: "Smith",
27
  type: "smith",
28
  simulate: (): Scene => {
29
  const action = pick(actions)
30
  const position = pick(positions)
31
- const time = pick(times)
32
 
33
  const prompt = [
34
  `static medium shot of Agent Smith from the Matrix`,
35
  `wearing a black costume with black tie and black sunglasses`,
36
  action,
37
  position,
38
- time,
39
  `high res`,
40
  `Matrix movie`,
41
  ].join(", ")
@@ -43,7 +51,8 @@ export const agent: Agent = {
43
  return {
44
  action,
45
  position,
46
- time,
 
47
  prompt
48
  }
49
  }
 
17
  "on the sidewalk of a street"
18
  ]
19
 
20
+ const lights = [
21
  "during the day",
22
  "during the night",
23
  ]
24
 
25
+ const actionnables = [
26
+ "face",
27
+ "costume",
28
+ "street",
29
+ "book",
30
+ "building",
31
+ ]
32
+
33
  export const agent: Agent = {
34
  title: "Smith",
35
  type: "smith",
36
  simulate: (): Scene => {
37
  const action = pick(actions)
38
  const position = pick(positions)
39
+ const light = pick(lights)
40
 
41
  const prompt = [
42
  `static medium shot of Agent Smith from the Matrix`,
43
  `wearing a black costume with black tie and black sunglasses`,
44
  action,
45
  position,
46
+ light,
47
  `high res`,
48
  `Matrix movie`,
49
  ].join(", ")
 
51
  return {
52
  action,
53
  position,
54
+ light,
55
+ actionnables,
56
  prompt
57
  }
58
  }
src/app/agents/types.ts CHANGED
@@ -3,7 +3,8 @@ export type AgentType = 'ant' | 'fish' | 'fox' | 'smith' | 'city' | 'dungeon'
3
  export interface Scene {
4
  action: string
5
  position: string
6
- time: string
 
7
  prompt: string
8
  }
9
 
 
3
  export interface Scene {
4
  action: string
5
  position: string
6
+ light: string
7
+ actionnables: string[]
8
  prompt: string
9
  }
10
 
src/app/main.tsx CHANGED
@@ -15,11 +15,13 @@ import {
15
  import { render } from "./render"
16
  import { Agent, AgentType, Scene } from "./agents/types"
17
  import { agents, defaultAgent, getAgent } from "./agents"
 
18
 
19
  export default function Main() {
20
- const [url, setUrl] = useState<string>()
21
  const [isPending, startTransition] = useTransition()
22
  const [scene, setScene] = useState<Scene>()
 
23
  const ref = useRef<AgentType>(defaultAgent)
24
 
25
  useEffect(() => {
@@ -37,7 +39,7 @@ export default function Main() {
37
  const scene = agent.simulate()
38
 
39
  // console.log(`rendering scene..`)
40
- const newUrl = await render(scene.prompt)
41
 
42
  if (type !== ref?.current) {
43
  console.log("agent type changed! reloading scene")
@@ -45,14 +47,16 @@ export default function Main() {
45
  return
46
  }
47
 
48
- if (newUrl) {
 
49
  // console.log(`got a new url: ${newUrl}`)
50
- setUrl(newUrl)
51
  setScene(scene)
 
52
  setTimeout(() => { updateView()}, 1000)
53
  } else {
54
  // console.log(`going to wait a bit more: ${newUrl}`)
55
- setTimeout(() => { updateView()}, 3000)
56
  }
57
  })
58
  }
@@ -70,7 +74,7 @@ export default function Main() {
70
  defaultValue={defaultAgent}
71
  onValueChange={(value) => {
72
  ref.current = value as AgentType
73
- // setUrl("")
74
  }}>
75
  <SelectTrigger className="w-[180px]">
76
  <SelectValue placeholder="Type" />
@@ -82,10 +86,19 @@ export default function Main() {
82
  </SelectContent>
83
  </Select>
84
  </div>
 
 
85
  {(scene) ? <div>
86
  <p>Action: {scene.action}</p>
87
  <p>Position: {scene.position}</p>
 
88
  </div> : null}
 
 
 
 
 
 
89
  </div>
90
  <VideoPlayer url={url} />
91
  </div>
 
15
  import { render } from "./render"
16
  import { Agent, AgentType, Scene } from "./agents/types"
17
  import { agents, defaultAgent, getAgent } from "./agents"
18
+ import { ImageSegment } from "./types"
19
 
20
  export default function Main() {
21
+ const [url, setUrl] = useState<string>("")
22
  const [isPending, startTransition] = useTransition()
23
  const [scene, setScene] = useState<Scene>()
24
+ const [segments, setSegments] = useState<ImageSegment[]>([])
25
  const ref = useRef<AgentType>(defaultAgent)
26
 
27
  useEffect(() => {
 
39
  const scene = agent.simulate()
40
 
41
  // console.log(`rendering scene..`)
42
+ const rendered = await render(scene.prompt, scene.actionnables)
43
 
44
  if (type !== ref?.current) {
45
  console.log("agent type changed! reloading scene")
 
47
  return
48
  }
49
 
50
+
51
+ if (rendered.videoUrl) {
52
  // console.log(`got a new url: ${newUrl}`)
53
+ setUrl(rendered.videoUrl)
54
  setScene(scene)
55
+ setSegments(rendered.segments)
56
  setTimeout(() => { updateView()}, 1000)
57
  } else {
58
  // console.log(`going to wait a bit more: ${newUrl}`)
59
+ setTimeout(() => { updateView()}, rendered.error ? 6000 : 3000)
60
  }
61
  })
62
  }
 
74
  defaultValue={defaultAgent}
75
  onValueChange={(value) => {
76
  ref.current = value as AgentType
77
+ setUrl("")
78
  }}>
79
  <SelectTrigger className="w-[180px]">
80
  <SelectValue placeholder="Type" />
 
86
  </SelectContent>
87
  </Select>
88
  </div>
89
+ <p>Note: changing the model might take up to 1 minute</p>
90
+
91
  {(scene) ? <div>
92
  <p>Action: {scene.action}</p>
93
  <p>Position: {scene.position}</p>
94
+ <p>Light: {scene.light}</p>
95
  </div> : null}
96
+ <div className="flex flex-col">
97
+ {segments.map((segment, i) =>
98
+ <div key={i}>
99
+ {segment.label} ({segment.score})
100
+ </div>)}
101
+ </div>
102
  </div>
103
  <VideoPlayer url={url} />
104
  </div>
src/app/render.ts CHANGED
@@ -1,10 +1,19 @@
1
  "use server"
2
 
 
 
3
  // note: there is no / at the end in the variable
4
  // so we have to add it ourselves if needed
5
  const apiUrl = process.env.RENDERING_ENGINE_API
6
 
7
- export async function render(prompt: string) {
 
 
 
 
 
 
 
8
  try {
9
  console.log(`calling ${apiUrl}/render with prompt: ${prompt}`)
10
  const res = await fetch(`${apiUrl}/render`, {
@@ -14,12 +23,20 @@ export async function render(prompt: string) {
14
  "Content-Type": "application/json",
15
  // Authorization: `Bearer ${process.env.VC_SECRET_ACCESS_TOKEN}`,
16
  },
17
- body: JSON.stringify({ prompt }),
 
 
 
 
 
 
 
18
  cache: 'no-store',
19
  // we can also use this (see https://vercel.com/blog/vercel-cache-api-nextjs-cache)
20
  // next: { revalidate: 1 }
21
  })
22
 
 
23
  // The return value is *not* serialized
24
  // You can return Date, Map, Set, etc.
25
 
@@ -29,11 +46,11 @@ export async function render(prompt: string) {
29
  throw new Error('Failed to fetch data')
30
  }
31
 
32
- const { url } = await res.json()
33
-
34
- return url
35
  } catch (err) {
36
  console.error(err)
37
- return ""
38
  }
39
  }
 
1
  "use server"
2
 
3
+ import { RenderAPIResponse } from "./types"
4
+
5
  // note: there is no / at the end in the variable
6
  // so we have to add it ourselves if needed
7
  const apiUrl = process.env.RENDERING_ENGINE_API
8
 
9
+ export async function render(prompt: string, actionnables: string[] = []) {
10
+ let defaulResult: RenderAPIResponse = {
11
+ videoUrl: "",
12
+ maskBase64: "",
13
+ error: "",
14
+ segments: []
15
+ }
16
+
17
  try {
18
  console.log(`calling ${apiUrl}/render with prompt: ${prompt}`)
19
  const res = await fetch(`${apiUrl}/render`, {
 
23
  "Content-Type": "application/json",
24
  // Authorization: `Bearer ${process.env.VC_SECRET_ACCESS_TOKEN}`,
25
  },
26
+ body: JSON.stringify({
27
+ prompt,
28
+ // nbFrames: 8 and nbSteps: 15 --> ~10 sec generation
29
+ nbFrames: 8,
30
+ nbSteps: 20,
31
+ segmentation: "firstframe",
32
+ actionnables,
33
+ }),
34
  cache: 'no-store',
35
  // we can also use this (see https://vercel.com/blog/vercel-cache-api-nextjs-cache)
36
  // next: { revalidate: 1 }
37
  })
38
 
39
+ // console.log("res:", res)
40
  // The return value is *not* serialized
41
  // You can return Date, Map, Set, etc.
42
 
 
46
  throw new Error('Failed to fetch data')
47
  }
48
 
49
+ const response = (await res.json()) as RenderAPIResponse
50
+ // console.log("response:", response)
51
+ return response
52
  } catch (err) {
53
  console.error(err)
54
+ return defaulResult
55
  }
56
  }
src/app/types.ts CHANGED
@@ -31,6 +31,17 @@ export interface ImageSegment {
31
  score: number
32
  }
33
 
34
- export interface RenderResponse {
35
-
 
 
 
 
 
 
 
 
 
 
 
36
  }
 
31
  score: number
32
  }
33
 
34
+
35
+ export interface ImageSegment {
36
+ id: number
37
+ box: number[]
38
+ label: string
39
+ score: number
40
+ }
41
+
42
+ export interface RenderAPIResponse {
43
+ videoUrl: string
44
+ error: string
45
+ maskBase64: string
46
+ segments: ImageSegment[]
47
  }
src/components/business/video-player.tsx CHANGED
@@ -4,7 +4,7 @@ export const VideoPlayer = ({ url }: { url?: string }) => {
4
 
5
  if (!url) {
6
  return <div className="flex w-full h-screen items-center justify-center text-center">
7
- <div>Generating first frames.. (might take around 30s)</div>
8
  </div>
9
  }
10
 
 
4
 
5
  if (!url) {
6
  return <div className="flex w-full h-screen items-center justify-center text-center">
7
+ <div>Rendering first scene (might take ~1 min)</div>
8
  </div>
9
  }
10