jbilcke-hf HF staff commited on
Commit
4348dc5
Β·
1 Parent(s): 0d218b1

let's have a proper /api/v1/

Browse files
src/app/api/v1/README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /v1
2
+
3
+ The first version of the public API
4
+
5
+ Note that this API is a work in progress and should be considered a draft.
6
+
7
+ It is subject to unannounced changes.
8
+
9
+ ## /create
10
+
11
+ This endpoint will generate a .clap (story only) from a prompt
12
+
13
+ ## /edit
14
+
15
+ This endpoint will edit a .clap to change models or storyboards
16
+
17
+ ## /export
18
+
19
+ This endpoint will export a .clap to a static video
20
+
21
+ parameters:
22
+
23
+ ### f: format (either "mp4" or "webm")
24
+
25
+ Example:
26
+
27
+ `POST <some_clap> /api/v1/export?f=webm`
28
+
src/app/api/{generate/story β†’ v1/create}/route.ts RENAMED
@@ -1,8 +1,8 @@
1
  import { NextResponse, NextRequest } from "next/server"
2
  import { ClapProject, getValidNumber, newClap, newSegment, serializeClap } from "@aitube/clap"
3
 
4
- import { predict } from "../../providers/huggingface/predictWithHuggingFace"
5
- import { parseRawStringToYAML } from "../../utils/parseRawStringToYAML"
6
 
7
  import { systemPrompt } from "./systemPrompt"
8
 
 
1
  import { NextResponse, NextRequest } from "next/server"
2
  import { ClapProject, getValidNumber, newClap, newSegment, serializeClap } from "@aitube/clap"
3
 
4
+ import { predict } from "@/app/api/providers/huggingface/predictWithHuggingFace"
5
+ import { parseRawStringToYAML } from "@/app/api/utils/parseRawStringToYAML"
6
 
7
  import { systemPrompt } from "./systemPrompt"
8
 
src/app/api/{generate/story β†’ v1/create}/systemPrompt.ts RENAMED
File without changes
src/app/api/{generate/story β†’ v1/create}/userPrompt.ts RENAMED
File without changes
src/app/api/{generate β†’ v1/edit}/models/generateAudioID.ts RENAMED
File without changes
src/app/api/{generate β†’ v1/edit}/models/generateImageID.ts RENAMED
@@ -4,8 +4,8 @@ import { generateSeed } from "@aitube/clap"
4
  import { sleep } from "@/lib/utils/sleep"
5
  import { getValidNumber } from "@/lib/utils/getValidNumber"
6
 
7
- import { newRender, getRender } from "../../providers/videochain/renderWithVideoChain"
8
- import { getNegativePrompt, getPositivePrompt } from "../../utils/imagePrompts"
9
 
10
  export async function generateImageID({
11
  prompt,
 
4
  import { sleep } from "@/lib/utils/sleep"
5
  import { getValidNumber } from "@/lib/utils/getValidNumber"
6
 
7
+ import { newRender, getRender } from "@/app/api/providers/videochain/renderWithVideoChain"
8
+ import { getNegativePrompt, getPositivePrompt } from "@/app/api/utils/imagePrompts"
9
 
10
  export async function generateImageID({
11
  prompt,
src/app/api/{generate β†’ v1/edit}/models/route.ts RENAMED
File without changes
src/app/api/{generate β†’ v1/edit}/models/systemPrompt.ts RENAMED
File without changes
src/app/api/{generate β†’ v1/edit}/storyboards/generateStoryboard.ts RENAMED
@@ -1,8 +1,8 @@
1
  import { generateSeed, getValidNumber } from "@aitube/clap"
2
 
3
- import { newRender, getRender } from "../../providers/videochain/renderWithVideoChain"
4
  import { sleep } from "@/lib/utils/sleep"
5
- import { getNegativePrompt, getPositivePrompt } from "../../utils/imagePrompts"
6
 
7
  export async function generateStoryboard({
8
  prompt,
 
1
  import { generateSeed, getValidNumber } from "@aitube/clap"
2
 
3
+ import { newRender, getRender } from "@/app/api/providers/videochain/renderWithVideoChain"
4
  import { sleep } from "@/lib/utils/sleep"
5
+ import { getNegativePrompt, getPositivePrompt } from "@/app/api/utils/imagePrompts"
6
 
7
  export async function generateStoryboard({
8
  prompt,
src/app/api/{generate β†’ v1/edit}/storyboards/route.ts RENAMED
@@ -6,8 +6,8 @@ import { startOfSegment1IsWithinSegment2 } from "@/lib/utils/startOfSegment1IsWi
6
  import { getVideoPrompt } from "@/components/interface/latent-engine/core/prompts/getVideoPrompt"
7
  import { getToken } from "@/app/api/auth/getToken"
8
 
9
- import { newRender, getRender } from "../../providers/videochain/renderWithVideoChain"
10
- import { getPositivePrompt } from "../../utils/imagePrompts"
11
  import { generateStoryboard } from "./generateStoryboard"
12
 
13
  // a helper to generate storyboards for a Clap
 
6
  import { getVideoPrompt } from "@/components/interface/latent-engine/core/prompts/getVideoPrompt"
7
  import { getToken } from "@/app/api/auth/getToken"
8
 
9
+ import { newRender, getRender } from "@/app/api/providers/videochain/renderWithVideoChain"
10
+ import { getPositivePrompt } from "@/app/api/utils/imagePrompts"
11
  import { generateStoryboard } from "./generateStoryboard"
12
 
13
  // a helper to generate storyboards for a Clap
src/app/api/{generate/video β†’ v1/export}/route.ts RENAMED
@@ -1,9 +1,26 @@
1
  import { NextResponse, NextRequest } from "next/server"
 
 
 
 
2
 
3
  // we hide/wrap the micro-service under a unified AiTube API
4
  export async function POST(req: NextRequest, res: NextResponse) {
5
 
6
- NextResponse.redirect(`${process.env.AI_TUBE_CLAP_EXPORTER_URL || "http://localhost:7860"}`)
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  }
8
  /*
9
  Alternative solution (in case the redirect doesn't work):
 
1
  import { NextResponse, NextRequest } from "next/server"
2
+ import queryString from "query-string"
3
+
4
+ type SupportedExportFormat = "mp4" | "webm"
5
+ const defaultExportFormat = "mp4"
6
 
7
  // we hide/wrap the micro-service under a unified AiTube API
8
  export async function POST(req: NextRequest, res: NextResponse) {
9
 
10
+ const qs = queryString.parseUrl(req.url || "")
11
+ const query = (qs || {}).query
12
+
13
+ let format: SupportedExportFormat = defaultExportFormat
14
+ try {
15
+ format = decodeURIComponent(query?.f?.toString() || defaultExportFormat).trim() as SupportedExportFormat
16
+ if (format !== "mp4" && format !== "webm") {
17
+ format = defaultExportFormat
18
+ }
19
+ } catch (err) {}
20
+
21
+ NextResponse.redirect(`${
22
+ process.env.AI_TUBE_CLAP_EXPORTER_URL || "http://localhost:7860"
23
+ }?f=${format}`)
24
  }
25
  /*
26
  Alternative solution (in case the redirect doesn't work):