mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
Network Requests for Previews and Segmentation (#40)
* Jobs API * SegmentationApi implementing testing it now.
This commit is contained in:
1 parent
3b32109e57
commit
47b0361bd7
3 files changed
+122
-1
No files matched your search
@@ -1,7 +1,26 @@
|
||||
import { ApiManager, ApiResponse } from "./ApiManager";
|
||||
import { Job } from "./models/Job";
|
||||
import { Job, JobPreview } from "./models/Job";
|
||||
|
||||
export class JobsApi extends ApiManager {
|
||||
public GetPreviewStatusByJobToken({
|
||||
token,
|
||||
}: {
|
||||
token: string;
|
||||
}): Promise<ApiResponse<JobPreview>> {
|
||||
console.log(token);
|
||||
|
||||
const endpoint = `${this.ApiTargets.BaseApi}/v1/workflows/preview_status/${token}`;
|
||||
|
||||
return this.get<ApiResponse<JobPreview>>({ endpoint })
|
||||
.then((response) => ({
|
||||
success: response.success,
|
||||
data: response.data,
|
||||
}))
|
||||
.catch((err) => {
|
||||
return { success: false, errorMessage: err.message };
|
||||
});
|
||||
}
|
||||
|
||||
public GetJobByToken({
|
||||
token,
|
||||
}: {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { ApiManager } from "./ApiManager";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
export interface Coordinates {
|
||||
coordinates: [number, number];
|
||||
include: boolean;
|
||||
}
|
||||
|
||||
export interface ObjectData {
|
||||
object_id: number;
|
||||
points: Coordinates[];
|
||||
}
|
||||
|
||||
export interface Frame {
|
||||
timestamp: number;
|
||||
objects: ObjectData[];
|
||||
}
|
||||
|
||||
export interface SegmentationRequest {
|
||||
session_id: string;
|
||||
fps: number;
|
||||
frames: Frame[];
|
||||
propogate: boolean;
|
||||
}
|
||||
|
||||
export interface SegmentationResponse {
|
||||
session_id: string;
|
||||
fps: number;
|
||||
frames: Frame[];
|
||||
propogate: boolean;
|
||||
}
|
||||
|
||||
export class SegmentationApi extends ApiManager {
|
||||
// returns uuid
|
||||
public async createSession(
|
||||
b64Video: string,
|
||||
): Promise<{ session_id: string }> {
|
||||
const endpoint = `https://hax.storyteller.ai/segmentation/new_session`;
|
||||
const id = uuidv4().toString();
|
||||
return this.postForm<{ session_id: "fix-mimetype" }>({
|
||||
endpoint: endpoint,
|
||||
formRecord: {
|
||||
session_id: "fix-mimetype",
|
||||
},
|
||||
uuid: id,
|
||||
blobFileName: id,
|
||||
});
|
||||
}
|
||||
|
||||
public addPointsToSession(
|
||||
session_id: string,
|
||||
fps: number,
|
||||
frames: Frame[],
|
||||
proprogate: boolean,
|
||||
): Promise<{}> {
|
||||
const endpoint = `https://hax.storyteller.ai/segmentation/new_session`;
|
||||
|
||||
const segmentationRequest: SegmentationRequest = {
|
||||
session_id: session_id,
|
||||
fps: fps,
|
||||
frames: frames,
|
||||
propogate: proprogate,
|
||||
};
|
||||
|
||||
return this.post<SegmentationRequest, SegmentationResponse>({
|
||||
endpoint: endpoint,
|
||||
body: segmentationRequest,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -35,3 +35,35 @@ export interface JobStatusResponse {
|
||||
progress_percentage: number;
|
||||
status: JobStatus;
|
||||
}
|
||||
|
||||
export interface JobPreview {
|
||||
success: boolean;
|
||||
state: {
|
||||
job_token: string;
|
||||
request: Record<string, unknown>;
|
||||
status: {
|
||||
status: string;
|
||||
maybe_extra_status_description: string | null;
|
||||
maybe_assigned_worker: string;
|
||||
maybe_assigned_cluster: string;
|
||||
maybe_first_started_at: string;
|
||||
attempt_count: number;
|
||||
requires_keepalive: boolean;
|
||||
maybe_failure_category: string;
|
||||
progress_percentage: number;
|
||||
};
|
||||
maybe_result: {
|
||||
expected_stages: number;
|
||||
currently_active_stage: number;
|
||||
per_stage_frame_count: number;
|
||||
stages: Array<{
|
||||
stage_progress: number;
|
||||
expected_frame_count: number;
|
||||
stage_complete: boolean;
|
||||
frames: string[];
|
||||
}>;
|
||||
};
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user