File size: 1,231 Bytes
e864e26
8919651
 
 
 
 
 
 
 
 
 
 
 
d4a1dc1
8919651
 
 
 
 
 
 
 
e864e26
8919651
 
58b1ffb
8919651
 
 
e864e26
8919651
 
 
 
 
 
e864e26
8919651
 
 
58b1ffb
8919651
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { ClapProject, ClapSegmentCategory, ClapSegmentFilteringMode, filterSegments } from "@aitube/clap"

import { LatentStory } from "@/app/api/v1/types"

/**
 * Extract the latent story from a ClapProject
 * 
 * This is useful to pass a simplified representation of a story to a LLM
 * 
 * @param clap 
 * @returns 
 */
export async function clapToLatentStory(clap: ClapProject): Promise<LatentStory[]> {
  const shots = clap.segments.filter(s => s.category === ClapSegmentCategory.CAMERA)

  const latentStories: LatentStory[] = []

  for (const shot of shots) {
    const image = filterSegments(
      ClapSegmentFilteringMode.START,
      shot,
      clap.segments,
      ClapSegmentCategory.STORYBOARD
    ).at(0)

    const comment = filterSegments(
      ClapSegmentFilteringMode.START,
      shot,
      clap.segments,
      ClapSegmentCategory.INTERFACE
    ).at(0)

    const voice = filterSegments(
      ClapSegmentFilteringMode.START,
      shot,
      clap.segments,
      ClapSegmentCategory.DIALOGUE
    ).at(0)

    const latentStory: LatentStory = {
      comment: comment.prompt,
      image: image.prompt,
      voice: voice.prompt,
    }
    
    latentStories.push(latentStory)
  }

  return latentStories
}