adding stylization api end point.

This commit is contained in:
Michael Chung committed 2024-03-29 22:17:12 -04:00
1 parent 2df5466fb2
commit c6dcbbfe78
2 files changed
+71 -4

No files matched your search

+65 -3
View File
@@ -8,7 +8,7 @@ import { TimelineDataState } from "./timeline";
* Storyteller Studio API Manager
* The source of truth of all these media items is the database in the cloud
*/
class MediaFile {
export class MediaFile {
public_bucket_path: string;
media_type: string;
media_token: string;
@@ -24,6 +24,31 @@ class MediaFile {
}
}
export enum ArtStyle {
Anime2_5D = "anime_2_5d",
Anime2DFlat = "anime_2d_flat",
Cartoon3D = "cartoon_3d",
ComicBook = "comic_book",
AnimeGhibli = "anime_ghibli",
InkPunk = "ink_punk",
InkSplash = "ink_splash",
InkBWStyle = "ink_bw_style",
JojoStyle = "jojo_style",
PaperOrigami = "paper_origami",
PixelArt = "pixel_art",
PopArt = "pop_art",
Realistic1 = "realistic_1",
Realistic2 = "realistic_2",
AnimeRetroNeon = "anime_retro_neon",
AnimeStandard = "anime_standard",
}
export enum Visibility {
Public = "public",
Hidden = "hidden",
Private = "private",
}
/**
* This is designed to surface user customer facing messages as errors.
*/
@@ -48,7 +73,7 @@ class APIManagerResponseError extends Error {
}
}
class APIManager {
export class APIManager {
baseUrl: String;
constructor() {
@@ -332,6 +357,43 @@ class APIManager {
.catch((error) => console.error("Error:", error));
return result;
}
public async stylizeVideo(media_token: string,
style: ArtStyle,
positive_prompt:string,
negative_prompt:string,
visibility:Visibility) {
let uuid = uuidv4();
const data = {
uuid_idempotency_token: uuid,
style: style,
prompt: positive_prompt,
negative_prompt: negative_prompt,
trim_start_millis: 0,
trim_end_millis: 3000,
enable_lipsync: true,
creator_set_visibility: visibility
}
const response = await fetch(`${this.baseUrl}/v1/video/enqueue_vst`, {
method: "POST",
credentials: "include",
headers: {
Accept: "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok) {
// Handle HTTP error responses
const errorData = await response.json();
throw new Error(`API Error: ${response.status} ${errorData.message}`);
}
// Assuming the response is JSON and matches the EnqueueVideoStyleTransferSuccessResponse interface
return await response.json();
}
}
export default APIManager;
+6 -1
View File
@@ -3,7 +3,7 @@ import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { FreeCam } from "./free_cam";
import { TransformControls } from "three/addons/controls/TransformControls.js";
import Scene from "./scene.js";
import APIManager from "./api_manager.js";
import { APIManager, ArtStyle, Visibility } from "./api_manager.js";
import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js";
import { RenderPass } from "three/addons/postprocessing/RenderPass.js";
import { OutlinePass } from "three/addons/postprocessing/OutlinePass.js";
@@ -321,6 +321,11 @@ class Editor {
console.log(result);
}
public async testStylizeRequest() {
const result = await this.api_manager.stylizeVideo("mu_6wy1570a0c3c0tpkkncf4tsvb5234",ArtStyle.Anime2_5D," ((masterpiece, best quality, 8K, detailed)), colorful, epic, fantasy, (fox, red fox:1.2), no humans, 1other, ((koi pond)), outdoors, pond, rocks, stones, koi fish, ((watercolor))), lilypad, fish swimming around.","",Visibility.Public)
console.log(result);
}
public async loadScene(scene_media_token: string) {
this.dispatchAppUiState({
type: APPUI_ACTION_TYPES.SHOW_EDITOR_LOADER,