Update app.py
Browse files2 unmodified lines3456789101161 unmodified lines73747576777879808182838413 unmodified lines98991001011021031041051061071082 unmodified linesimport jsondef bytes_to_giga_bytes(bytes):return f"{(bytes / 1024 / 1024 / 1024):.3f}"def load_model_index(pipeline_id, token=None, revision=None):index_path = hf_hub_download(repo_id=pipeline_id, filename="model_index.json", revision=revision, token=token)61 unmodified linesprint(selected_file.rfilename)component_wise_memory[component] = bytes_to_giga_bytes(selected_file.size)return component_wise_memorygr.Interface(title="Compute component-wise memory of a 🧨 Diffusers pipeline.",description="Sizes will be reported in GB. It can handle pipelines where the text encoder checkpoints might be shared (PixArt, for example).",fn=get_component_wise_memory,inputs=[gr.components.Textbox(lines=1, label="pipeline_id", info="Example: runwayml/stable-diffusion-v1-5"),13 unmodified linesinfo="Extension to use.",),],outputs="text",examples=[["runwayml/stable-diffusion-v1-5", None, "fp32", None, ".safetensors"],["stabilityai/stable-diffusion-xl-base-1.0", None, "fp16", None, ".safetensors"],["PixArt-alpha/PixArt-XL-2-1024-MS", None, "fp32", None, ".safetensors"],],theme=gr.themes.Soft(),allow_flagging=False,2 unmodified lines3456789101112131415161718192021222324252661 unmodified lines88899091929394959697989913 unmodified lines1131141151161171181191201211221232 unmodified linesimport jsondef format_size(num: int) -> str:"""Format size in bytes into a human-readable string.Taken from https://stackoverflow.com/a/1094933"""num_f = float(num)for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:if abs(num_f) < 1000.0:return f"{num_f:3.1f}{unit}"num_f /= 1000.0return f"{num_f:.1f}Y"def format_output(memory_mapping):markdown_str = ""if memory_mapping:for component, memory in memory_mapping:markdown_str += f"* {component}: {format_size(memory)}\n"return markdown_strdef load_model_index(pipeline_id, token=None, revision=None):index_path = hf_hub_download(repo_id=pipeline_id, filename="model_index.json", revision=revision, token=token)61 unmodified linesprint(selected_file.rfilename)component_wise_memory[component] = bytes_to_giga_bytes(selected_file.size)return format_output(component_wise_memory)gr.Interface(title="Compute component-wise memory of a 🧨 Diffusers pipeline.",description="Sizes will be reported in GB.",fn=get_component_wise_memory,inputs=[gr.components.Textbox(lines=1, label="pipeline_id", info="Example: runwayml/stable-diffusion-v1-5"),13 unmodified linesinfo="Extension to use.",),],outputs="markdown",examples=[["runwayml/stable-diffusion-v1-5", None, "fp32", None, ".safetensors"],["stabilityai/stable-diffusion-xl-base-1.0", None, "fp16", None, ".safetensors"],[""],],theme=gr.themes.Soft(),allow_flagging=False,
app.py+22-7