Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
637b219
1
Parent(s):
e02a62b
fix Clap types
Browse files- src/clap/parseClap.ts +41 -4
- src/clap/serializeClap.ts +36 -1
- src/clap/types.ts +34 -0
src/clap/parseClap.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import YAML from "yaml"
|
2 |
import { v4 as uuidv4 } from "uuid"
|
3 |
|
4 |
-
import { ClapHeader, ClapMeta, ClapModel, ClapProject, ClapSegment } from "./types"
|
5 |
import { getValidNumber } from "@/lib/getValidNumber"
|
6 |
|
7 |
/**
|
@@ -68,6 +68,7 @@ export async function parseClap(inputStringOrBlob: string | Blob): Promise<ClapP
|
|
68 |
|
69 |
|
70 |
const expectedNumberOfModels = maybeClapHeader.numberOfModels || 0
|
|
|
71 |
const expectedNumberOfSegments = maybeClapHeader.numberOfSegments || 0
|
72 |
|
73 |
// note: we assume the order is strictly enforced!
|
@@ -76,10 +77,15 @@ export async function parseClap(inputStringOrBlob: string | Blob): Promise<ClapP
|
|
76 |
const afterTheHeaders = 2
|
77 |
const afterTheModels = afterTheHeaders + expectedNumberOfModels
|
78 |
|
|
|
|
|
79 |
// note: if there are no expected models, maybeModels will be empty
|
80 |
const maybeModels = rawData.slice(afterTheHeaders, afterTheModels) as ClapModel[]
|
81 |
|
82 |
-
|
|
|
|
|
|
|
83 |
|
84 |
const clapModels: ClapModel[] = maybeModels.map(({
|
85 |
id,
|
@@ -118,7 +124,30 @@ export async function parseClap(inputStringOrBlob: string | Blob): Promise<ClapP
|
|
118 |
voiceId,
|
119 |
}))
|
120 |
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
const clapSegments: ClapSegment[] = maybeSegments.map(({
|
123 |
id,
|
124 |
track,
|
@@ -126,11 +155,15 @@ export async function parseClap(inputStringOrBlob: string | Blob): Promise<ClapP
|
|
126 |
endTimeInMs,
|
127 |
category,
|
128 |
modelId,
|
|
|
129 |
prompt,
|
130 |
outputType,
|
131 |
renderId,
|
132 |
status,
|
133 |
assetUrl,
|
|
|
|
|
|
|
134 |
outputGain,
|
135 |
seed,
|
136 |
}) => ({
|
@@ -141,11 +174,15 @@ export async function parseClap(inputStringOrBlob: string | Blob): Promise<ClapP
|
|
141 |
endTimeInMs,
|
142 |
category,
|
143 |
modelId,
|
|
|
144 |
prompt,
|
145 |
outputType,
|
146 |
renderId,
|
147 |
status,
|
148 |
assetUrl,
|
|
|
|
|
|
|
149 |
outputGain,
|
150 |
seed,
|
151 |
}))
|
@@ -153,7 +190,7 @@ export async function parseClap(inputStringOrBlob: string | Blob): Promise<ClapP
|
|
153 |
return {
|
154 |
meta: clapMeta,
|
155 |
models: clapModels,
|
|
|
156 |
segments: clapSegments
|
157 |
}
|
158 |
}
|
159 |
-
|
|
|
1 |
import YAML from "yaml"
|
2 |
import { v4 as uuidv4 } from "uuid"
|
3 |
|
4 |
+
import { ClapHeader, ClapMeta, ClapModel, ClapProject, ClapScene, ClapSegment } from "./types"
|
5 |
import { getValidNumber } from "@/lib/getValidNumber"
|
6 |
|
7 |
/**
|
|
|
68 |
|
69 |
|
70 |
const expectedNumberOfModels = maybeClapHeader.numberOfModels || 0
|
71 |
+
const expectedNumberOfScenes = maybeClapHeader.numberOfScenes || 0
|
72 |
const expectedNumberOfSegments = maybeClapHeader.numberOfSegments || 0
|
73 |
|
74 |
// note: we assume the order is strictly enforced!
|
|
|
77 |
const afterTheHeaders = 2
|
78 |
const afterTheModels = afterTheHeaders + expectedNumberOfModels
|
79 |
|
80 |
+
const afterTheScenes = afterTheModels + expectedNumberOfScenes
|
81 |
+
|
82 |
// note: if there are no expected models, maybeModels will be empty
|
83 |
const maybeModels = rawData.slice(afterTheHeaders, afterTheModels) as ClapModel[]
|
84 |
|
85 |
+
// note: if there are no expected scenes, maybeScenes will be empty
|
86 |
+
const maybeScenes = rawData.slice(afterTheModels, afterTheScenes) as ClapScene[]
|
87 |
+
|
88 |
+
const maybeSegments = rawData.slice(afterTheScenes) as ClapSegment[]
|
89 |
|
90 |
const clapModels: ClapModel[] = maybeModels.map(({
|
91 |
id,
|
|
|
124 |
voiceId,
|
125 |
}))
|
126 |
|
127 |
+
const clapScenes: ClapScene[] = maybeScenes.map(({
|
128 |
+
id,
|
129 |
+
scene,
|
130 |
+
line,
|
131 |
+
rawLine,
|
132 |
+
sequenceFullText,
|
133 |
+
sequenceStartAtLine,
|
134 |
+
sequenceEndAtLine,
|
135 |
+
startAtLine,
|
136 |
+
endAtLine,
|
137 |
+
events,
|
138 |
+
}) => ({
|
139 |
+
id,
|
140 |
+
scene,
|
141 |
+
line,
|
142 |
+
rawLine,
|
143 |
+
sequenceFullText,
|
144 |
+
sequenceStartAtLine,
|
145 |
+
sequenceEndAtLine,
|
146 |
+
startAtLine,
|
147 |
+
endAtLine,
|
148 |
+
events: events.map(e => e)
|
149 |
+
}))
|
150 |
+
|
151 |
const clapSegments: ClapSegment[] = maybeSegments.map(({
|
152 |
id,
|
153 |
track,
|
|
|
155 |
endTimeInMs,
|
156 |
category,
|
157 |
modelId,
|
158 |
+
sceneId,
|
159 |
prompt,
|
160 |
outputType,
|
161 |
renderId,
|
162 |
status,
|
163 |
assetUrl,
|
164 |
+
assetDuration,
|
165 |
+
createdBy,
|
166 |
+
editedBy,
|
167 |
outputGain,
|
168 |
seed,
|
169 |
}) => ({
|
|
|
174 |
endTimeInMs,
|
175 |
category,
|
176 |
modelId,
|
177 |
+
sceneId,
|
178 |
prompt,
|
179 |
outputType,
|
180 |
renderId,
|
181 |
status,
|
182 |
assetUrl,
|
183 |
+
assetDuration,
|
184 |
+
createdBy,
|
185 |
+
editedBy,
|
186 |
outputGain,
|
187 |
seed,
|
188 |
}))
|
|
|
190 |
return {
|
191 |
meta: clapMeta,
|
192 |
models: clapModels,
|
193 |
+
scenes: clapScenes,
|
194 |
segments: clapSegments
|
195 |
}
|
196 |
}
|
|
src/clap/serializeClap.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
import YAML from "yaml"
|
2 |
import { v4 as uuidv4 } from "uuid"
|
3 |
|
4 |
-
import { ClapHeader, ClapMeta, ClapModel, ClapProject, ClapSegment } from "./types"
|
5 |
import { getValidNumber } from "@/lib/getValidNumber"
|
6 |
|
7 |
export async function serializeClap({
|
8 |
meta, // ClapMeta
|
9 |
models, // ClapModel[]
|
|
|
10 |
segments, // ClapSegment[]
|
11 |
}: ClapProject): Promise<Blob> {
|
12 |
|
@@ -48,6 +49,30 @@ export async function serializeClap({
|
|
48 |
voiceId,
|
49 |
}))
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
const clapSegments: ClapSegment[] = segments.map(({
|
52 |
id,
|
53 |
track,
|
@@ -55,11 +80,15 @@ export async function serializeClap({
|
|
55 |
endTimeInMs,
|
56 |
category,
|
57 |
modelId,
|
|
|
58 |
prompt,
|
59 |
outputType,
|
60 |
renderId,
|
61 |
status,
|
62 |
assetUrl,
|
|
|
|
|
|
|
63 |
outputGain,
|
64 |
seed,
|
65 |
}) => ({
|
@@ -69,11 +98,15 @@ export async function serializeClap({
|
|
69 |
endTimeInMs,
|
70 |
category,
|
71 |
modelId,
|
|
|
72 |
prompt,
|
73 |
outputType,
|
74 |
renderId,
|
75 |
status,
|
76 |
assetUrl,
|
|
|
|
|
|
|
77 |
outputGain,
|
78 |
seed,
|
79 |
}))
|
@@ -81,6 +114,7 @@ export async function serializeClap({
|
|
81 |
const clapHeader: ClapHeader = {
|
82 |
format: "clap-0",
|
83 |
numberOfModels: clapModels.length,
|
|
|
84 |
numberOfSegments: clapSegments.length,
|
85 |
}
|
86 |
|
@@ -100,6 +134,7 @@ export async function serializeClap({
|
|
100 |
clapHeader,
|
101 |
clapMeta,
|
102 |
...clapModels,
|
|
|
103 |
...clapSegments
|
104 |
]
|
105 |
|
|
|
1 |
import YAML from "yaml"
|
2 |
import { v4 as uuidv4 } from "uuid"
|
3 |
|
4 |
+
import { ClapHeader, ClapMeta, ClapModel, ClapProject, ClapScene, ClapSegment } from "./types"
|
5 |
import { getValidNumber } from "@/lib/getValidNumber"
|
6 |
|
7 |
export async function serializeClap({
|
8 |
meta, // ClapMeta
|
9 |
models, // ClapModel[]
|
10 |
+
scenes, // ClapScene[]
|
11 |
segments, // ClapSegment[]
|
12 |
}: ClapProject): Promise<Blob> {
|
13 |
|
|
|
49 |
voiceId,
|
50 |
}))
|
51 |
|
52 |
+
const clapScenes: ClapScene[] = scenes.map(({
|
53 |
+
id,
|
54 |
+
scene,
|
55 |
+
line,
|
56 |
+
rawLine,
|
57 |
+
sequenceFullText,
|
58 |
+
sequenceStartAtLine,
|
59 |
+
sequenceEndAtLine,
|
60 |
+
startAtLine,
|
61 |
+
endAtLine,
|
62 |
+
events,
|
63 |
+
}) => ({
|
64 |
+
id,
|
65 |
+
scene,
|
66 |
+
line,
|
67 |
+
rawLine,
|
68 |
+
sequenceFullText,
|
69 |
+
sequenceStartAtLine,
|
70 |
+
sequenceEndAtLine,
|
71 |
+
startAtLine,
|
72 |
+
endAtLine,
|
73 |
+
events: events.map(e => e)
|
74 |
+
}))
|
75 |
+
|
76 |
const clapSegments: ClapSegment[] = segments.map(({
|
77 |
id,
|
78 |
track,
|
|
|
80 |
endTimeInMs,
|
81 |
category,
|
82 |
modelId,
|
83 |
+
sceneId,
|
84 |
prompt,
|
85 |
outputType,
|
86 |
renderId,
|
87 |
status,
|
88 |
assetUrl,
|
89 |
+
assetDuration,
|
90 |
+
createdBy,
|
91 |
+
editedBy,
|
92 |
outputGain,
|
93 |
seed,
|
94 |
}) => ({
|
|
|
98 |
endTimeInMs,
|
99 |
category,
|
100 |
modelId,
|
101 |
+
sceneId,
|
102 |
prompt,
|
103 |
outputType,
|
104 |
renderId,
|
105 |
status,
|
106 |
assetUrl,
|
107 |
+
assetDuration,
|
108 |
+
createdBy,
|
109 |
+
editedBy,
|
110 |
outputGain,
|
111 |
seed,
|
112 |
}))
|
|
|
114 |
const clapHeader: ClapHeader = {
|
115 |
format: "clap-0",
|
116 |
numberOfModels: clapModels.length,
|
117 |
+
numberOfScenes: clapScenes.length,
|
118 |
numberOfSegments: clapSegments.length,
|
119 |
}
|
120 |
|
|
|
134 |
clapHeader,
|
135 |
clapMeta,
|
136 |
...clapModels,
|
137 |
+
...clapScenes,
|
138 |
...clapSegments
|
139 |
]
|
140 |
|
src/clap/types.ts
CHANGED
@@ -3,6 +3,11 @@ export type ClapSegmentCategory = "render" | "preview" | "characters" | "locatio
|
|
3 |
export type ClapOutputType = "text" | "movement" | "image" | "video" | "audio"
|
4 |
export type ClapSegmentStatus = "pending" | "completed" | "error"
|
5 |
|
|
|
|
|
|
|
|
|
|
|
6 |
export type ClapAssetSource =
|
7 |
| "REMOTE" // http:// or https://
|
8 |
|
@@ -60,6 +65,7 @@ export type ClapVoice = {
|
|
60 |
export type ClapHeader = {
|
61 |
format: "clap-0"
|
62 |
numberOfModels: number
|
|
|
63 |
numberOfSegments: number
|
64 |
}
|
65 |
|
@@ -75,6 +81,29 @@ export type ClapMeta = {
|
|
75 |
extraPositivePrompt: string[]
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
export type ClapSegment = {
|
79 |
id: string
|
80 |
track: number
|
@@ -82,11 +111,15 @@ export type ClapSegment = {
|
|
82 |
endTimeInMs: number
|
83 |
category: ClapSegmentCategory
|
84 |
modelId: string
|
|
|
85 |
prompt: string
|
86 |
outputType: ClapOutputType
|
87 |
renderId: string
|
88 |
status: ClapSegmentStatus
|
89 |
assetUrl: string
|
|
|
|
|
|
|
90 |
outputGain: number
|
91 |
seed: number
|
92 |
}
|
@@ -116,6 +149,7 @@ export type ClapModel = {
|
|
116 |
export type ClapProject = {
|
117 |
meta: ClapMeta
|
118 |
models: ClapModel[]
|
|
|
119 |
segments: ClapSegment[]
|
120 |
// let's keep room for other stuff (screenplay etc)
|
121 |
}
|
|
|
3 |
export type ClapOutputType = "text" | "movement" | "image" | "video" | "audio"
|
4 |
export type ClapSegmentStatus = "pending" | "completed" | "error"
|
5 |
|
6 |
+
export type ClapAuthor =
|
7 |
+
| "auto" // the element was edited automatically using basic if/else logical rules
|
8 |
+
| "ai" // the element was edited using a large language model
|
9 |
+
| "human" // the element was edited by a human
|
10 |
+
|
11 |
export type ClapAssetSource =
|
12 |
| "REMOTE" // http:// or https://
|
13 |
|
|
|
65 |
export type ClapHeader = {
|
66 |
format: "clap-0"
|
67 |
numberOfModels: number
|
68 |
+
numberOfScenes: number
|
69 |
numberOfSegments: number
|
70 |
}
|
71 |
|
|
|
81 |
extraPositivePrompt: string[]
|
82 |
}
|
83 |
|
84 |
+
export type ClapSceneEvent = {
|
85 |
+
id: string
|
86 |
+
type: "description" | "dialogue" | "action"
|
87 |
+
character?: string
|
88 |
+
description: string
|
89 |
+
behavior: string
|
90 |
+
startAtLine: number
|
91 |
+
endAtLine: number
|
92 |
+
}
|
93 |
+
|
94 |
+
export type ClapScene = {
|
95 |
+
id: string
|
96 |
+
scene: string
|
97 |
+
line: string
|
98 |
+
rawLine: string
|
99 |
+
sequenceFullText: string
|
100 |
+
sequenceStartAtLine: number
|
101 |
+
sequenceEndAtLine: number
|
102 |
+
startAtLine: number
|
103 |
+
endAtLine: number
|
104 |
+
events: ClapSceneEvent[]
|
105 |
+
}
|
106 |
+
|
107 |
export type ClapSegment = {
|
108 |
id: string
|
109 |
track: number
|
|
|
111 |
endTimeInMs: number
|
112 |
category: ClapSegmentCategory
|
113 |
modelId: string
|
114 |
+
sceneId: string
|
115 |
prompt: string
|
116 |
outputType: ClapOutputType
|
117 |
renderId: string
|
118 |
status: ClapSegmentStatus
|
119 |
assetUrl: string
|
120 |
+
assetDuration: number
|
121 |
+
createdBy: ClapAuthor
|
122 |
+
editedBy: ClapAuthor
|
123 |
outputGain: number
|
124 |
seed: number
|
125 |
}
|
|
|
149 |
export type ClapProject = {
|
150 |
meta: ClapMeta
|
151 |
models: ClapModel[]
|
152 |
+
scenes: ClapScene[]
|
153 |
segments: ClapSegment[]
|
154 |
// let's keep room for other stuff (screenplay etc)
|
155 |
}
|