mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
e4a307ed6c
* changes * changes * add changeset * add changeset * Server fns ext (#5760) * start changes * changes * changes * fix arrows * add changeset * rename demo * fix some ci * add changeset * add changeset * fix * remove configs * fix * fix * add changeset * fixes * linting * Update gradio/components/file_explorer.py * notebook * typing * tweaks * fixed class method problem * fix test * file explorer * gr.load * format * tweaks * fix * fix * fix * fix * final tweaks + changelog * changelog * changelog * changelog * lint --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
34 lines
774 B
TypeScript
34 lines
774 B
TypeScript
import type { FileData } from "@gradio/upload";
|
|
|
|
export const prettyBytes = (bytes: number): string => {
|
|
let units = ["B", "KB", "MB", "GB", "PB"];
|
|
let i = 0;
|
|
while (bytes > 1024) {
|
|
bytes /= 1024;
|
|
i++;
|
|
}
|
|
let unit = units[i];
|
|
return bytes.toFixed(1) + " " + unit;
|
|
};
|
|
|
|
export const display_file_name = (value: FileData): string => {
|
|
var str: string;
|
|
str = value.orig_name || value.name;
|
|
if (str.length > 30) {
|
|
return `${str.substr(0, 30)}...`;
|
|
}
|
|
return str;
|
|
};
|
|
|
|
export const display_file_size = (value: FileData | FileData[]): string => {
|
|
var total_size = 0;
|
|
if (Array.isArray(value)) {
|
|
for (var file of value) {
|
|
if (file.size !== undefined) total_size += file.size;
|
|
}
|
|
} else {
|
|
total_size = value.size || 0;
|
|
}
|
|
return prettyBytes(total_size);
|
|
};
|