Spaces:
Paused
Paused
Julian Bilcke
commited on
Commit
Β·
734f3d3
1
Parent(s):
e6812d5
better arch
Browse files- src/app/{scenes/ants.ts β agents/ant.ts} +19 -15
- src/app/{scenes/fishTank.ts β agents/fish.ts} +20 -16
- src/app/agents/fox.ts +43 -0
- src/app/agents/index.ts +11 -0
- src/app/{scenes β agents}/pick.ts +0 -0
- src/app/{scenes β agents}/types.ts +7 -1
- src/app/main.tsx +22 -34
- src/app/{renderScene.ts β render.ts} +1 -1
src/app/{scenes/ants.ts β agents/ant.ts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import { pick } from "./pick"
|
|
|
|
| 2 |
|
| 3 |
const actions = [
|
| 4 |
"working on lavae",
|
|
@@ -17,22 +18,25 @@ const positions = [
|
|
| 17 |
"on the ground"
|
| 18 |
]
|
| 19 |
|
| 20 |
-
export const
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
}
|
| 38 |
}
|
|
|
|
| 1 |
import { pick } from "./pick"
|
| 2 |
+
import { Agent } from "./types"
|
| 3 |
|
| 4 |
const actions = [
|
| 5 |
"working on lavae",
|
|
|
|
| 18 |
"on the ground"
|
| 19 |
]
|
| 20 |
|
| 21 |
+
export const agent: Agent = {
|
| 22 |
+
title: "Ant",
|
| 23 |
+
type: "ant",
|
| 24 |
+
simulate: (): Scene => {
|
| 25 |
+
const action = pick(actions)
|
| 26 |
+
const position = pick(positions)
|
| 27 |
|
| 28 |
+
const prompt = [
|
| 29 |
+
`close-up shot of a couple of ants`,
|
| 30 |
+
action,
|
| 31 |
+
position,
|
| 32 |
+
`high res`,
|
| 33 |
+
`documentary`,
|
| 34 |
+
].join(", ")
|
| 35 |
|
| 36 |
+
return {
|
| 37 |
+
action,
|
| 38 |
+
position,
|
| 39 |
+
prompt
|
| 40 |
+
}
|
| 41 |
}
|
| 42 |
}
|
src/app/{scenes/fishTank.ts β agents/fish.ts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import { pick } from "./pick"
|
|
|
|
| 2 |
|
| 3 |
const actions = [
|
| 4 |
"idling",
|
|
@@ -20,22 +21,25 @@ const positions = [
|
|
| 20 |
"hiding in the coral"
|
| 21 |
]
|
| 22 |
|
| 23 |
-
export const
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
}
|
| 41 |
-
}
|
|
|
|
| 1 |
import { pick } from "./pick"
|
| 2 |
+
import { Agent, Scene } from "./types"
|
| 3 |
|
| 4 |
const actions = [
|
| 5 |
"idling",
|
|
|
|
| 21 |
"hiding in the coral"
|
| 22 |
]
|
| 23 |
|
| 24 |
+
export const agent: Agent = {
|
| 25 |
+
title: "Fish",
|
| 26 |
+
type: "fish",
|
| 27 |
+
simulate: (): Scene => {
|
| 28 |
+
const action = pick(actions)
|
| 29 |
+
const position = pick(positions)
|
| 30 |
|
| 31 |
+
const prompt = [
|
| 32 |
+
`medium shot of a clownfish`,
|
| 33 |
+
action,
|
| 34 |
+
position,
|
| 35 |
+
`in front of yellow coral`,
|
| 36 |
+
`high res underwater footage`,
|
| 37 |
+
].join(", ")
|
| 38 |
|
| 39 |
+
return {
|
| 40 |
+
action,
|
| 41 |
+
position,
|
| 42 |
+
prompt
|
| 43 |
+
}
|
| 44 |
}
|
| 45 |
+
}
|
src/app/agents/fox.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { pick } from "./pick"
|
| 2 |
+
import { Agent, Scene } from "./types"
|
| 3 |
+
|
| 4 |
+
const actions = [
|
| 5 |
+
"waiting",
|
| 6 |
+
"jumping",
|
| 7 |
+
"eating a mouse",
|
| 8 |
+
"looking at camera",
|
| 9 |
+
"touch a rock",
|
| 10 |
+
"touching grass",
|
| 11 |
+
"drinking from a water hole"
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
const positions = [
|
| 15 |
+
"in the forest",
|
| 16 |
+
"in a plain",
|
| 17 |
+
"in front of a fox hole",
|
| 18 |
+
"in front of a bush"
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
export const agent: Agent = {
|
| 23 |
+
title: "Fox",
|
| 24 |
+
type: "fox",
|
| 25 |
+
simulate: (): Scene => {
|
| 26 |
+
const action = pick(actions)
|
| 27 |
+
const position = pick(positions)
|
| 28 |
+
|
| 29 |
+
const prompt = [
|
| 30 |
+
`medium shot of a fox`,
|
| 31 |
+
action,
|
| 32 |
+
position,
|
| 33 |
+
`high res`,
|
| 34 |
+
`documentary`,
|
| 35 |
+
].join(", ")
|
| 36 |
+
|
| 37 |
+
return {
|
| 38 |
+
action,
|
| 39 |
+
position,
|
| 40 |
+
prompt
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
src/app/agents/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Agent, AgentType } from "./types"
|
| 2 |
+
|
| 3 |
+
import { agent as ant } from "./ant"
|
| 4 |
+
import { agent as fish } from "./fish"
|
| 5 |
+
import { agent as fox } from "./fox"
|
| 6 |
+
|
| 7 |
+
export const agents = { ant, fish, fox }
|
| 8 |
+
|
| 9 |
+
export const defaultAgent: AgentType = "fox"
|
| 10 |
+
|
| 11 |
+
export const getAgent = (type?: AgentType) => agents[type || defaultAgent] || agents[defaultAgent]
|
src/app/{scenes β agents}/pick.ts
RENAMED
|
File without changes
|
src/app/{scenes β agents}/types.ts
RENAMED
|
@@ -1,7 +1,13 @@
|
|
|
|
|
| 1 |
|
| 2 |
export interface Scene {
|
| 3 |
-
name: string
|
| 4 |
action: string
|
| 5 |
position: string
|
| 6 |
prompt: string
|
| 7 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type AgentType = 'ant' | 'fish' | 'fox'
|
| 2 |
|
| 3 |
export interface Scene {
|
|
|
|
| 4 |
action: string
|
| 5 |
position: string
|
| 6 |
prompt: string
|
| 7 |
}
|
| 8 |
+
|
| 9 |
+
export interface Agent {
|
| 10 |
+
title: string
|
| 11 |
+
type: AgentType
|
| 12 |
+
simulate: () => Scene
|
| 13 |
+
}
|
src/app/main.tsx
CHANGED
|
@@ -12,33 +12,16 @@ import {
|
|
| 12 |
SelectValue,
|
| 13 |
} from "@/components/ui/select"
|
| 14 |
|
| 15 |
-
import {
|
| 16 |
-
import { Scene } from "./
|
| 17 |
-
|
| 18 |
-
import { getScene as getSceneAnts } from "./scenes/ants"
|
| 19 |
-
import { getScene as getSceneFishes } from "./scenes/fishTank"
|
| 20 |
-
|
| 21 |
-
type SceneType = 'ant' | 'fish'
|
| 22 |
-
|
| 23 |
-
const types: {
|
| 24 |
-
label: string
|
| 25 |
-
value: SceneType
|
| 26 |
-
}[] = [
|
| 27 |
-
{
|
| 28 |
-
label: "Ant",
|
| 29 |
-
value: "ant"
|
| 30 |
-
},
|
| 31 |
-
{
|
| 32 |
-
label: "Fish",
|
| 33 |
-
value: "fish"
|
| 34 |
-
}
|
| 35 |
-
]
|
| 36 |
|
| 37 |
export default function Main() {
|
| 38 |
const [url, setUrl] = useState<string>()
|
| 39 |
const [isPending, startTransition] = useTransition()
|
|
|
|
| 40 |
const [scene, setScene] = useState<Scene>()
|
| 41 |
-
const ref = useRef<
|
| 42 |
|
| 43 |
useEffect(() => {
|
| 44 |
|
|
@@ -47,21 +30,26 @@ export default function Main() {
|
|
| 47 |
|
| 48 |
startTransition(async () => {
|
| 49 |
|
| 50 |
-
console.log(`
|
| 51 |
const type = ref?.current
|
| 52 |
-
const
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
if (type !== ref?.current) {
|
| 57 |
-
console.log("
|
| 58 |
setTimeout(() => { updateView() }, 0)
|
| 59 |
return
|
| 60 |
}
|
| 61 |
|
| 62 |
// console.log(`newUrl: ${newUrl}`)
|
| 63 |
setUrl(newUrl)
|
| 64 |
-
|
|
|
|
| 65 |
setTimeout(() => { updateView()}, 2000)
|
| 66 |
})
|
| 67 |
}
|
|
@@ -76,24 +64,24 @@ export default function Main() {
|
|
| 76 |
<div className="flex flex-row items-center space-x-3">
|
| 77 |
<label className="flex">Agent model:</label>
|
| 78 |
<Select
|
| 79 |
-
defaultValue={
|
| 80 |
onValueChange={(value) => {
|
| 81 |
-
ref.current = value as
|
| 82 |
setUrl("")
|
| 83 |
}}>
|
| 84 |
<SelectTrigger className="w-[180px]">
|
| 85 |
<SelectValue placeholder="Type" />
|
| 86 |
</SelectTrigger>
|
| 87 |
<SelectContent>
|
| 88 |
-
{
|
| 89 |
-
<SelectItem key={
|
| 90 |
)}
|
| 91 |
</SelectContent>
|
| 92 |
</Select>
|
| 93 |
</div>
|
| 94 |
-
{url ? <div>
|
| 95 |
-
<p>Action: {scene
|
| 96 |
-
<p>Position: {scene
|
| 97 |
</div> : null}
|
| 98 |
</div>
|
| 99 |
<VideoPlayer url={url} />
|
|
|
|
| 12 |
SelectValue,
|
| 13 |
} from "@/components/ui/select"
|
| 14 |
|
| 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 [agent, setAgent] = useState<Agent>()
|
| 23 |
const [scene, setScene] = useState<Scene>()
|
| 24 |
+
const ref = useRef<AgentType>(defaultAgent)
|
| 25 |
|
| 26 |
useEffect(() => {
|
| 27 |
|
|
|
|
| 30 |
|
| 31 |
startTransition(async () => {
|
| 32 |
|
| 33 |
+
// console.log(`getting agent..`)
|
| 34 |
const type = ref?.current
|
| 35 |
+
const agent = getAgent(type)
|
| 36 |
+
|
| 37 |
+
// console.log(`asking agent to determine things..`)
|
| 38 |
+
const scene = agent.simulate()
|
| 39 |
|
| 40 |
+
// console.log(`rendering scene..`)
|
| 41 |
+
const newUrl = await render(scene.prompt)
|
| 42 |
|
| 43 |
if (type !== ref?.current) {
|
| 44 |
+
console.log("agent type changed while we were rendering")
|
| 45 |
setTimeout(() => { updateView() }, 0)
|
| 46 |
return
|
| 47 |
}
|
| 48 |
|
| 49 |
// console.log(`newUrl: ${newUrl}`)
|
| 50 |
setUrl(newUrl)
|
| 51 |
+
setAgent(agent)
|
| 52 |
+
setScene(scene)
|
| 53 |
setTimeout(() => { updateView()}, 2000)
|
| 54 |
})
|
| 55 |
}
|
|
|
|
| 64 |
<div className="flex flex-row items-center space-x-3">
|
| 65 |
<label className="flex">Agent model:</label>
|
| 66 |
<Select
|
| 67 |
+
defaultValue={defaultAgent}
|
| 68 |
onValueChange={(value) => {
|
| 69 |
+
ref.current = value as AgentType
|
| 70 |
setUrl("")
|
| 71 |
}}>
|
| 72 |
<SelectTrigger className="w-[180px]">
|
| 73 |
<SelectValue placeholder="Type" />
|
| 74 |
</SelectTrigger>
|
| 75 |
<SelectContent>
|
| 76 |
+
{Object.entries(agents).map(([key, agent]) =>
|
| 77 |
+
<SelectItem key={key} value={key}>{agent.title}</SelectItem>
|
| 78 |
)}
|
| 79 |
</SelectContent>
|
| 80 |
</Select>
|
| 81 |
</div>
|
| 82 |
+
{(url && scene) ? <div>
|
| 83 |
+
<p>Action: {scene.action}</p>
|
| 84 |
+
<p>Position: {scene.position}</p>
|
| 85 |
</div> : null}
|
| 86 |
</div>
|
| 87 |
<VideoPlayer url={url} />
|
src/app/{renderScene.ts β render.ts}
RENAMED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
// so we have to add it ourselves if needed
|
| 5 |
const apiUrl = process.env.RENDERING_ENGINE_API
|
| 6 |
|
| 7 |
-
export async function
|
| 8 |
try {
|
| 9 |
console.log(`calling ${apiUrl}/render with prompt: ${prompt}`)
|
| 10 |
const res = await fetch(`${apiUrl}/render`, {
|
|
|
|
| 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`, {
|