Spaces:
Runtime error
Runtime error
File size: 1,808 Bytes
a53aa3c | 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 51 52 53 54 55 56 57 58 59 60 61 | import { normalise_file, FileData } from "@gradio/client";
export class BlurhashFileData {
image?: FileData;
blurhash?: string;
width?: number;
height?: number;
constructor({ image, blurhash, width, height }: { image?: FileData; blurhash?: string; width?: number; height?: number }) {
this.image = image ? new FileData(image) : undefined;
this.blurhash = blurhash;
this.width = width;
this.height = height;
}
}
export function normalise_blurhash_file(
file: BlurhashFileData | null,
server_url: string,
proxy_url: string | null
): BlurhashFileData | null;
export function normalise_blurhash_file(
file: BlurhashFileData[] | null,
server_url: string,
proxy_url: string | null
): BlurhashFileData[] | null;
export function normalise_blurhash_file(
file: BlurhashFileData[] | BlurhashFileData | null,
server_url: string, // root: string,
proxy_url: string | null // root_url: string | null
): BlurhashFileData[] | BlurhashFileData | null;
export function normalise_blurhash_file(
blurhash_file: BlurhashFileData[] | BlurhashFileData | null,
server_url: string, // root: string,
proxy_url: string | null // root_url: string | null
): BlurhashFileData[] | BlurhashFileData | null {
if (blurhash_file == null) {
return null;
}
if (Array.isArray(blurhash_file)) {
const normalized_files: (BlurhashFileData | null)[] = [];
for (const x of blurhash_file) {
normalized_files.push(normalise_blurhash_file(x, server_url, proxy_url));
}
return normalized_files as BlurhashFileData[];
}
const file_data = blurhash_file.image ? normalise_file(blurhash_file.image, server_url, null) : null;
return new BlurhashFileData({
image: file_data ? file_data : undefined,
blurhash: blurhash_file.blurhash,
width: blurhash_file.width,
height: blurhash_file.height,
});
} |