jbilcke-hf HF staff commited on
Commit
f95b0b5
·
1 Parent(s): 5b8b5b9

add agent smith

Browse files
src/app/agents/index.ts CHANGED
@@ -3,9 +3,10 @@ import { Agent, AgentType } from "./types"
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]
 
3
  import { agent as ant } from "./ant"
4
  import { agent as fish } from "./fish"
5
  import { agent as fox } from "./fox"
6
+ import { agent as smith } from "./smith"
7
 
8
+ export const agents = { ant, fish, fox, smith }
9
 
10
+ export const defaultAgent: AgentType = "fish"
11
 
12
  export const getAgent = (type?: AgentType) => agents[type || defaultAgent] || agents[defaultAgent]
src/app/agents/smith.ts ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { pick } from "./pick"
2
+ import { Agent, Scene } from "./types"
3
+
4
+ const actions = [
5
+ "standing and waiting",
6
+ "standing and looking at camera",
7
+ "standing and adjusting their tie",
8
+ "standing and talking on a cellphone",
9
+ "standing and reading the journal"
10
+ ]
11
+
12
+
13
+ const positions = [
14
+ "on the roof of a building",
15
+ "in the lobby of a building",
16
+ "in an elevator",
17
+ "on the sidewalk of a street"
18
+ ]
19
+
20
+ export const agent: Agent = {
21
+ title: "Smith",
22
+ type: "smith",
23
+ simulate: (): Scene => {
24
+ const action = pick(actions)
25
+ const position = pick(positions)
26
+
27
+ const prompt = [
28
+ `static medium shot of Agent Smith from the Matrix`,
29
+ `wearing a black costume with black tie and black sunglasses`,
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/agents/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type AgentType = 'ant' | 'fish' | 'fox'
2
 
3
  export interface Scene {
4
  action: string
 
1
+ export type AgentType = 'ant' | 'fish' | 'fox' | 'smith'
2
 
3
  export interface Scene {
4
  action: string
src/app/main.tsx CHANGED
@@ -19,16 +19,15 @@ import { agents, defaultAgent, getAgent } from "./agents"
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
 
28
  const updateView = async () => {
29
- console.log(`update view..`)
30
 
31
- startTransition(async () => {
32
 
33
  // console.log(`getting agent..`)
34
  const type = ref?.current
@@ -41,18 +40,20 @@ export default function Main() {
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
- if (!newUrl) {
51
  setUrl(newUrl)
 
 
 
 
 
52
  }
53
- setAgent(agent)
54
- setScene(scene)
55
- setTimeout(() => { updateView()}, 2000)
56
  })
57
  }
58
 
 
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(() => {
26
 
27
  const updateView = async () => {
28
+ // console.log(`update view..`)
29
 
30
+ await startTransition(async () => {
31
 
32
  // console.log(`getting agent..`)
33
  const type = ref?.current
 
40
  const newUrl = await render(scene.prompt)
41
 
42
  if (type !== ref?.current) {
43
+ console.log("agent type changed! reloading scene")
44
  setTimeout(() => { updateView() }, 0)
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
  }
59