File size: 4,710 Bytes
18ce093 9959fea 18ce093 9959fea 18ce093 0296fb6 5497f8f 18ce093 0296fb6 18ce093 0296fb6 9959fea 18ce093 9a6b7a2 18ce093 392ca7c 18ce093 e841823 5497f8f e841823 5497f8f 9959fea 5497f8f 0296fb6 e841823 9959fea 18ce093 9959fea 0296fb6 18ce093 e8d5783 18ce093 e841823 18ce093 9959fea 18ce093 |
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import gradio as gr
from convert_diffusion_to_gguf import SUPPORTED_ARCHS, qconfig_map, convert
from huggingface_hub import create_repo, upload_file
from argparse import Namespace
from io import StringIO
from pathlib import Path
log_stream = StringIO()
def upload(args):
url = ""
if args.host_repo_id and args.hf_token:
repo_id = create_repo(args.host_repo_id, repo_type="model", exist_ok=True, token=args.hf_token).repo_id
info = upload_file(
repo_id=repo_id, path_in_repo=str(args.outfile), path_or_fileobj=str(args.outfile), token=args.hf_token
)
url = info.commit_url
print(f"Uploaded to {url}")
return url
def go_gguf(
model_repo_id,
subfolder,
arch,
outtype,
outfile_name,
bigendian,
verbose,
host_repo_id,
hf_token,
progress=gr.Progress(track_tqdm=True),
):
log_stream.truncate(0)
log_stream.seek(0)
args = Namespace(
model=Path(model_repo_id),
subfolder=subfolder,
arch=arch,
outtype=outtype,
outfile=Path(outfile_name),
bigendian=bigendian,
verbose=verbose,
host_repo_id=host_repo_id,
hf_token=hf_token,
cache_dir=None,
)
try:
progress(0.1, desc="Starting conversion... (This may take a while depending on model size)")
convert(args)
progress(0.8, desc="β
Conversion Complete. Starting upload...")
url = upload(args)
if url:
return log_stream.getvalue(), f"### β
Success!\n\nUploaded to: [{url}]({url})"
else:
return (
log_stream.getvalue(),
"### β
Conversion Complete!\n\n(File was not uploaded as no repo/token was provided)",
)
except Exception as e:
return log_stream.getvalue(), str(e)
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("<h1><center>GGUF Converter for Diffusers format model checkpoints</center></h1>")
gr.Markdown(
"Convert `diffusers` format model checkpoints from the Hub to GGUF format and optionally upload them back. Based on [this repo](https://github.com/ngxson/diffusion-to-gguf)."
)
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### π₯ Input Model")
model_repo_id = gr.Textbox(label="Model Repo ID", placeholder="e.g., Qwen/Qwen-Image")
subfolder = gr.Textbox(label="Subfolder (Optional)", placeholder="e.g., transformer")
gr.Markdown("### βοΈ Conversion Settings")
arch = gr.Dropdown(choices=SUPPORTED_ARCHS, label="Architecture")
outtype = gr.Dropdown(choices=list(qconfig_map.keys()), label="Quantization Type", value="F16")
outfile_name = gr.Textbox(label="Output Filename", value="{ftype}.gguf")
with gr.Accordion("Advanced Settings", open=False):
bigendian = gr.Checkbox(label="Use Big Endian")
verbose = gr.Checkbox(label="Verbose Logging", value=True)
gr.Markdown("### π€ Upload to Hub (Optional)")
host_repo_id = gr.Textbox(label="Your Hub Repo ID", placeholder="e.g., YourUsername/My-GGUFs")
hf_token = gr.Textbox(label="Hugging Face Token", type="password", placeholder="hf_...")
convert_btn = gr.Button("Convert & Upload", variant="primary")
with gr.Column(scale=2):
gr.Markdown("### π Logs")
logs_output = gr.Textbox(
label="Conversion Logs", lines=25, max_lines=25, interactive=False, autoscroll=True
)
gr.Markdown("### π Result")
url_output = gr.Markdown()
gr.Examples(
examples=[
[
"black-forest-labs/FLUX.1-schnell",
"transformer",
"flux",
"Q4_0",
"flux-schnell-q4.gguf",
False,
False,
"YourUsername/MyGGUFs",
"hf_...",
],
[
"Qwen/Qwen-Image",
"transformer",
"qwen",
"Q8_0",
"qwen-q4.gguf",
False,
False,
"YourUsername/MyGGUFs",
"hf_...",
],
],
inputs=[model_repo_id, subfolder, arch, outtype, outfile_name, bigendian, verbose, host_repo_id, hf_token],
)
convert_btn.click(
fn=go_gguf,
inputs=[model_repo_id, subfolder, arch, outtype, outfile_name, bigendian, verbose, host_repo_id, hf_token],
outputs=[logs_output, url_output],
)
if __name__ == "__main__":
demo.launch()
|