Spaces:
Runtime error
Runtime error
File size: 2,514 Bytes
e0097f3 26e2bde 889bd09 26e2bde e604382 e0097f3 f660de1 e0097f3 0ee720e 6fcc7bb e0097f3 01dd240 e0097f3 0ee720e e0097f3 e604382 e0097f3 53c05f3 e0097f3 deb501d d0af4d3 756a5fd e0097f3 a7b696a e604382 e0097f3 091f7ec b178974 f4bc47f e0097f3 2ab651f 107722c |
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 |
import gradio as gr
import time
import os
from huggingface_hub import HfApi, create_repo
def convert_checkpoint(url, name,repo_id, hf_token ,image_size, scheduler_type, use_half):
try:
print("Downloading")
# Download the file
os.system(f"wget -q {url} --content-disposition -O {name}.safetensors")
time.sleep(5)
print("Download successful")
# Construct the checkpoint path and dump path
checkpoint_path = f"{name}.safetensors"
dump_path = f"/home/user/app/{name}"
cmd = [
"python3",
"diffusers/scripts/convert_original_stable_diffusion_to_diffusers.py", # Replace with the name of your script
"--checkpoint_path", checkpoint_path,
f"--scheduler_type {scheduler_type}",
f"--image_size {image_size}",
"--prediction_type epsilon",
"--device cpu",
"--from_safetensors",
"--to_safetensors",
"--dump_path", dump_path
]
if use_half:
cmd.append("--half")
result = os.system(" ".join(cmd))
output = result
os.remove(checkpoint_path)
# Log in to your Hugging Face account
os.system(f"huggingface-cli login --token {hf_token}")
# Create a repository
api = HfApi()
api.create_repo(f"{repo_id}/{name}")
# Upload a folder to the repository
api.upload_folder(
folder_path=dump_path,
repo_id=f"{repo_id}/{name}",
repo_type="model",
)
except Exception as e:
output = str(e)
return output
iface = gr.Interface(
fn=convert_checkpoint,
inputs=[
gr.inputs.Textbox(label="URL"),
gr.inputs.Textbox(label="Name"),
gr.inputs.Textbox(label="Repo id"),
# gr.inputs.Dropdown(label="Visibility", choices=["True","False"]),
gr.inputs.Textbox(label="Hugging Face API Token"),
gr.inputs.Radio(label="Image Size", choices=["512", "768"]),
gr.inputs.Dropdown(label="Scheduler Type", choices=['pndm', 'lms', 'ddim', 'euler', 'euler-ancestral', 'dpm']),
gr.inputs.Checkbox(label="Use Half Precision")
],
outputs=gr.outputs.Textbox(),
title="**Forked from https://huggingface.co/spaces/Androidonnxfork/CivitAi-to-Diffusers**",
max_queue_size=5
)
iface.launch()
|